<?php declare(strict_types = 1);
/**
* @testCase
*/
namespace NextrasTestsOrmIntegrationRelationships;
use NextrasTestsOrmAuthor;
use NextrasTestsOrmBook;
use NextrasTestsOrmTestCase;
use TesterAssert;
$dic = require_once __DIR__ . '/../../../bootstrap.php';
class RelationshipsManyHasOneIsChangedTest extends TestCase
{
public function testBasic()
{
/** @var Author $author1 */
/** @var Author $author2 */
$author1 = $this->e(Author::class);
$author2 = $this->e(Author::class);
/** @var Book $book */
$book = $this->e(Book::class);
assert::
null($book->
translator);
$book->translator = $author1;
assert::
same(1,
$author1->
translatedBooks->
count());
assert::
same(0,
$author2->
translatedBooks->
count());
$book->translator = $author2;
assert::
same(0,
$author1->
translatedBooks->
count());
assert::
same(1,
$author2->
translatedBooks->
count());
$book->translator = null;
assert::
same(0,
$author1->
translatedBooks->
count());
assert::
same(0,
$author2->
translatedBooks->
count());
assert::
true($book->
getProperty('author')->
isModified());
$book->translator = null;
assert::
true($book->
getProperty('author')->
isModified());
}
}
$test = new RelationshipsManyHasOneIsChangedTest($dic);
$test->run();
?>