Skip to content

Commit 7478efc

Browse files
committed
upgrade to cypher datastructures 0.2.0 wip
1 parent 66b0d5a commit 7478efc

File tree

4 files changed

+147
-113
lines changed

4 files changed

+147
-113
lines changed

tests/FeatureTest/IndexFeatureTest.php

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Syndesi\CypherEntityManager\Tests\FeatureTest;
6+
7+
use Syndesi\CypherDataStructures\Type\NodeIndex;
8+
use Syndesi\CypherEntityManager\Tests\FeatureTestCase;
9+
use Syndesi\CypherEntityManager\Type\EntityManager;
10+
11+
class NodeIndexFeatureTest extends FeatureTestCase
12+
{
13+
public function testIndex(): void
14+
{
15+
// use BTREE for Neo4j 4.x and RANGE for Neo4j 5.x
16+
$defaultIndex = 'BTREE';
17+
if (false !== $_ENV["NEO4J_VERSION"]) {
18+
if (str_starts_with($_ENV["NEO4J_VERSION"], '5.')) {
19+
$defaultIndex = 'RANGE';
20+
}
21+
}
22+
23+
$nodeIndexA = (new NodeIndex())
24+
->setFor('NodeA')
25+
->setType($defaultIndex)
26+
->setName('index_node_a')
27+
->addProperty('id');
28+
$nodeIndexB = (new NodeIndex())
29+
->setFor('NodeB')
30+
->setType($defaultIndex)
31+
->setName('index_node_b')
32+
->addProperty('id')
33+
->addProperty('composite');
34+
35+
$em = $this->container->get(EntityManager::class);
36+
$this->assertIndexDoesNotExist('index_node_a');
37+
$em->create($nodeIndexA);
38+
$em->flush();
39+
$this->assertIndexExist('index_node_a');
40+
$em->create($nodeIndexB);
41+
$em->flush();
42+
$this->assertIndexExist('index_node_b');
43+
44+
$em->delete($nodeIndexA);
45+
$em->flush();
46+
$this->assertIndexDoesNotExist('index_node_a');
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Syndesi\CypherEntityManager\Tests\FeatureTest;
6+
7+
use Syndesi\CypherDataStructures\Type\RelationIndex;
8+
use Syndesi\CypherEntityManager\Tests\FeatureTestCase;
9+
use Syndesi\CypherEntityManager\Type\EntityManager;
10+
11+
class RelationIndexFeatureTest extends FeatureTestCase
12+
{
13+
public function testIndex(): void
14+
{
15+
// use BTREE for Neo4j 4.x and RANGE for Neo4j 5.x
16+
$defaultIndex = 'BTREE';
17+
if (false !== $_ENV["NEO4J_VERSION"]) {
18+
if (str_starts_with($_ENV["NEO4J_VERSION"], '5.')) {
19+
$defaultIndex = 'RANGE';
20+
}
21+
}
22+
23+
$relationIndexA = (new RelationIndex())
24+
->setFor('RELATION_A')
25+
->setType($defaultIndex)
26+
->setName('index_relation_a')
27+
->addProperty('id');
28+
$relationIndexB = (new RelationIndex())
29+
->setFor('RELATION_B')
30+
->setType($defaultIndex)
31+
->setName('index_relation_b')
32+
->addProperty('id')
33+
->addProperty('composite');
34+
35+
$em = $this->container->get(EntityManager::class);
36+
$this->assertIndexDoesNotExist('index_relation_a');
37+
$em->create($relationIndexA);
38+
$em->flush();
39+
$this->assertIndexExist('index_relation_a');
40+
$em->create($relationIndexB);
41+
$em->flush();
42+
$this->assertIndexExist('index_relation_b');
43+
44+
$em->delete($relationIndexA);
45+
$em->flush();
46+
$this->assertIndexDoesNotExist('index_relation_a');
47+
}
48+
}

tests/Helper/StructureHelperTest.php

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,40 @@
66

77
use PHPUnit\Framework\TestCase;
88
use Syndesi\CypherDataStructures\Type\Node;
9-
use Syndesi\CypherDataStructures\Type\NodeLabel;
10-
use Syndesi\CypherDataStructures\Type\PropertyName;
119
use Syndesi\CypherDataStructures\Type\Relation;
12-
use Syndesi\CypherDataStructures\Type\RelationType;
1310
use Syndesi\CypherEntityManager\Exception\InvalidArgumentException;
1411
use Syndesi\CypherEntityManager\Helper\StructureHelper;
1512

1613
class StructureHelperTest extends TestCase
1714
{
18-
public function testIdentifierStorageToString(): void
15+
public function testEmptyStatement(): void
16+
{
17+
$statement = StructureHelper::getEmptyStatement();
18+
$this->assertSame('MATCH (n) LIMIT 0', $statement->getText());
19+
}
20+
21+
public function testIdentifiersToStructure(): void
1922
{
2023
$node = (new Node())
21-
->addProperty(new PropertyName('id'), 1000)
22-
->addProperty(new PropertyName('_id'), 1001)
23-
->addProperty(new PropertyName('_z'), 1002)
24-
->addIdentifier(new PropertyName('id'))
25-
->addIdentifier(new PropertyName('_id'))
26-
->addIdentifier(new PropertyName('_z'));
24+
->addProperty('id', 1000)
25+
->addProperty('_id', 1001)
26+
->addProperty('_z', 1002)
27+
->addIdentifier('id')
28+
->addIdentifier('_id')
29+
->addIdentifier('_z');
2730
$this->assertSame(
2831
'_id, _z, id',
29-
StructureHelper::identifierStorageToString($node->getIdentifiers())
32+
StructureHelper::identifiersToStructure($node->getIdentifiers())
3033
);
3134
}
3235

3336
public function testGetNodeStructure(): void
3437
{
3538
$node = (new Node())
36-
->addNodeLabel(new NodeLabel('Node'))
37-
->addProperty(new PropertyName('id'), 1234)
38-
->addProperty(new PropertyName('someKey'), 'some value')
39-
->addIdentifier(new PropertyName('id'));
39+
->addLabel('Node')
40+
->addProperty('id', 1234)
41+
->addProperty('someKey', 'some value')
42+
->addIdentifier('id');
4043
$this->assertSame('(:Node id)', StructureHelper::getNodeStructure($node));
4144
}
4245

@@ -46,8 +49,8 @@ public function testInvalidGetNodeStructure(): void
4649
$this->markTestSkipped();
4750
}
4851
$node = (new Node())
49-
->addNodeLabel(new NodeLabel('Node'))
50-
->addProperty(new PropertyName('someKey'), 'some value');
52+
->addLabel('Node')
53+
->addProperty('someKey', 'some value');
5154
$this->expectException(InvalidArgumentException::class);
5255
$this->expectExceptionMessage('at least one identifier is required');
5356
StructureHelper::getNodeStructure($node);
@@ -56,21 +59,21 @@ public function testInvalidGetNodeStructure(): void
5659
public function testGetRelationStructure(): void
5760
{
5861
$startNode = (new Node())
59-
->addNodeLabel(new NodeLabel('StartNode'))
60-
->addProperty(new PropertyName('id'), 1234)
61-
->addIdentifier(new PropertyName('id'));
62+
->addLabel('StartNode')
63+
->addProperty('id', 1234)
64+
->addIdentifier('id');
6265

6366
$endNode = (new Node())
64-
->addNodeLabel(new NodeLabel('EndNode'))
65-
->addProperty(new PropertyName('id'), 4321)
66-
->addIdentifier(new PropertyName('id'));
67+
->addLabel('EndNode')
68+
->addProperty('id', 4321)
69+
->addIdentifier('id');
6770

6871
$relation = (new Relation())
69-
->setRelationType(new RelationType('RELATION'))
72+
->setType('RELATION')
7073
->setStartNode($startNode)
7174
->setEndNode($endNode)
72-
->addProperty(new PropertyName('id'), 1000)
73-
->addIdentifier(new PropertyName('id'));
75+
->addProperty('id', 1000)
76+
->addIdentifier('id');
7477

7578
$this->assertSame('(:StartNode id)-[RELATION id]->(:EndNode id)', StructureHelper::getRelationStructure($relation));
7679
}
@@ -81,18 +84,18 @@ public function testInvalidGetRelationStructureWithMissingStartNode(): void
8184
$this->markTestSkipped();
8285
}
8386
$endNode = (new Node())
84-
->addNodeLabel(new NodeLabel('EndNode'))
85-
->addProperty(new PropertyName('id'), 4321)
86-
->addIdentifier(new PropertyName('id'));
87+
->addLabel('EndNode')
88+
->addProperty('id', 4321)
89+
->addIdentifier('id');
8790

8891
$relation = (new Relation())
89-
->setRelationType(new RelationType('RELATION'))
92+
->setType('RELATION')
9093
->setEndNode($endNode)
91-
->addProperty(new PropertyName('id'), 1000)
92-
->addIdentifier(new PropertyName('id'));
94+
->addProperty('id', 1000)
95+
->addIdentifier('id');
9396

9497
$this->expectException(InvalidArgumentException::class);
95-
$this->expectExceptionMessage('start node can not be null');
98+
$this->expectExceptionMessage('Start node of relation can not be null');
9699
StructureHelper::getRelationStructure($relation);
97100
}
98101

