public function testDeleteAll() { $books = Book::select($this->getConn())->execute(); $this->assertSame(50, count($books)); Book::deleteAll($this->getConn()); $no_books = Book::select($this->getConn())->execute(); $this->assertSame(0, count($no_books)); }
public function testSelectWithEager() { $this->loadData('bookshop'); $this->resetQueryCount(); $books = Book::select($this->getConn())->with('author')->execute(); foreach ($books as $book) { //ensure the related entities are actually loaded $book->author; } $this->assertSame('Thomas Hardy', $books[0]->author->name); //only two queries should have run $this->assertSame(2, $this->getQueryCount()); }
/** * Check that selecting one entity works with both methods. */ public function selectorProvider() { return [[Book::selectOne($this->getConn())], [Book::select($this->getConn())->one()]]; }
public function testCountLimitNotReached() { $this->loadData('bookshop'); $count = Book::select($this->getConn())->count()->where('id', '>', 43)->limit(20)->execute(); $this->assertSame(7, $count); }
/** * @dataProvider insertMethodProvider() */ public function testInsertCallsInsertEvent($insert_method) { Book::addEventCallBack('insert', function ($book) { $book->description = 'description-' . $book->description; }); $conn = $this->getConn(); for ($i = 1; $i < 4; $i++) { $book = new Book($conn, ['name' => 'foo', 'description' => $i, 'authors_id' => 0]); $book->{$insert_method}(); } $books = Book::select($conn)->execute(); $expected = ['description-1', 'description-2', 'description-3']; $this->assertSame($expected, $books->getColumn('description')); Book::resetEventCallbacks(); }
public function testWhereInEmpty() { $this->loadData('bookshop'); $books = Book::select($this->getConn())->whereIn('id', [])->execute(); $this->assertInstanceOf('ActiveDoctrine\\Entity\\EntityCollection', $books); $this->assertSame(0, count($books)); }
public function testSelect() { $this->expectDriver(); $selector = Book::select($this->conn); $this->assertInstanceOf('ActiveDoctrine\\Entity\\EntitySelector', $selector); $this->assertSame('SELECT * FROM `books`', $selector->getSQL()); }