public function testDelete() { $book = Book::selectOne($this->getConn())->where('id', 1)->execute(); $this->assertTrue($book->isStored()); $this->assertSame($book, $book->delete()); $this->assertNull(Book::selectOne($this->getConn())->where('id', 1)->execute()); $this->assertFalse($book->isStored()); }
public function testSetBelongsTo() { $book = Book::selectOne($this->getConn())->execute(); $this->assertFalse($book->hasRelation('details')); $details = BookDetails::selectOne($this->getConn())->execute(); $this->assertNotSame($book->id, $details->books_id); $details->book = $book; $this->assertSame($book->id, $details->books_id); $this->assertSame($book, $details->book); $this->assertTrue($details->hasRelation('book')); }
/** * @dataProvider insertMethodProvider() */ public function testInsertOne($insert_method) { $conn = $this->getConn(); $book = new Book($conn); $book->name = 'Foo'; $book->description = 'Bar'; $book->authors_id = 0; $book->{$insert_method}(); //select it to check it has been inserted $selected = Book::selectOne($conn)->execute(); $this->assertInstanceOf('ActiveDoctrine\\Tests\\Fixtures\\Bookshop\\Book', $selected); $this->assertEquals($book->getValues(), $selected->getValues()); }
/** * @dataProvider updateMethodProvider */ public function testUpdateCallsUpdateEvent($update_method) { Book::addEventCallBack('update', function ($book) { $book->description = 'update-' . $book->description; }); $this->loadSchema('bookshop'); $this->loadData('bookshop'); $conn = $this->getConn(); $book = Book::selectOne($this->getConn())->where('id', '=', 2)->execute(); $book->{$update_method}(); $this->assertSame('update-The second book', $book->description); Book::resetEventCallbacks(); }
/** * Check that selecting one entity works with both methods. */ public function selectorProvider() { return [[Book::selectOne($this->getConn())], [Book::select($this->getConn())->one()]]; }
public function testSelectOne() { $this->expectDriver(); $selector = Book::selectOne($this->conn); $this->assertInstanceOf('ActiveDoctrine\\Entity\\EntitySelector', $selector); $this->assertSame('SELECT * FROM `books` LIMIT 1', $selector->getSQL()); }