@@ -102,18 +105,18 @@ public function testInvalidGetRelationStructureWithMissingEndNode(): void
102105
$this->markTestSkipped();
103106
}
104107
$startNode = (new Node())
105-
->addNodeLabel(new NodeLabel('StartNode'))
106-
->addProperty(new PropertyName('id'), 1234)
107-
->addIdentifier(new PropertyName('id'));
108+
->addLabel('StartNode')
109+
->addProperty('id', 1234)
110+
->addIdentifier('id');
108111

109112
$relation = (new Relation())
110-
->setRelationType(new RelationType('RELATION'))
113+
->setType('RELATION')
111114
->setStartNode($startNode)
112-
->addProperty(new PropertyName('id'), 1000)
113-
->addIdentifier(new PropertyName('id'));
115+
->addProperty('id', 1000)
116+
->addIdentifier('id');
114117

115118
$this->expectException(InvalidArgumentException::class);
116-
$this->expectExceptionMessage('end node can not be null');
119+
$this->expectExceptionMessage('End node of relation can not be null');
117120
StructureHelper::getRelationStructure($relation);
118121
}
119122

@@ -123,20 +126,20 @@ public function testInvalidGetRelationStructureWithMissingIdentifier(): void
123126
$this->markTestSkipped();
124127
}
125128
$startNode = (new Node())
126-
->addNodeLabel(new NodeLabel('StartNode'))
127-
->addProperty(new PropertyName('id'), 1234)
128-
->addIdentifier(new PropertyName('id'));
129+
->addLabel('StartNode')
130+
->addProperty('id', 1234)
131+
->addIdentifier('id');
129132

130133
$endNode = (new Node())
131-
->addNodeLabel(new NodeLabel('EndNode'))
132-
->addProperty(new PropertyName('id'), 4321)
133-
->addIdentifier(new PropertyName('id'));
134+
->addLabel('EndNode')
135+
->addProperty('id', 4321)
136+
->addIdentifier('id');
134137

135138
$relation = (new Relation())
136-
->setRelationType(new RelationType('RELATION'))
139+
->setType('RELATION')
137140
->setStartNode($startNode)
138141
->setEndNode($endNode)
139-
->addProperty(new PropertyName('id'), 1000);
142+
->addProperty('id', 1000);
140143

141144
$this->expectException(InvalidArgumentException::class);
142145
$this->expectExceptionMessage('at least one relation identifier is required');

0 commit comments

Comments
 (0)