From 06ba38f95a2225bdeea28fa66386dc0d472ab0a0 Mon Sep 17 00:00:00 2001 From: chvarkov Date: Fri, 3 May 2019 23:48:55 +0300 Subject: [PATCH] Implemented multiple labels ability. --- graphaware-mapping.xsd | 5 +- src/Annotations/Node.php | 4 +- src/Metadata/ClassMetadata.php | 6 +- .../NodeAnnotationMetadataFactory.php | 2 +- .../Factory/Xml/NodeEntityMetadataFactory.php | 4 +- src/Metadata/NodeAnnotationMetadata.php | 16 ++-- src/Metadata/NodeEntityMetadata.php | 6 +- src/Persister/EntityPersister.php | 6 +- src/Persister/FlushOperationProcessor.php | 4 +- src/Persisters/BasicEntityPersister.php | 24 ++--- tests/Community/Issue103/Context.php | 2 +- tests/Community/Issue103/Entity.php | 2 +- tests/Community/Issue21/TestUser.php | 2 +- .../TimestampConverterIntegrationTest.php | 2 +- tests/Integration/Models/Base/User.php | 2 +- .../Models/BooleanLabel/BlogPost.php | 2 +- .../EntityWithSimpleRelationship/Car.php | 2 +- .../ModelNumber.php | 2 +- .../EntityWithSimpleRelationship/Person.php | 2 +- .../Models/ManyToManyRelationship/Group.php | 2 +- .../Models/ManyToManyRelationship/User.php | 2 +- tests/Integration/Models/ManyToOne/Bag.php | 2 +- tests/Integration/Models/ManyToOne/Woman.php | 2 +- tests/Integration/Models/MoviesDemo/Movie.php | 2 +- .../Integration/Models/MoviesDemo/Person.php | 2 +- .../Models/MultipleLabelsEntity/Person.php | 95 +++++++++++++++++++ .../Models/MultipleLabelsEntity/Student.php | 68 +++++++++++++ .../Models/MultipleLabelsEntity/Worker.php | 63 ++++++++++++ .../NodePropertyKeyMapping/Employee.php | 2 +- .../Integration/Models/OneToManyRE/House.php | 2 +- .../Integration/Models/OneToManyRE/Owner.php | 2 +- .../Models/OrderedRelationships/Click.php | 2 +- .../Models/OrderedRelationships/Item.php | 2 +- .../RelationshipCollection/Building.php | 2 +- .../Models/RelationshipCollection/Floor.php | 2 +- .../RelationshipPropertyKeyMapping/Device.php | 2 +- .../Employee.php | 2 +- .../Models/RelationshipSameLabel/Building.php | 2 +- .../RelationshipSameLabel/Equipment.php | 2 +- .../Models/RelationshipSameLabel/Room.php | 2 +- .../Models/SimpleRelationshipEntity/Guest.php | 2 +- .../Models/SimpleRelationshipEntity/Hotel.php | 2 +- .../Integration/Models/SingleEntity/User.php | 2 +- tests/Integration/Models/Tree/Level.php | 2 +- .../Integration/MultipleLabelsEntityTest.php | 57 +++++++++++ ...RelationshipEntityBetweenSameModelTest.php | 2 +- tests/Mapping/NodeEntityWithCustomRepo.php | 2 +- tests/Metadata/Factory/Fixtures/Movie.php | 2 +- tests/Metadata/Factory/Fixtures/Person.php | 2 +- .../Factory/Fixtures/graphaware/Movie.ogm.xml | 2 +- .../Fixtures/graphaware/Person.ogm.xml | 2 +- .../GraphEntityMetadataFactoryTest.php | 4 +- tests/Proxy/Init.php | 2 +- tests/Proxy/Model/Account.php | 2 +- tests/Proxy/Model/Group.php | 2 +- tests/Proxy/Model/PHP7/Profile.php | 2 +- tests/Proxy/Model/PHP7/User.php | 2 +- tests/Proxy/Model/Profile.php | 2 +- tests/Proxy/Model/User.php | 2 +- tests/Proxy/Profile.php | 2 +- tests/Proxy/Related.php | 2 +- 61 files changed, 371 insertions(+), 85 deletions(-) create mode 100644 tests/Integration/Models/MultipleLabelsEntity/Person.php create mode 100644 tests/Integration/Models/MultipleLabelsEntity/Student.php create mode 100644 tests/Integration/Models/MultipleLabelsEntity/Worker.php create mode 100644 tests/Integration/MultipleLabelsEntityTest.php diff --git a/graphaware-mapping.xsd b/graphaware-mapping.xsd index 5677d09a..07cbee64 100644 --- a/graphaware-mapping.xsd +++ b/graphaware-mapping.xsd @@ -71,7 +71,7 @@ - + @@ -82,6 +82,9 @@ + + + diff --git a/src/Annotations/Node.php b/src/Annotations/Node.php index 433ac765..31d1cb98 100644 --- a/src/Annotations/Node.php +++ b/src/Annotations/Node.php @@ -18,9 +18,9 @@ final class Node implements Entity { /** - * @var string + * @var string[] */ - public $label; + public $labels; /** * @var string diff --git a/src/Metadata/ClassMetadata.php b/src/Metadata/ClassMetadata.php index a804c4e0..10637f3e 100644 --- a/src/Metadata/ClassMetadata.php +++ b/src/Metadata/ClassMetadata.php @@ -48,15 +48,15 @@ public function isRelationshipEntity() } /** - * @return string + * @return string[] */ - public function getLabel() + public function getLabels() { if (!$this->isNodeEntity()) { throw new MappingException(sprintf('This class metadata is not for a node entity')); } - return $this->entityAnnotation->label; + return $this->entityAnnotation->labels; } /** diff --git a/src/Metadata/Factory/Annotation/NodeAnnotationMetadataFactory.php b/src/Metadata/Factory/Annotation/NodeAnnotationMetadataFactory.php index 4e254167..995bb06e 100644 --- a/src/Metadata/Factory/Annotation/NodeAnnotationMetadataFactory.php +++ b/src/Metadata/Factory/Annotation/NodeAnnotationMetadataFactory.php @@ -43,7 +43,7 @@ public function create($nodeEntityClass) $annotation = $this->reader->getClassAnnotation($reflectionClass, Node::class); if (null !== $annotation) { - return new NodeAnnotationMetadata($annotation->label, $annotation->repository); + return new NodeAnnotationMetadata($annotation->labels, $annotation->repository); } throw new MappingException(sprintf('The class "%s" is missing the "%s" annotation', $nodeEntityClass, Node::class)); diff --git a/src/Metadata/Factory/Xml/NodeEntityMetadataFactory.php b/src/Metadata/Factory/Xml/NodeEntityMetadataFactory.php index d44ff429..b6bdf6f3 100644 --- a/src/Metadata/Factory/Xml/NodeEntityMetadataFactory.php +++ b/src/Metadata/Factory/Xml/NodeEntityMetadataFactory.php @@ -59,14 +59,14 @@ public function buildNodeEntityMetadata(\SimpleXMLElement $node, $className) */ private function buildNodeMetadata(\SimpleXMLElement $node, $className) { - if (!isset($node['label'])) { + if (!isset($node['labels'])) { throw new MappingException( sprintf('Class "%s" OGM XML node configuration is missing "label" attribute', $className) ); } return new NodeAnnotationMetadata( - (string) $node['label'], + \explode(' ',(string) $node['labels']), isset($node['repository-class']) ? (string) $node['repository-class'] : null ); } diff --git a/src/Metadata/NodeAnnotationMetadata.php b/src/Metadata/NodeAnnotationMetadata.php index ae87c52e..27352319 100644 --- a/src/Metadata/NodeAnnotationMetadata.php +++ b/src/Metadata/NodeAnnotationMetadata.php @@ -14,9 +14,9 @@ final class NodeAnnotationMetadata { /** - * @var string + * @var string[] */ - private $label; + private $labels; /** * @var string @@ -24,21 +24,21 @@ final class NodeAnnotationMetadata private $customRepository; /** - * @param string $label + * @param string[] $labels * @param string|null $repository */ - public function __construct($label, $repository) + public function __construct($labels, $repository) { - $this->label = $label; + $this->labels = $labels; $this->customRepository = $repository; } /** - * @return string + * @return string[] */ - public function getLabel() + public function getLabels() { - return $this->label; + return $this->labels; } /** diff --git a/src/Metadata/NodeEntityMetadata.php b/src/Metadata/NodeEntityMetadata.php index 64017cc7..65d9ee98 100644 --- a/src/Metadata/NodeEntityMetadata.php +++ b/src/Metadata/NodeEntityMetadata.php @@ -66,11 +66,11 @@ public function __construct( } /** - * @return string + * @return string[] */ - public function getLabel() + public function getLabels() { - return $this->nodeAnnotationMetadata->getLabel(); + return $this->nodeAnnotationMetadata->getLabels(); } /** diff --git a/src/Persister/EntityPersister.php b/src/Persister/EntityPersister.php index 22df3ba8..82e2b240 100644 --- a/src/Persister/EntityPersister.php +++ b/src/Persister/EntityPersister.php @@ -70,7 +70,7 @@ public function getCreateQuery($object) } } - $query = sprintf('CREATE (n:%s) SET n += {properties}', $this->classMetadata->getLabel()); + $query = sprintf('CREATE (n:%s) SET n += {properties}', \implode(':', $this->classMetadata->getLabels())); if (!empty($extraLabels)) { foreach ($extraLabels as $label) { $query .= ' SET n:'.$label; @@ -141,8 +141,8 @@ public function getUpdateQuery($object) */ public function refresh($id, $entity) { - $label = $this->classMetadata->getLabel(); - $query = sprintf('MATCH (n:%s) WHERE id(n) = {%s} RETURN n', $label, 'id'); + $label = $this->classMetadata->getLabels(); + $query = sprintf('MATCH (n:%s) WHERE id(n) = {%s} RETURN n', \implode(':', $label), 'id'); $result = $this->entityManager->getDatabaseDriver()->run($query, ['id' => $id]); if ($result->size() > 0) { diff --git a/src/Persister/FlushOperationProcessor.php b/src/Persister/FlushOperationProcessor.php index 97963492..313ab414 100644 --- a/src/Persister/FlushOperationProcessor.php +++ b/src/Persister/FlushOperationProcessor.php @@ -32,7 +32,7 @@ public function processNodesCreationJob(array $nodesScheduledForCreate) $byLabelsMap = []; foreach ($nodesScheduledForCreate as $node) { $metadata = $this->em->getClassMetadataFor(get_class($node)); - $byLabelsMap[$metadata->getLabel()][] = $node; + $byLabelsMap[\implode('`:`', $metadata->getLabels())][] = $node; } return $this->createLabeledNodesCreationStack($byLabelsMap); @@ -49,7 +49,7 @@ private function createLabeledNodesCreationStack(array $byLabelsMap) $metadata = $this->em->getClassMetadataFor(get_class($entity)); $oid = spl_object_hash($entity); $labeledProperties = $metadata->getLabeledPropertiesToBeSet($entity); - $lblKey = sprintf('%s_%s', $metadata->getLabel(), implode('_', array_map(function (LabeledPropertyMetadata $labeledPropertyMetadata) { + $lblKey = sprintf('%s_%s', \implode(':', $metadata->getLabels()), implode('_', array_map(function (LabeledPropertyMetadata $labeledPropertyMetadata) { return $labeledPropertyMetadata->getLabelName(); }, $labeledProperties))); diff --git a/src/Persisters/BasicEntityPersister.php b/src/Persisters/BasicEntityPersister.php index c7a6e672..150fbe15 100644 --- a/src/Persisters/BasicEntityPersister.php +++ b/src/Persisters/BasicEntityPersister.php @@ -144,8 +144,8 @@ public function getCountForRelationship($alias, $sourceEntity) public function getMatchCypher(array $criteria = [], $orderBy = null, $limit = null, $offset = null) { $identifier = $this->_classMetadata->getEntityAlias(); - $classLabel = $this->_classMetadata->getLabel(); - $cypher = 'MATCH ('.$identifier.':'.$classLabel.') '; + $classLabels = $this->_classMetadata->getLabels(); + $cypher = 'MATCH ('.$identifier.':'.\implode(':', $classLabels).') '; $filter_cursor = 0; $params = []; @@ -188,7 +188,7 @@ private function getSimpleRelationshipStatement($alias, $sourceEntity) $relationshipMeta = $this->_classMetadata->getRelationship($alias); $relAlias = $relationshipMeta->getAlias(); $targetMetadata = $this->_em->getClassMetadataFor($relationshipMeta->getTargetEntity()); - $targetClassLabel = $targetMetadata->getLabel(); + $targetClassLabels = $targetMetadata->getLabels(); $targetAlias = $targetMetadata->getEntityAlias(); $sourceEntityId = $this->_classMetadata->getIdValue($sourceEntity); $relationshipType = $relationshipMeta->getType(); @@ -199,7 +199,7 @@ private function getSimpleRelationshipStatement($alias, $sourceEntity) $relPattern = sprintf('%s-[%s:`%s`]-%s', $isIncoming, $relAlias, $relationshipType, $isOutgoing); $cypher = 'MATCH (n) WHERE id(n) = {id} '; - $cypher .= 'MATCH (n)'.$relPattern.'('.$targetAlias.($targetClassLabel != null ? ':' . $targetClassLabel : '').') '; + $cypher .= 'MATCH (n)'.$relPattern.'('.$targetAlias.($targetClassLabels != null ? ':' . \implode(':', $targetClassLabels) : '').') '; $cypher .= 'RETURN '.$targetAlias; $params = ['id' => (int) $sourceEntityId]; @@ -237,7 +237,7 @@ private function getSimpleRelationshipCollectionStatement($alias, $sourceEntity) $relationshipMeta = $this->_classMetadata->getRelationship($alias); $relAlias = $relationshipMeta->getAlias(); $targetMetadata = $this->_em->getClassMetadataFor($relationshipMeta->getTargetEntity()); - $targetClassLabel = $targetMetadata->getLabel(); + $targetClassLabels = $targetMetadata->getLabels(); $targetAlias = $targetMetadata->getEntityAlias(); $sourceEntityId = $this->_classMetadata->getIdValue($sourceEntity); $relationshipType = $relationshipMeta->getType(); @@ -248,7 +248,7 @@ private function getSimpleRelationshipCollectionStatement($alias, $sourceEntity) $relPattern = sprintf('%s-[%s:`%s`]-%s', $isIncoming, $relAlias, $relationshipType, $isOutgoing); $cypher = 'MATCH (n) WHERE id(n) = {id} '; - $cypher .= 'MATCH (n)'.$relPattern.'('.$targetAlias.($targetClassLabel != null ? ':' . $targetClassLabel : '').') '; + $cypher .= 'MATCH (n)'.$relPattern.'('.$targetAlias.($targetClassLabels != null ? ':' . \implode(':', $targetClassLabels) : '').') '; $cypher .= 'RETURN '.$targetAlias.' AS '.$targetAlias.' '; if ($relationshipMeta->hasOrderBy()) { @@ -263,8 +263,8 @@ private function getSimpleRelationshipCollectionStatement($alias, $sourceEntity) private function getMatchOneByIdCypher($id) { $identifier = $this->_classMetadata->getEntityAlias(); - $label = $this->_classMetadata->getLabel(); - $cypher = 'MATCH ('.$identifier.':`'.$label.'`) WHERE id('.$identifier.') = {id} RETURN '.$identifier; + $labels = $this->_classMetadata->getLabels(); + $cypher = 'MATCH ('.$identifier.':`'.\implode('`:`', $labels).'`) WHERE id('.$identifier.') = {id} RETURN '.$identifier; $params = ['id' => (int) $id]; return Statement::create($cypher, $params); @@ -274,11 +274,11 @@ private function getDegreeStatement($alias, $sourceEntity) { $relationshipMeta = $this->_classMetadata->getRelationship($alias); $relAlias = $relationshipMeta->getAlias(); - $targetClassLabel = ''; + $targetClassLabels = ''; if ($relationshipMeta->isRelationshipEntity() === false && $relationshipMeta->isTargetEntity() === true) { $targetMetadata = $this->_em->getClassMetadataFor($relationshipMeta->getTargetEntity()); - if ($targetMetadata->getLabel() != null) { - $targetClassLabel = ':'.$targetMetadata->getLabel(); + if ($targetMetadata->getLabels() != null) { + $targetClassLabels = ':'. \implode(':', $targetMetadata->getLabels()); } } $sourceEntityId = $this->_classMetadata->getIdValue($sourceEntity); @@ -290,7 +290,7 @@ private function getDegreeStatement($alias, $sourceEntity) $relPattern = sprintf('%s-[:`%s`]-%s', $isIncoming, $relationshipType, $isOutgoing); $cypher = 'MATCH (n) WHERE id(n) = {id} '; - $cypher .= 'RETURN size((n)'.$relPattern.'('.$targetClassLabel.')) '; + $cypher .= 'RETURN size((n)'.$relPattern.'('.$targetClassLabels.')) '; $cypher .= 'AS '.$alias; return Statement::create($cypher, ['id' => $sourceEntityId]); diff --git a/tests/Community/Issue103/Context.php b/tests/Community/Issue103/Context.php index 1a3a285e..5be40b7b 100644 --- a/tests/Community/Issue103/Context.php +++ b/tests/Community/Issue103/Context.php @@ -6,7 +6,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Context") + * @OGM\Node(labels={"Context"}) */ class Context { diff --git a/tests/Community/Issue103/Entity.php b/tests/Community/Issue103/Entity.php index 12a6a828..2e251112 100644 --- a/tests/Community/Issue103/Entity.php +++ b/tests/Community/Issue103/Entity.php @@ -6,7 +6,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Entity") + * @OGM\Node(labels={"Entity"}) */ class Entity { diff --git a/tests/Community/Issue21/TestUser.php b/tests/Community/Issue21/TestUser.php index 940eb8ae..efad2a90 100644 --- a/tests/Community/Issue21/TestUser.php +++ b/tests/Community/Issue21/TestUser.php @@ -17,7 +17,7 @@ /** * Class TestUser. * - * @OGM\Node(label="TestUser") + * @OGM\Node(labels={"TestUser"}) */ class TestUser implements \JsonSerializable { diff --git a/tests/Integration/Convert/TimestampConverterIntegrationTest.php b/tests/Integration/Convert/TimestampConverterIntegrationTest.php index 6b65f3c2..cfb4729f 100644 --- a/tests/Integration/Convert/TimestampConverterIntegrationTest.php +++ b/tests/Integration/Convert/TimestampConverterIntegrationTest.php @@ -113,7 +113,7 @@ public function testTimestampOnRelationshipEntityIsConverted() * Class TimestampConverterEntity * @package GraphAware\Neo4j\OGM\Tests\Integration\Convert * - * @OGM\Node(label="Entity") + * @OGM\Node(labels={"Entity"}) */ class TimestampConverterEntity { diff --git a/tests/Integration/Models/Base/User.php b/tests/Integration/Models/Base/User.php index c29213da..b7eba871 100644 --- a/tests/Integration/Models/Base/User.php +++ b/tests/Integration/Models/Base/User.php @@ -16,7 +16,7 @@ /** * Class User. * - * @OGM\Node(label="User") + * @OGM\Node(labels={"User"}) */ class User { diff --git a/tests/Integration/Models/BooleanLabel/BlogPost.php b/tests/Integration/Models/BooleanLabel/BlogPost.php index c205c57a..c7aedd05 100644 --- a/tests/Integration/Models/BooleanLabel/BlogPost.php +++ b/tests/Integration/Models/BooleanLabel/BlogPost.php @@ -16,7 +16,7 @@ /** * Class BlogPost. * - * @OGM\Node(label="BlogPost") + * @OGM\Node(labels={"BlogPost"}) */ class BlogPost { diff --git a/tests/Integration/Models/EntityWithSimpleRelationship/Car.php b/tests/Integration/Models/EntityWithSimpleRelationship/Car.php index 3ef2f9b7..14b2f937 100644 --- a/tests/Integration/Models/EntityWithSimpleRelationship/Car.php +++ b/tests/Integration/Models/EntityWithSimpleRelationship/Car.php @@ -16,7 +16,7 @@ /** * Class Car. * - * @OGM\Node(label="Car") + * @OGM\Node(labels={"Car"}) */ class Car { diff --git a/tests/Integration/Models/EntityWithSimpleRelationship/ModelNumber.php b/tests/Integration/Models/EntityWithSimpleRelationship/ModelNumber.php index dc003acd..5ef02ac7 100644 --- a/tests/Integration/Models/EntityWithSimpleRelationship/ModelNumber.php +++ b/tests/Integration/Models/EntityWithSimpleRelationship/ModelNumber.php @@ -16,7 +16,7 @@ /** * Class ModelNumber. * - * @OGM\Node(label="ModelNumber") + * @OGM\Node(labels={"ModelNumber"}) */ class ModelNumber { diff --git a/tests/Integration/Models/EntityWithSimpleRelationship/Person.php b/tests/Integration/Models/EntityWithSimpleRelationship/Person.php index 3ab966a6..92fbc647 100644 --- a/tests/Integration/Models/EntityWithSimpleRelationship/Person.php +++ b/tests/Integration/Models/EntityWithSimpleRelationship/Person.php @@ -16,7 +16,7 @@ /** * Class Person. * - * @OGM\Node(label="Person") + * @OGM\Node(labels={"Person"}) */ class Person { diff --git a/tests/Integration/Models/ManyToManyRelationship/Group.php b/tests/Integration/Models/ManyToManyRelationship/Group.php index 5e957613..374c8c90 100644 --- a/tests/Integration/Models/ManyToManyRelationship/Group.php +++ b/tests/Integration/Models/ManyToManyRelationship/Group.php @@ -17,7 +17,7 @@ /** * Class Group. * - * @OGM\Node(label="Group") + * @OGM\Node(labels={"Group"}) */ class Group { diff --git a/tests/Integration/Models/ManyToManyRelationship/User.php b/tests/Integration/Models/ManyToManyRelationship/User.php index ebf5c06b..dab64e9c 100644 --- a/tests/Integration/Models/ManyToManyRelationship/User.php +++ b/tests/Integration/Models/ManyToManyRelationship/User.php @@ -17,7 +17,7 @@ /** * Class User. * - * @OGM\Node(label="User") + * @OGM\Node(labels={"User"}) */ class User { diff --git a/tests/Integration/Models/ManyToOne/Bag.php b/tests/Integration/Models/ManyToOne/Bag.php index 42afb1ff..6a125f75 100644 --- a/tests/Integration/Models/ManyToOne/Bag.php +++ b/tests/Integration/Models/ManyToOne/Bag.php @@ -8,7 +8,7 @@ * Class Bag * @package GraphAware\Neo4j\OGM\Tests\Integration\Models\ManyToOne * - * @OGM\Node(label="Bag") + * @OGM\Node(labels={"Bag"}) */ class Bag { diff --git a/tests/Integration/Models/ManyToOne/Woman.php b/tests/Integration/Models/ManyToOne/Woman.php index 94693ad8..ff11f1d1 100644 --- a/tests/Integration/Models/ManyToOne/Woman.php +++ b/tests/Integration/Models/ManyToOne/Woman.php @@ -8,7 +8,7 @@ * Class Woman * @package GraphAware\Neo4j\OGM\Tests\Integration\Models\ManyToOne * - * @OGM\Node(label="Woman") + * @OGM\Node(labels={"Woman"}) */ class Woman { diff --git a/tests/Integration/Models/MoviesDemo/Movie.php b/tests/Integration/Models/MoviesDemo/Movie.php index 9d56ceb4..82ef9f0d 100644 --- a/tests/Integration/Models/MoviesDemo/Movie.php +++ b/tests/Integration/Models/MoviesDemo/Movie.php @@ -17,7 +17,7 @@ /** * Class Movie. * - * @OGM\Node(label="Movie", repository="GraphAware\Neo4j\OGM\Tests\Integration\Repository\MoviesCustomRepository") + * @OGM\Node(labels={"Movie"}, repository="GraphAware\Neo4j\OGM\Tests\Integration\Repository\MoviesCustomRepository") */ class Movie { diff --git a/tests/Integration/Models/MoviesDemo/Person.php b/tests/Integration/Models/MoviesDemo/Person.php index a0b93526..bbb0067c 100644 --- a/tests/Integration/Models/MoviesDemo/Person.php +++ b/tests/Integration/Models/MoviesDemo/Person.php @@ -17,7 +17,7 @@ /** * Class Person. * - * @OGM\Node(label="Person") + * @OGM\Node(labels={"Person"}) */ class Person { diff --git a/tests/Integration/Models/MultipleLabelsEntity/Person.php b/tests/Integration/Models/MultipleLabelsEntity/Person.php new file mode 100644 index 00000000..fddd5b8c --- /dev/null +++ b/tests/Integration/Models/MultipleLabelsEntity/Person.php @@ -0,0 +1,95 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace GraphAware\Neo4j\OGM\Tests\Integration\Models\MultipleLabelsEntity; + +use GraphAware\Neo4j\OGM\Annotations as OGM; + +/** + * Class Person. + * + * @OGM\Node(labels={"Person"}) + */ +class Person +{ + /** + * @var int + * + * @OGM\GraphId() + */ + protected $id; + + /** + * @var string + * + * @OGM\Property(type="string", nullable=false) + */ + protected $first; + + /** + * @var string + * + * @OGM\Property(type="string", nullable=false) + */ + protected $last; + + /** + * Person constructor. + * + * @param string $first + * @param string $last + */ + public function __construct($first, $last) + { + $this->first = $first; + $this->last = $last; + } + + /** + * @return string + */ + public function getFirst() + { + return $this->first; + } + + /** + * @param $first + * + * @return $this + */ + public function setFirst($first) + { + $this->first = $first; + + return $this; + } + + /** + * @return string + */ + public function getLast() + { + return $this->last; + } + + /** + * @param $last + * + * @return $this + */ + public function setLast($last) + { + $this->last = $last; + + return $this; + } +} diff --git a/tests/Integration/Models/MultipleLabelsEntity/Student.php b/tests/Integration/Models/MultipleLabelsEntity/Student.php new file mode 100644 index 00000000..eef0703b --- /dev/null +++ b/tests/Integration/Models/MultipleLabelsEntity/Student.php @@ -0,0 +1,68 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace GraphAware\Neo4j\OGM\Tests\Integration\Models\MultipleLabelsEntity; + +use GraphAware\Neo4j\OGM\Annotations as OGM; + +/** + * Class Student. + * + * @OGM\Node(labels={"Student", "Person"}) + */ +class Student extends Person +{ + /** + * @OGM\GraphId + */ + protected $id; + + /** + * @var int + * + * @OGM\Property(type="int", nullable=false) + */ + private $course; + + /** + * Student constructor. + * + * @param $first + * @param $last + * @param $course + */ + public function __construct($first, $last, $course) + { + parent::__construct($first, $last); + + $this->course = $course; + } + + /** + * @return string + */ + public function getCourse() + { + return $this->course; + } + + /** + * @param $course + * + * @return $this + */ + public function setCourse($course) + { + $this->course = $course; + + return $this; + } +} diff --git a/tests/Integration/Models/MultipleLabelsEntity/Worker.php b/tests/Integration/Models/MultipleLabelsEntity/Worker.php new file mode 100644 index 00000000..ccf74d63 --- /dev/null +++ b/tests/Integration/Models/MultipleLabelsEntity/Worker.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace GraphAware\Neo4j\OGM\Tests\Integration\Models\MultipleLabelsEntity; + +use GraphAware\Neo4j\OGM\Annotations as OGM; + +/** + * Class Worker. + * + * @OGM\Node(labels={"Worker", "Person"}) + */ +class Worker extends Person +{ + /** + * @var string + * + * @OGM\Property(type="string", nullable=false) + */ + private $company; + + /** + * Student constructor. + * + * @param $first + * @param $last + * @param $company + */ + public function __construct($first, $last, $company) + { + parent::__construct($first, $last); + + $this->company = $company; + } + + /** + * @return string + */ + public function getCompany() + { + return $this->company; + } + + /** + * @param $company + * + * @return $this + */ + public function setCompany($company) + { + $this->company = $company; + + return $this; + } +} diff --git a/tests/Integration/Models/NodePropertyKeyMapping/Employee.php b/tests/Integration/Models/NodePropertyKeyMapping/Employee.php index 8e7d5513..bae387d1 100644 --- a/tests/Integration/Models/NodePropertyKeyMapping/Employee.php +++ b/tests/Integration/Models/NodePropertyKeyMapping/Employee.php @@ -16,7 +16,7 @@ /** * Class Employee. * - * @OGM\Node(label="Employee") + * @OGM\Node(labels={"Employee"}) */ class Employee { diff --git a/tests/Integration/Models/OneToManyRE/House.php b/tests/Integration/Models/OneToManyRE/House.php index e75ca0d5..47f690f5 100644 --- a/tests/Integration/Models/OneToManyRE/House.php +++ b/tests/Integration/Models/OneToManyRE/House.php @@ -16,7 +16,7 @@ /** * Class House. * - * @OGM\Node(label="House") + * @OGM\Node(labels={"House"}) */ class House { diff --git a/tests/Integration/Models/OneToManyRE/Owner.php b/tests/Integration/Models/OneToManyRE/Owner.php index b2398309..0b1837d3 100644 --- a/tests/Integration/Models/OneToManyRE/Owner.php +++ b/tests/Integration/Models/OneToManyRE/Owner.php @@ -17,7 +17,7 @@ /** * Class Owner. * - * @OGM\Node(label="Owner") + * @OGM\Node(labels={"Owner"}) */ class Owner { diff --git a/tests/Integration/Models/OrderedRelationships/Click.php b/tests/Integration/Models/OrderedRelationships/Click.php index 27071c16..80ef6d45 100644 --- a/tests/Integration/Models/OrderedRelationships/Click.php +++ b/tests/Integration/Models/OrderedRelationships/Click.php @@ -16,7 +16,7 @@ /** * Class Click. * - * @OGM\Node(label="Click") + * @OGM\Node(labels={"Click"}) */ class Click { diff --git a/tests/Integration/Models/OrderedRelationships/Item.php b/tests/Integration/Models/OrderedRelationships/Item.php index 8b1fcf2f..7d4dc896 100644 --- a/tests/Integration/Models/OrderedRelationships/Item.php +++ b/tests/Integration/Models/OrderedRelationships/Item.php @@ -17,7 +17,7 @@ /** * Class Item. * - * @OGM\Node(label="Item") + * @OGM\Node(labels={"Item"}) */ class Item { diff --git a/tests/Integration/Models/RelationshipCollection/Building.php b/tests/Integration/Models/RelationshipCollection/Building.php index 8feed6b8..1c9b33f8 100644 --- a/tests/Integration/Models/RelationshipCollection/Building.php +++ b/tests/Integration/Models/RelationshipCollection/Building.php @@ -17,7 +17,7 @@ /** * Class Building. * - * @OGM\Node(label="Building") + * @OGM\Node(labels={"Building"}) */ class Building { diff --git a/tests/Integration/Models/RelationshipCollection/Floor.php b/tests/Integration/Models/RelationshipCollection/Floor.php index 9e871ceb..d9e13ada 100644 --- a/tests/Integration/Models/RelationshipCollection/Floor.php +++ b/tests/Integration/Models/RelationshipCollection/Floor.php @@ -16,7 +16,7 @@ /** * Class Floor. * - * @OGM\Node(label="Floor") + * @OGM\Node(labels={"Floor"}) */ class Floor { diff --git a/tests/Integration/Models/RelationshipPropertyKeyMapping/Device.php b/tests/Integration/Models/RelationshipPropertyKeyMapping/Device.php index 6e2c9608..f8afc2e9 100644 --- a/tests/Integration/Models/RelationshipPropertyKeyMapping/Device.php +++ b/tests/Integration/Models/RelationshipPropertyKeyMapping/Device.php @@ -16,7 +16,7 @@ /** * Class Device. * - * @OGM\Node(label="Device") + * @OGM\Node(labels={"Device"}) */ class Device { diff --git a/tests/Integration/Models/RelationshipPropertyKeyMapping/Employee.php b/tests/Integration/Models/RelationshipPropertyKeyMapping/Employee.php index f2384564..040b494a 100644 --- a/tests/Integration/Models/RelationshipPropertyKeyMapping/Employee.php +++ b/tests/Integration/Models/RelationshipPropertyKeyMapping/Employee.php @@ -16,7 +16,7 @@ /** * Class Employee. * - * @OGM\Node(label="Employee") + * @OGM\Node(labels={"Employee"}) */ class Employee { diff --git a/tests/Integration/Models/RelationshipSameLabel/Building.php b/tests/Integration/Models/RelationshipSameLabel/Building.php index 5329fd86..366bd370 100644 --- a/tests/Integration/Models/RelationshipSameLabel/Building.php +++ b/tests/Integration/Models/RelationshipSameLabel/Building.php @@ -17,7 +17,7 @@ /** * Class Building. * - * @OGM\Node(label="Building") + * @OGM\Node(labels={"Building"}) */ class Building { diff --git a/tests/Integration/Models/RelationshipSameLabel/Equipment.php b/tests/Integration/Models/RelationshipSameLabel/Equipment.php index 01dc8d8b..7a88ee4f 100644 --- a/tests/Integration/Models/RelationshipSameLabel/Equipment.php +++ b/tests/Integration/Models/RelationshipSameLabel/Equipment.php @@ -17,7 +17,7 @@ /** * Class Equipment. * - * @OGM\Node(label="Equipment") + * @OGM\Node(labels={"Equipment"}) */ class Equipment { diff --git a/tests/Integration/Models/RelationshipSameLabel/Room.php b/tests/Integration/Models/RelationshipSameLabel/Room.php index 773b4382..0a715784 100644 --- a/tests/Integration/Models/RelationshipSameLabel/Room.php +++ b/tests/Integration/Models/RelationshipSameLabel/Room.php @@ -17,7 +17,7 @@ /** * Class Room. * - * @OGM\Node(label="Room") + * @OGM\Node(labels={"Room"}) */ class Room { diff --git a/tests/Integration/Models/SimpleRelationshipEntity/Guest.php b/tests/Integration/Models/SimpleRelationshipEntity/Guest.php index 08acf646..50090171 100644 --- a/tests/Integration/Models/SimpleRelationshipEntity/Guest.php +++ b/tests/Integration/Models/SimpleRelationshipEntity/Guest.php @@ -16,7 +16,7 @@ /** * Class Guest. * - * @OGM\Node(label="Guest") + * @OGM\Node(labels={"Guest"}) */ class Guest { diff --git a/tests/Integration/Models/SimpleRelationshipEntity/Hotel.php b/tests/Integration/Models/SimpleRelationshipEntity/Hotel.php index a9243de9..d9a471fc 100644 --- a/tests/Integration/Models/SimpleRelationshipEntity/Hotel.php +++ b/tests/Integration/Models/SimpleRelationshipEntity/Hotel.php @@ -16,7 +16,7 @@ /** * Class Hotel. * - * @OGM\Node(label="Hotel") + * @OGM\Node(labels={"Hotel"}) */ class Hotel { diff --git a/tests/Integration/Models/SingleEntity/User.php b/tests/Integration/Models/SingleEntity/User.php index fe987096..21af4059 100644 --- a/tests/Integration/Models/SingleEntity/User.php +++ b/tests/Integration/Models/SingleEntity/User.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="User") + * @OGM\Node(labels={"User"}) */ class User { diff --git a/tests/Integration/Models/Tree/Level.php b/tests/Integration/Models/Tree/Level.php index d85e54c4..415f7bda 100644 --- a/tests/Integration/Models/Tree/Level.php +++ b/tests/Integration/Models/Tree/Level.php @@ -8,7 +8,7 @@ /** * - * @OGM\Node(label="Level") + * @OGM\Node(labels={"Level"}) */ class Level { diff --git a/tests/Integration/MultipleLabelsEntityTest.php b/tests/Integration/MultipleLabelsEntityTest.php new file mode 100644 index 00000000..8bb1225c --- /dev/null +++ b/tests/Integration/MultipleLabelsEntityTest.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace GraphAware\Neo4j\OGM\Tests\Integration; + + +use GraphAware\Neo4j\OGM\Tests\Integration\Models\MultipleLabelsEntity\Person; +use GraphAware\Neo4j\OGM\Tests\Integration\Models\MultipleLabelsEntity\Student; +use GraphAware\Neo4j\OGM\Tests\Integration\Models\MultipleLabelsEntity\Worker; + +class MultipleLabelsEntityTest extends IntegrationTestCase +{ + public function setUp() + { + parent::setUp(); + $this->clearDb(); + } + + public function testUsage() + { + $student = new Student('First student', 'Last student', 4); + $this->em->persist($student); + + $worker = new Worker('First worker', 'Last worker', 'ITSM'); + $this->em->persist($worker); + + $this->em->flush(); + + $persons = $this->em->getRepository(Person::class)->findAll(); + self::assertCount(2, $persons); + + foreach ($persons as $person) { + self::assertInstanceOf(Person::class, $person); + } + + $student = $this->em->getRepository(Student::class)->findOneBy(['first' => 'First student']); + self::assertInstanceOf(Student::class, $student); + + $worker = $this->em->getRepository(Worker::class)->findOneBy(['company' => 'ITSM']); + self::assertInstanceOf(Worker::class, $worker); + + $this->em->remove($student); + $this->em->remove($worker); + $this->em->flush(); + + $persons = $this->em->getRepository(Person::class)->findAll(); + self::assertCount(0, $persons); + } +} diff --git a/tests/Integration/RelationshipEntityBetweenSameModelTest.php b/tests/Integration/RelationshipEntityBetweenSameModelTest.php index bb7db308..51c1f5db 100644 --- a/tests/Integration/RelationshipEntityBetweenSameModelTest.php +++ b/tests/Integration/RelationshipEntityBetweenSameModelTest.php @@ -142,7 +142,7 @@ public function testUserWithReCanBeRetrievedChain() /** * - * @OGM\Node(label="User") + * @OGM\Node(labels={"User"}) */ class SystemUser { diff --git a/tests/Mapping/NodeEntityWithCustomRepo.php b/tests/Mapping/NodeEntityWithCustomRepo.php index 35d0b21a..b63470e6 100644 --- a/tests/Mapping/NodeEntityWithCustomRepo.php +++ b/tests/Mapping/NodeEntityWithCustomRepo.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Dummy", repository="DummyRepository") + * @OGM\Node(labels={"Dummy"}, repository="DummyRepository") */ class NodeEntityWithCustomRepo { diff --git a/tests/Metadata/Factory/Fixtures/Movie.php b/tests/Metadata/Factory/Fixtures/Movie.php index 303ac434..44131086 100644 --- a/tests/Metadata/Factory/Fixtures/Movie.php +++ b/tests/Metadata/Factory/Fixtures/Movie.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Movie",repository="GraphAware\Neo4j\OGM\Tests\Metadata\Factory\Fixtures\MovieRepository") + * @OGM\Node(labels={"Movie"},repository="GraphAware\Neo4j\OGM\Tests\Metadata\Factory\Fixtures\MovieRepository") */ class Movie { diff --git a/tests/Metadata/Factory/Fixtures/Person.php b/tests/Metadata/Factory/Fixtures/Person.php index f4aa8930..066d27c9 100644 --- a/tests/Metadata/Factory/Fixtures/Person.php +++ b/tests/Metadata/Factory/Fixtures/Person.php @@ -15,7 +15,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Person") + * @OGM\Node(labels={"Person"}) */ class Person { diff --git a/tests/Metadata/Factory/Fixtures/graphaware/Movie.ogm.xml b/tests/Metadata/Factory/Fixtures/graphaware/Movie.ogm.xml index 6acd6e70..7dcd75a8 100644 --- a/tests/Metadata/Factory/Fixtures/graphaware/Movie.ogm.xml +++ b/tests/Metadata/Factory/Fixtures/graphaware/Movie.ogm.xml @@ -2,7 +2,7 @@ - diff --git a/tests/Metadata/Factory/Fixtures/graphaware/Person.ogm.xml b/tests/Metadata/Factory/Fixtures/graphaware/Person.ogm.xml index 26bc2094..dca3221d 100644 --- a/tests/Metadata/Factory/Fixtures/graphaware/Person.ogm.xml +++ b/tests/Metadata/Factory/Fixtures/graphaware/Person.ogm.xml @@ -2,7 +2,7 @@ - + diff --git a/tests/Metadata/Factory/GraphEntityMetadataFactoryTest.php b/tests/Metadata/Factory/GraphEntityMetadataFactoryTest.php index 61334888..e4c0e9a6 100644 --- a/tests/Metadata/Factory/GraphEntityMetadataFactoryTest.php +++ b/tests/Metadata/Factory/GraphEntityMetadataFactoryTest.php @@ -137,7 +137,7 @@ private function assertRatingMetadata($metadata) */ private function assertPersonMetadata($metadata) { - $this->assertSame('Person', $metadata->getLabel()); + $this->assertSame('Person', $metadata->getLabels()); $this->assertSame(false, $metadata->hasCustomRepository()); $this->assertSame('id', $metadata->getIdentifier()); @@ -186,7 +186,7 @@ private function assertPersonMetadata($metadata) */ private function assertMovieMetadata($metadata) { - $this->assertSame('Movie', $metadata->getLabel()); + $this->assertSame('Movie', $metadata->getLabels()); $this->assertSame(MovieRepository::class, $metadata->getRepositoryClass()); $this->assertSame('id', $metadata->getIdentifier()); diff --git a/tests/Proxy/Init.php b/tests/Proxy/Init.php index 7d4a6e71..b2e66507 100644 --- a/tests/Proxy/Init.php +++ b/tests/Proxy/Init.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Init") + * @OGM\Node(labels={"Init"}) * * Class Init */ diff --git a/tests/Proxy/Model/Account.php b/tests/Proxy/Model/Account.php index 430792bc..350b9cc2 100644 --- a/tests/Proxy/Model/Account.php +++ b/tests/Proxy/Model/Account.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Account") + * @OGM\Node(labels={"Account"}) */ class Account { diff --git a/tests/Proxy/Model/Group.php b/tests/Proxy/Model/Group.php index 57ee01d3..9a9de6d1 100644 --- a/tests/Proxy/Model/Group.php +++ b/tests/Proxy/Model/Group.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Group") + * @OGM\Node(labels={"Group"}) */ class Group { diff --git a/tests/Proxy/Model/PHP7/Profile.php b/tests/Proxy/Model/PHP7/Profile.php index 48a69ce5..9578bc2c 100644 --- a/tests/Proxy/Model/PHP7/Profile.php +++ b/tests/Proxy/Model/PHP7/Profile.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Profile") + * @OGM\Node(labels={"Profile"}) */ class Profile { diff --git a/tests/Proxy/Model/PHP7/User.php b/tests/Proxy/Model/PHP7/User.php index 6cdf36ca..94721160 100644 --- a/tests/Proxy/Model/PHP7/User.php +++ b/tests/Proxy/Model/PHP7/User.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="User") + * @OGM\Node(labels={"User"}) */ class User { diff --git a/tests/Proxy/Model/Profile.php b/tests/Proxy/Model/Profile.php index 7338dc00..e07cae08 100644 --- a/tests/Proxy/Model/Profile.php +++ b/tests/Proxy/Model/Profile.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Profile") + * @OGM\Node(labels={"Profile"}) */ class Profile { diff --git a/tests/Proxy/Model/User.php b/tests/Proxy/Model/User.php index b6ec9c46..eb9f7be8 100644 --- a/tests/Proxy/Model/User.php +++ b/tests/Proxy/Model/User.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="User") + * @OGM\Node(labels={"User"}) */ class User { diff --git a/tests/Proxy/Profile.php b/tests/Proxy/Profile.php index 770692c4..638d37fe 100644 --- a/tests/Proxy/Profile.php +++ b/tests/Proxy/Profile.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Profile") + * @OGM\Node(labels={"Profile"}) */ class Profile { diff --git a/tests/Proxy/Related.php b/tests/Proxy/Related.php index 85c016cd..a04dc89b 100644 --- a/tests/Proxy/Related.php +++ b/tests/Proxy/Related.php @@ -14,7 +14,7 @@ use GraphAware\Neo4j\OGM\Annotations as OGM; /** - * @OGM\Node(label="Related") + * @OGM\Node(labels={"Related"}) * * Class Related */