Пример #1
0
 /**
  * @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();
 }
Пример #2
0
 /**
  * @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();
 }
Пример #3
0
 public function testEventCallbacksAreClassSpecific()
 {
     Book::resetEventCallbacks();
     Author::resetEventCallbacks();
     $foo = function () {
     };
     $bar = function () {
     };
     Book::addEventCallBack('insert', $foo);
     Author::addEventCallBack('update', $bar);
     $callbacks = new \ReflectionProperty('ActiveDoctrine\\Entity\\Entity', 'callbacks');
     $callbacks->setAccessible(true);
     $this->assertSame(['insert' => [$foo]], $callbacks->getValue()['ActiveDoctrine\\Tests\\Fixtures\\Bookshop\\Book']);
     $this->assertSame(['update' => [$bar]], $callbacks->getValue()['ActiveDoctrine\\Tests\\Fixtures\\Bookshop\\Author']);
 }