pastebin

Paste Search Dynamic
Recent pastes
manyHasOne isChanged
  1. <?php declare(strict_types = 1);
  2.  
  3. /**
  4.  * @testCase
  5.  */
  6.  
  7. namespace NextrasTestsOrmIntegrationRelationships;
  8.  
  9. use NextrasTestsOrmAuthor;
  10. use NextrasTestsOrmBook;
  11. use NextrasTestsOrmTestCase;
  12. use TesterAssert;
  13.  
  14.  
  15. $dic = require_once __DIR__ . '/../../../bootstrap.php';
  16.  
  17.  
  18. class RelationshipsManyHasOneIsChangedTest extends TestCase
  19. {
  20.         public function testBasic()
  21.         {
  22.                 /** @var Author $author1 */
  23.                 /** @var Author $author2 */
  24.                 $author1 = $this->e(Author::class);
  25.                 $author2 = $this->e(Author::class);
  26.  
  27.                 /** @var Book $book */
  28.                 $book = $this->e(Book::class);
  29.  
  30.                 assert::null($book->translator);
  31.  
  32.                 $book->translator = $author1;
  33.                 assert::same(1, $author1->translatedBooks->count());
  34.                 assert::same(0, $author2->translatedBooks->count());
  35.  
  36.                 $book->translator = $author2;
  37.                 assert::same(0, $author1->translatedBooks->count());
  38.                 assert::same(1, $author2->translatedBooks->count());
  39.  
  40.                 $book->translator = null;
  41.                 assert::same(0, $author1->translatedBooks->count());
  42.                 assert::same(0, $author2->translatedBooks->count());
  43.  
  44.                 assert::true($book->getProperty('author')->isModified());
  45.  
  46.                 $book->translator = null;
  47.                 assert::true($book->getProperty('author')->isModified());
  48.         }
  49. }
  50.  
  51. $test = new RelationshipsManyHasOneIsChangedTest($dic);
  52. $test->run();
  53. ?>
Parsed in 0.073 seconds