public function testCountBy()
{
$library = $this->dataLibrary->createEmpty();
$library->set('name', 'A');
$this->dataLibrary->create($library);
$library = $this->dataLibrary->createEmpty();
$library->set('name', 'B');
$this->dataLibrary->create($library);
$library = $this->dataLibrary->createEmpty();
$library->set('name', 'C');
$this->dataLibrary->create($library);
$table = $this->dataLibrary->getDefinition()->getTable();
$book = $this->dataBook->createEmpty();
$book->set('title', 'title');
$book->set('author', 'author');
$book->set('pages', 111);
$book->set('library', $library->get('id'));
$this->dataBook->create($book);
$library->set('libraryBook', [['id' => $book->get('id')]]);
$this->dataLibrary->update($library);
$read = $this->dataLibrary->countBy($table, ['libraryBook' => [['id' => $book->get('id')]]], ['libraryBook' => '='], true);
$expected = 1;
$this->assertSame($expected, $read);
$this->dataLibrary->delete($library);
$read = $this->dataLibrary->countBy($table, [], [], false);
$expected = 3;
$this->assertSame($read, $expected);
$read = $this->dataLibrary->countBy($table, [], [], true);
$expected = 2;
$this->assertSame($read, $expected);
$read = $this->dataLibrary->countBy($table, ['id' => 1], ['id' => '='], false);
$expected = 1;
$this->assertSame($read, $expected);
$read = $this->dataLibrary->countBy($table, ['id' => 1], ['id' => '!='], false);
$expected = 2;
$this->assertSame($read, $expected);
$read = $this->dataLibrary->countBy($table, ['id' => 1, 'name' => 'A'], ['id' => '=', 'name' => '='], false);
$expected = 1;
$this->assertSame($read, $expected);
$read = $this->dataLibrary->countBy($table, ['id' => 1, 'name' => 'B'], ['id' => '=', 'name' => '='], false);
$expected = 0;
$this->assertSame($read, $expected);
$read = $this->dataLibrary->countBy($table, ['id' => 3], ['id' => '='], false);
$expected = 1;
$this->assertSame($read, $expected);
$read = $this->dataLibrary->countBy($table, ['id' => 3], ['id' => '='], true);
$expected = 0;
$this->assertSame($read, $expected);
}