Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Refresh test #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/Integration/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ protected function persist(...$objects)

protected function assertGraphNotExist($q)
{
$this->assertTrue($this->checkGraph($q)->size() < 1);
$this->assertTrue($this->checkGraph($q)->size() < 1, "Failed asserting that the following graph does not exist: $q");
}

protected function assertGraphExist($q)
{
$this->assertTrue($this->checkGraph($q)->size() > 0);
$this->assertTrue($this->checkGraph($q)->size() > 0, "Failed asserting that the following graph exists: $q");
}

protected function checkGraph($q)
Expand All @@ -81,12 +81,12 @@ protected function checkGraph($q)

protected function assertNodesCount($count)
{
$this->assertSame($count, $this->client->run('MATCH (n) RETURN count(n) AS c')->firstRecord()->get('c'));
$this->assertSame($count, $this->client->run('MATCH (n) RETURN count(n) AS c')->firstRecord()->get('c'), "Failed asserting that node count is $count.");
}

protected function assertRelationshipsCount($count)
{
$this->assertSame($count, $this->client->run('MATCH (n)-[r]->(o) RETURN count(r) AS c')->firstRecord()->get('c'));
$this->assertSame($count, $this->client->run('MATCH (n)-[r]->(o) RETURN count(r) AS c')->firstRecord()->get('c'), "Failed asserting that relationship count is $count.");
}

protected function playMovies()
Expand Down
32 changes: 32 additions & 0 deletions tests/Integration/OneToManyRelationshipEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,36 @@ public function testOwnerCanAddOneToCollectionAfterLoad()
$result = $this->client->run('MATCH (o:Owner)-[r:ACQUIRED]->(h) RETURN count(r) AS c');
$this->assertSame(1, $result->firstRecord()->get('c'));
}

public function testOwnerCanRefreshCollection()
{
// create initial data
$owner = new Owner('M');
$house1 = new House();
$house1->setAddress('A Street 1');
$this->persist($owner, $house1);
$this->em->flush();
$this->assertGraphExist('(o:Owner {name:"M"})');
$this->assertGraphExist('(h:House {address: "A Street 1"})');
$this->em->flush();
$this->em->clear();

// load owner instance
/** @var Owner $me */
$me = $this->em->getRepository(Owner::class)->findOneBy(['name' => 'M']);

$this->assertSame(0, $me->getAcquisitions()->count());

// make some changes to the db
$this->em->getDatabaseDriver()->run('MATCH (o:Owner {name:"M"}), (h:House {address: "A Street 1"}) CREATE (o)-[r:ACQUIRED {year: 1980}]->(h)');
$this->assertGraphExist('(o:Owner {name:"M"})-[r:ACQUIRED {year: 1980}]->(h:House {address: "A Street 1"})');

// this line should fetch a new record, but somehow it uses a chaced one, as the assertation below fails
$me = $this->em->getRepository(Owner::class)->findOneBy(['name' => 'M']);

// uncommenting this line complains that the entity is not managed by the entity manager, however if it is cached, I expect it to be refreshed by this.
// $this->em->refresh($me);
$this->assertSame(1, $me->getAcquisitions()->count());
}

}