From 24af146aba768c2855ff9314232d365e6cef4c5c Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 13 Oct 2017 14:49:02 +0200 Subject: [PATCH 1/2] improved test assertation messages --- tests/Integration/IntegrationTestCase.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Integration/IntegrationTestCase.php b/tests/Integration/IntegrationTestCase.php index ba5c79f8..fd0f122f 100644 --- a/tests/Integration/IntegrationTestCase.php +++ b/tests/Integration/IntegrationTestCase.php @@ -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) @@ -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() From a6d47b9145b5839b1d0d3a2aa1597494468b843e Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 13 Oct 2017 14:50:20 +0200 Subject: [PATCH 2/2] added failing test for #158 expecting `refresh()` method to update the record --- .../OneToManyRelationshipEntityTest.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Integration/OneToManyRelationshipEntityTest.php b/tests/Integration/OneToManyRelationshipEntityTest.php index d7a880c8..674c7c0b 100644 --- a/tests/Integration/OneToManyRelationshipEntityTest.php +++ b/tests/Integration/OneToManyRelationshipEntityTest.php @@ -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()); + } + }