Esempio n. 1
0
 public function testDelete()
 {
     $this->initConnection();
     $bookstore = $this->dbDiffer('bookstore');
     $bookstore->snapshot();
     // select the opinion of 3
     $opinions = BooksOpinions::select()->equal('opinion_id', 3)->first();
     $this->assertEquals($opinions->get('opinion'), 'Everyone has their history and quirks.');
     $this->assertEquals($opinions instanceof BooksOpinions, true);
     $result = $opinions->delete();
     $bookstore->snapshot();
     $this->assertEquals($result instanceof BooksOpinions, true);
     $this->assertEquals($bookstore->numOfChanged(), 1);
     $this->assertEquals($bookstore->numOfDeleted(), 1);
     // add three test row
     BooksOpinions::fetchNew()->set('book_id', 2)->set('opinion', 'test')->save();
     BooksOpinions::fetchNew()->set('book_id', 2)->set('opinion', 'test')->save();
     BooksOpinions::fetchNew()->set('book_id', 2)->set('opinion', 'test')->save();
     $bookstore->snapshot();
     $pk = $opinions->save();
     $bookstore->snapshot();
     $this->assertEquals($pk, 3);
     $this->assertEquals($bookstore->numOfCreated(), 1);
     $this->assertEquals($bookstore->numOfChanged(), 1);
 }