public function testFetchExistingUserWithRoleAndAddResourceWithCypherInit()
{
$this->prepareDb();
/** @var User $user */
$user = $this->em->getRepository(User::class)->findOneBy('login', 'test');
/** @var ResourceModel $resource */
$resource = $this->em->getRepository(ResourceModel::class)->findOneBy('name', 'wood');
$this->assertNotNull($user);
$this->assertNotNull($resource);
$this->assertEquals('wood', $resource->getName());
$this->assertCount(0, $user->getUserResources());
$user->addResource($resource, 20);
$this->em->persist($user);
$this->em->persist($resource);
$this->em->flush();
foreach (['water', 'food', 'work', 'stone'] as $res) {
$res2 = $this->em->getRepository(ResourceModel::class)->findOneBy('name', $res);
$user->addResource($res2, 15);
}
$this->em->flush();
$this->assertGraphExist('(r:Resource {name:"wood"})<-[:HAS_RESOURCE]-(u:User {login:"test"})-[:HAS_ROLE]->(role:Role {name:"pageViews"})');
$result = $this->client->run('MATCH (n:User {login:"test"}) RETURN size((n)-[:HAS_RESOURCE]->()) AS value');
$resourcesCount = $result->firstRecord()->get('value');
$this->assertEquals(5, $resourcesCount);
}