From f4dda9f278148010fb50d35bd2006fbede37306c Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 8 Jan 2024 17:50:29 +0100 Subject: [PATCH] allow doctrine/persistence 3 --- .github/workflows/static.yml | 2 +- .github/workflows/test-application.yaml | 12 +- CHANGELOG.md | 12 +- composer.json | 6 +- lib/Doctrine/ODM/PHPCR/ChildrenCollection.php | 49 ++-- lib/Doctrine/ODM/PHPCR/Configuration.php | 33 --- .../Decorator/DocumentManagerDecorator.php | 6 +- lib/Doctrine/ODM/PHPCR/DocumentManager.php | 37 +-- .../ODM/PHPCR/DocumentManagerInterface.php | 26 +- .../PHPCR/ImmutableReferrersCollection.php | 14 +- .../PHPCR/Mapping/ClassMetadataFactory.php | 5 - .../ODM/PHPCR/PersistentCollection.php | 44 ++-- .../Tests/ODM/PHPCR/ConfigurationTest.php | 33 --- .../Functional/FindTypeValidationTest.php | 5 +- .../Functional/Hierarchy/ChildrenTest.php | 8 +- .../Tests/ODM/PHPCR/Functional/MergeTest.php | 241 ------------------ .../ODM/PHPCR/Functional/QueryBuilderTest.php | 5 +- .../Versioning/VersioningTestAbstract.php | 18 -- 18 files changed, 102 insertions(+), 454 deletions(-) delete mode 100644 tests/Doctrine/Tests/ODM/PHPCR/ConfigurationTest.php delete mode 100644 tests/Doctrine/Tests/ODM/PHPCR/Functional/MergeTest.php diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 007d37859..936eb3331 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -17,7 +17,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.3' extensions: "curl,dom,json,xml,dom" coverage: none diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index ed7107c6e..1a23e1c08 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -27,7 +27,6 @@ jobs: matrix: php-version: - - '8.0' - '8.1' - '8.2' - '8.3' @@ -35,12 +34,9 @@ jobs: symfony-version: ['*'] jackalope-version: ['1.*'] include: - - php-version: '8.0' + - php-version: '8.1' dependencies: lowest symfony-version: '*' - - php-version: '8.0' - dependencies: highest - symfony-version: '6.*' - php-version: '8.1' dependencies: highest symfony-version: '5.4.*' @@ -109,7 +105,6 @@ jobs: matrix: php-version: - - '8.0' - '8.1' - '8.2' - '8.3' @@ -117,12 +112,9 @@ jobs: symfony-version: ['*'] jackalope-version: ['1.*'] include: - - php-version: '8.0' + - php-version: '8.1' dependencies: lowest symfony-version: '*' - - php-version: '8.0' - dependencies: highest - symfony-version: '6.*' - php-version: '8.1' dependencies: highest symfony-version: 5.4.* diff --git a/CHANGELOG.md b/CHANGELOG.md index 85500d44e..0693a5be6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,16 @@ Changelog * Removed annotation mappings. Use attributes (or XML or YAML) instead. +* `ChildrenCollection::slice` no longer accepts a node name as offset. If you + want a slice starting from a node name, use `ChildrenCollection::sliceByChildName` + instead. + +* Removed `DocumentManager::merge()` + +* Removed support for short namespace aliases. ``ClassMetadataFactory::getFqcnFromAlias`` and the namespace registering + on `Configuration` are removed. `ClassMetadataFactory` methods now require their `$className` argument to be an + actual FQCN. + ### New Features * `DocumentManager::getDocumentId()` to get the id of a managed document @@ -25,7 +35,7 @@ Changelog * Allow using `doctrine/persistence` -* Added support for Symfony 7. Dropped support for PHP < 8.0 and Symfony < 5.4. +* Added support for Symfony 7. Dropped support for PHP < 8.1 and Symfony < 5.4. 1.x === diff --git a/composer.json b/composer.json index e57c11a89..d7bcb2740 100644 --- a/composer.json +++ b/composer.json @@ -21,13 +21,13 @@ "minimum-stability": "beta", "prefer-stable": true, "require": { - "php": "^8.0", - "doctrine/collections": "^1.0 || ^2.0", + "php": "^8.1", + "doctrine/collections": "^2.0", "doctrine/common": "^2.4 || ^3.0", "doctrine/annotations": "^1.14.3 || ^2.0", "doctrine/data-fixtures": "^1.0", "doctrine/event-manager": "^1.0 || ^2.0", - "doctrine/persistence": "^2.4", + "doctrine/persistence": "^3.0", "phpcr/phpcr": "^2.1.1", "phpcr/phpcr-implementation": "^2.1", "phpcr/phpcr-utils": "^1.3.0 || ^2.0", diff --git a/lib/Doctrine/ODM/PHPCR/ChildrenCollection.php b/lib/Doctrine/ODM/PHPCR/ChildrenCollection.php index 5d1a59263..427f64883 100644 --- a/lib/Doctrine/ODM/PHPCR/ChildrenCollection.php +++ b/lib/Doctrine/ODM/PHPCR/ChildrenCollection.php @@ -17,10 +17,7 @@ class ChildrenCollection extends PersistentCollection { private object $document; - /** - * @var array|string|null - */ - private $filter; + private string|array|null $filter; private int $fetchDepth; @@ -34,14 +31,14 @@ class ChildrenCollection extends PersistentCollection /** * Creates a new persistent collection. * - * @param object $document The parent document instance - * @param string|array $filter Filter string or array of filter string - * @param int $fetchDepth Optional fetch depth, -1 to not override - * @param string|null $locale The locale to use during the loading of this collection + * @param object $document The parent document instance + * @param array|string|null $filter Filter string for child names or array of filter strings + * @param int $fetchDepth Optional fetch depth, -1 to not override + * @param string|null $locale The locale to use during the loading of this collection */ - public function __construct(DocumentManagerInterface $dm, object $document, $filter = null, int $fetchDepth = -1, string $locale = null) + public function __construct(DocumentManagerInterface $dm, object $document, array|string $filter = null, int $fetchDepth = -1, string $locale = null) { - $this->dm = $dm; + parent::__construct($dm); $this->document = $document; $this->filter = $filter; $this->fetchDepth = $fetchDepth; @@ -159,20 +156,13 @@ public function isEmpty(): bool return parent::isEmpty(); } - public function slice($offset, $length = null) + public function slice(int $offset, $length = null): array { if (!$this->isInitialized()) { $nodeNames = $this->getOriginalNodeNames(); - if (!is_numeric($offset)) { - $offset = array_search($offset, $nodeNames, true); - if (false === $offset) { - return new ArrayCollection(); - } - } - $nodeNames = array_slice($nodeNames, $offset, $length); $parentPath = $this->getNode($this->fetchDepth)->getPath(); - array_walk($nodeNames, function (&$nodeName) use ($parentPath) { + array_walk($nodeNames, static function (&$nodeName) use ($parentPath) { $nodeName = "$parentPath/$nodeName"; }); @@ -181,12 +171,25 @@ public function slice($offset, $length = null) return $this->getChildren($childNodes); } - if (!is_numeric($offset)) { - $nodeNames = $this->collection->getKeys(); - $offset = array_search($offset, $nodeNames, true); + return parent::slice($offset, $length); + } + + public function sliceByChildName(string $firstChild, $length = null): array + { + if (!$this->isInitialized()) { + $nodeNames = $this->getOriginalNodeNames(); + $offset = array_search($firstChild, $nodeNames, true); if (false === $offset) { - return new ArrayCollection(); + return []; } + + return $this->slice($offset, $length); + } + + $nodeNames = $this->collection->getKeys(); + $offset = array_search($firstChild, $nodeNames, true); + if (false === $offset) { + return []; } return parent::slice($offset, $length); diff --git a/lib/Doctrine/ODM/PHPCR/Configuration.php b/lib/Doctrine/ODM/PHPCR/Configuration.php index 4ddd98d01..7d19fc19f 100644 --- a/lib/Doctrine/ODM/PHPCR/Configuration.php +++ b/lib/Doctrine/ODM/PHPCR/Configuration.php @@ -25,7 +25,6 @@ class Configuration 'metadataDriverImpl' => null, 'metadataCacheImpl' => null, 'documentClassMapper' => null, - 'documentNamespaces' => [], 'proxyNamespace' => 'MyPHPCRProxyNS', 'autoGenerateProxyClasses' => true, ]; @@ -62,38 +61,6 @@ public function getWriteDoctrineMetadata(): bool return $this->attributes['writeDoctrineMetadata']; } - /** - * Adds a namespace with the specified alias. - */ - public function addDocumentNamespace(string $alias, string $namespace): void - { - $this->attributes['documentNamespaces'][$alias] = $namespace; - } - - /** - * Resolves a registered namespace alias to the full namespace. - * - * @throws PHPCRException - */ - public function getDocumentNamespace(string $documentNamespaceAlias): string - { - if (!array_key_exists($documentNamespaceAlias, $this->attributes['documentNamespaces'])) { - throw PHPCRException::unknownDocumentNamespace($documentNamespaceAlias); - } - - return trim($this->attributes['documentNamespaces'][$documentNamespaceAlias], '\\'); - } - - /** - * Set the document alias map. - * - * @param array $documentNamespaces - */ - public function setDocumentNamespaces(array $documentNamespaces): void - { - $this->attributes['documentNamespaces'] = $documentNamespaces; - } - /** * Sets the driver implementation that is used to retrieve mapping metadata. */ diff --git a/lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php b/lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php index b15306f1a..7064623c9 100644 --- a/lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php +++ b/lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php @@ -163,7 +163,7 @@ public function reorder(object $document, string $srcName, string $targetName, b $this->wrapped->reorder($document, $srcName, $targetName, $before); } - public function getChildren(object $document, $filter = null, int $fetchDepth = -1, string $locale = null): ChildrenCollection + public function getChildren(object $document, array|string $filter = null, int $fetchDepth = -1, string $locale = null): ChildrenCollection { return $this->wrapped->getChildren($document, $filter, $fetchDepth, $locale); } @@ -173,12 +173,12 @@ public function getReferrers(object $document, string $type = null, string $name return $this->wrapped->getReferrers($document, $type, $name, $locale, $refClass); } - public function flush($document = null): void + public function flush(object|array $document = null): void { $this->wrapped->flush($document); } - public function getReference(string $documentName, $id) + public function getReference(string $documentName, object|string $id): mixed { return $this->wrapped->getReference($documentName, $id); } diff --git a/lib/Doctrine/ODM/PHPCR/DocumentManager.php b/lib/Doctrine/ODM/PHPCR/DocumentManager.php index b94af35ee..df639fb4f 100644 --- a/lib/Doctrine/ODM/PHPCR/DocumentManager.php +++ b/lib/Doctrine/ODM/PHPCR/DocumentManager.php @@ -478,37 +478,6 @@ public function remove($document): void $this->unitOfWork->scheduleRemove($document); } - /** - * {@inheritdoc} - * - * Merge the state of the detached object into the persistence context of - * this ObjectManager and returns the managed copy of the object. - * - * This will copy all fields of $document over the fields of the managed - * document and then cascade the merge to relations as configured. - * - * The object passed to merge will *not* become associated/managed with - * this ObjectManager. - * - * @param object $document the document to merge over a persisted document - * with the same id - * - * @return object The managed document where $document has been merged - * into. This is *not* the same instance as the parameter. - * - * @throws InvalidArgumentException if $document is not an object - */ - public function merge($document): object - { - if (!is_object($document)) { - throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given'); - } - - $this->errorIfClosed(); - - return $this->unitOfWork->merge($document); - } - /** * {@inheritdoc} * @@ -552,7 +521,7 @@ public function refresh($document): void $this->unitOfWork->refresh($document); } - public function getChildren(object $document, $filter = null, int $fetchDepth = -1, string $locale = null): ChildrenCollection + public function getChildren(object $document, array|string $filter = null, int $fetchDepth = -1, string $locale = null): ChildrenCollection { $this->errorIfClosed(); @@ -578,7 +547,7 @@ public function getReferrers(object $document, string $type = null, string $name * @throws InvalidArgumentException if $document is neither null nor a * document or an array of documents */ - public function flush($document = null): void + public function flush(object|array $document = null): void { if (null !== $document && !is_object($document) && !is_array($document)) { throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given'); @@ -588,7 +557,7 @@ public function flush($document = null): void $this->unitOfWork->commit($document); } - public function getReference(string $documentName, $id) + public function getReference(string $documentName, object|string $id): mixed { return $this->unitOfWork->getOrCreateProxy($id, $documentName); } diff --git a/lib/Doctrine/ODM/PHPCR/DocumentManagerInterface.php b/lib/Doctrine/ODM/PHPCR/DocumentManagerInterface.php index 80e443a9d..1280d66d5 100644 --- a/lib/Doctrine/ODM/PHPCR/DocumentManagerInterface.php +++ b/lib/Doctrine/ODM/PHPCR/DocumentManagerInterface.php @@ -39,18 +39,18 @@ use PHPCR\Util\QOM\QueryBuilder as PhpcrQueryBuilder; /** - * The PHPCR-ODM document manager adds PHPCR specific methods to the object manager.. + * The PHPCR-ODM document manager adds PHPCR specific methods to the object manager. */ interface DocumentManagerInterface extends ObjectManager { /** * @{@inheritDoc} * - * Overwritten to tighten return type. + * Overwritten to tighten return type. We can't tighten the return type declaration because of Doctrine\Persistence\ObjectManagerDecorator. * * @return PhpcrClassMetadata */ - public function getClassMetadata($className); + public function getClassMetadata(string $className); /** * Add or replace a translation strategy. @@ -141,7 +141,7 @@ public function findMany(?string $className, array $ids): Collection; * @param string $locale The language to try to load * @param bool $fallback Set to true if the language fallback mechanism should be used * - * @return object the translated document or null if not found + * @return object|null the translated document or null if not found * * @throws MissingTranslationException if $fallback is false and the * translation was not found @@ -301,16 +301,16 @@ public function reorder(object $document, string $srcName, string $targetName, b * * Note that this method only returns children that have been flushed. * - * @param object $document Document instance which children should be loaded - * @param string|array $filter Optional filter to filter on children names - * @param int $fetchDepth Optional fetch depth - * @param string|null $locale The locale to use during the loading of this collection + * @param object $document Document instance which children should be loaded + * @param array|string|null $filter Optional filter to filter on children names + * @param int $fetchDepth Optional fetch depth + * @param string|null $locale The locale to use during the loading of this collection * * @return ChildrenCollection collection of child documents * * @throws InvalidArgumentException if $document is not an object */ - public function getChildren(object $document, $filter = null, int $fetchDepth = -1, string $locale = null): ChildrenCollection; + public function getChildren(object $document, array|string $filter = null, int $fetchDepth = -1, string $locale = null): ChildrenCollection; /** * Get the documents that refer a given document using an optional name. @@ -342,11 +342,9 @@ public function getReferrers(object $document, string $type = null, string $name * has its identifier populated. Otherwise a proxy is returned that automatically * loads itself on first access. * - * @param string|object $id - * * @return mixed|object the document reference */ - public function getReference(string $documentName, $id); + public function getReference(string $documentName, object|string $id): mixed; /** * Create a new version of the document that has been previously persisted @@ -433,7 +431,7 @@ public function getAllLinearVersions(object $document, int $limit = -1): array; * @param string $id Id of the document * @param string $versionName The version name as given by getLinearPredecessors * - * @return object The detached document or null if the document is not found + * @return object|null The detached document or null if the document is not found * * @throws UnsupportedRepositoryOperationException if the implementation does not support versioning * @throws InvalidArgumentException if there is a document with $id but no version with $name @@ -461,7 +459,7 @@ public function getUnitOfWork(): UnitOfWork; * @throws InvalidArgumentException if $document is neither null nor a * document or an array of documents */ - public function flush($document = null): void; + public function flush(object|array $document = null): void; /** * Closes the DocumentManager. All entities that are currently managed diff --git a/lib/Doctrine/ODM/PHPCR/ImmutableReferrersCollection.php b/lib/Doctrine/ODM/PHPCR/ImmutableReferrersCollection.php index fcea9741e..dc55db3ee 100644 --- a/lib/Doctrine/ODM/PHPCR/ImmutableReferrersCollection.php +++ b/lib/Doctrine/ODM/PHPCR/ImmutableReferrersCollection.php @@ -17,37 +17,37 @@ public function __construct(DocumentManagerInterface $dm, $document, $type = nul parent::__construct($dm, $document, $type, null, $locale); } - public function add($element): bool + public function add($element): never { throw new BadMethodCallException('Can not call '.__METHOD__.' on immutable collection'); } - public function clear(): void + public function clear(): never { throw new BadMethodCallException('Can not call '.__METHOD__.' on immutable collection'); } - public function offsetSet($offset, $value): void + public function offsetSet($offset, $value): never { throw new BadMethodCallException('Can not call '.__METHOD__.' on immutable collection'); } - public function offsetUnset($offset): void + public function offsetUnset($offset): never { throw new BadMethodCallException('Can not call '.__METHOD__.' on immutable collection'); } - public function remove($key) + public function remove($key): never { throw new BadMethodCallException('Can not call '.__METHOD__.' on immutable collection'); } - public function removeElement($element): bool + public function removeElement($element): never { throw new BadMethodCallException('Can not call '.__METHOD__.' on immutable collection'); } - public function set($key, $value): void + public function set($key, $value): never { throw new BadMethodCallException('Can not call '.__METHOD__.' on immutable collection'); } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php index ddddb1bb3..04d0818a9 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php @@ -69,11 +69,6 @@ protected function newClassMetadataInstance($className): ClassMetadata return new ClassMetadata($className); } - protected function getFqcnFromAlias($namespaceAlias, $simpleClassName): string - { - return $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias).'\\'.$simpleClassName; - } - /** * Actually loads PHPCR-ODM metadata from the underlying metadata. * diff --git a/lib/Doctrine/ODM/PHPCR/PersistentCollection.php b/lib/Doctrine/ODM/PHPCR/PersistentCollection.php index 581b7b06f..b5a48287a 100644 --- a/lib/Doctrine/ODM/PHPCR/PersistentCollection.php +++ b/lib/Doctrine/ODM/PHPCR/PersistentCollection.php @@ -59,12 +59,12 @@ public function unwrap(): Collection return new ArrayCollection(); } - public function add($element): bool + public function add($element): void { $this->initialize(); $this->isDirty = true; - return $this->collection->add($element); + $this->collection->add($element); } public function clear(): void @@ -95,7 +95,7 @@ public function count(): int return $this->collection->count(); } - public function current() + public function current(): mixed { $this->initialize(); @@ -116,13 +116,27 @@ public function filter(\Closure $p): Collection return $this->collection->filter($p); } - public function first() + public function first(): mixed { $this->initialize(); return $this->collection->first(); } + public function findFirst(\Closure $p): mixed + { + $this->initialize(); + + return $this->collection->findFirst($p); + } + + public function reduce(\Closure $func, $initial = null) + { + $this->initialize(); + + return $this->collection->reduce($func); + } + public function forAll(\Closure $p): bool { $this->initialize(); @@ -130,7 +144,7 @@ public function forAll(\Closure $p): bool return $this->collection->forAll($p); } - public function get($key) + public function get($key): mixed { $this->initialize(); @@ -158,7 +172,7 @@ public function getValues(): array return $this->collection->getValues(); } - public function indexOf($element) + public function indexOf($element): bool|int|string { $this->initialize(); @@ -172,14 +186,14 @@ public function isEmpty(): bool return $this->collection->isEmpty(); } - public function key() + public function key(): int|null|string { $this->initialize(); return $this->collection->key(); } - public function last() + public function last(): mixed { $this->initialize(); @@ -193,7 +207,7 @@ public function map(\Closure $func): Collection return $this->collection->map($func); } - public function next() + public function next(): mixed { $this->initialize(); @@ -207,8 +221,7 @@ public function offsetExists($offset): bool return $this->collection->offsetExists($offset); } - #[\ReturnTypeWillChange] // type mixed is not available for older php versions - public function offsetGet($offset) + public function offsetGet($offset): mixed { $this->initialize(); @@ -238,7 +251,7 @@ public function partition(\Closure $p): array return $this->collection->partition($p); } - public function remove($key) + public function remove($key): mixed { $this->initialize(); $this->isDirty = true; @@ -261,7 +274,7 @@ public function set($key, $value): void $this->collection->set($key, $value); } - public function slice($offset, $length = null) + public function slice(int $offset, $length = null): array { $this->initialize(); @@ -322,10 +335,9 @@ public function setLocale(?string $locale): void } /** - * @param array|Collection $collection The collection to initialize with - * @param bool $forceOverwrite If to force the database to be forced to the state of the collection + * @param bool $forceOverwrite Whether to force the database to be updated with $collection */ - protected function initializeFromCollection($collection, bool $forceOverwrite = false): void + protected function initializeFromCollection(array|Collection $collection, bool $forceOverwrite = false): void { $this->collection = is_array($collection) ? new ArrayCollection($collection) : $collection; $this->initialized = $forceOverwrite ? self::INITIALIZED_FROM_COLLECTION_FORCE : self::INITIALIZED_FROM_COLLECTION; diff --git a/tests/Doctrine/Tests/ODM/PHPCR/ConfigurationTest.php b/tests/Doctrine/Tests/ODM/PHPCR/ConfigurationTest.php deleted file mode 100644 index 36a6ca26d..000000000 --- a/tests/Doctrine/Tests/ODM/PHPCR/ConfigurationTest.php +++ /dev/null @@ -1,33 +0,0 @@ -addDocumentNamespace('foo', 'Documents\Bar'); - $this->assertEquals('Documents\Bar', $config->getDocumentNamespace('foo')); - - $config = new Configuration(); - - $config->setDocumentNamespaces(['foo' => 'Documents\Bar']); - $this->assertEquals('Documents\Bar', $config->getDocumentNamespace('foo')); - - $this->expectException(PHPCRException::class); - $config->getDocumentNamespace('bar'); - } -} diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/FindTypeValidationTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/FindTypeValidationTest.php index b4f98e69e..af9c965b2 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/FindTypeValidationTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/FindTypeValidationTest.php @@ -64,10 +64,7 @@ public function testFind(): void public function testFindWithNamespace(): void { - $config = $this->dm->getConfiguration(); - $config->addDocumentNamespace('Foobar', 'Doctrine\Tests\ODM\PHPCR\Functional'); - - $user = $this->dm->find('Foobar:TypeUser', 'functional/user'); + $user = $this->dm->find(TypeUser::class, 'functional/user'); $this->assertNotNull($user); } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/Hierarchy/ChildrenTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/Hierarchy/ChildrenTest.php index 263ec2778..cc129e38b 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/Hierarchy/ChildrenTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/Hierarchy/ChildrenTest.php @@ -106,11 +106,11 @@ public function testSliceChildrenCollection(): void $this->createChildren(); $parent = $this->dm->find($this->type, '/functional/parent'); - $collection = $parent->allChildren->slice('Child B', 2); + $collection = $parent->allChildren->sliceByChildName('Child B', 2); $this->assertEquals(['Child B', 'Child C'], array_keys($collection)); $parent->allChildren->initialize(); - $collection = $parent->allChildren->slice('Child B', 2); + $collection = $parent->allChildren->sliceByChildName('Child B', 2); $this->assertEquals(['Child B', 'Child C'], array_keys($collection)); } @@ -138,8 +138,8 @@ public function testLazyLoading(): void $this->assertCount(4, $parent->allChildren); $this->assertFalse($parent->aChildren->contains(new ChildrenTestObj())); $this->assertTrue($parent->allChildren->containsKey('Child D')); - $this->assertEquals('Child B', key($parent->allChildren->slice('Child B', 2))); - $this->assertCount(2, $parent->allChildren->slice('Child B', 2)); + $this->assertEquals('Child B', key($parent->allChildren->sliceByChildName('Child B', 2))); + $this->assertCount(2, $parent->allChildren->sliceByChildName('Child B', 2)); $this->assertFalse($parent->aChildren->isInitialized()); $this->assertFalse($parent->allChildren->isInitialized()); diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/MergeTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/MergeTest.php deleted file mode 100644 index 1a6f5726c..000000000 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/MergeTest.php +++ /dev/null @@ -1,241 +0,0 @@ -dm = $this->createDocumentManager([__DIR__]); - $this->node = $this->resetFunctionalNode($this->dm); - $this->dm->getPhpcrSession()->save(); - } - - public function testMergeNewDocument(): void - { - $user = new CmsUser(); - $user->username = 'beberlei'; - $user->name = 'Benjamin'; - - $mergedUser = $this->dm->merge($user); - - $this->assertNotSame($mergedUser, $user); - $this->assertInstanceOf(CmsUser::class, $mergedUser); - $this->assertEquals('beberlei', $mergedUser->username); - $this->assertEquals($this->node->getPath().'/'.$mergedUser->username, $mergedUser->id, 'Merged new document should have generated path'); - $this->assertInstanceOf(ReferenceManyCollection::class, $mergedUser->articles); - } - - public function testMergeManagedDocument(): void - { - $user = new CmsUser(); - $user->username = 'beberlei'; - $user->name = 'Benjamin'; - - $this->dm->persist($user); - $this->dm->flush(); - - $mergedUser = $this->dm->merge($user); - - $this->assertSame($mergedUser, $user); - } - - public function testMergeKnownDocument(): void - { - $user = new CmsUser(); - $user->username = 'beberlei'; - $user->name = 'Benjamin'; - - $this->dm->persist($user); - $this->dm->flush(); - $this->dm->clear(); - - $mergedUser = $this->dm->merge($user); - - $this->assertNotSame($mergedUser, $user); - $this->assertSame($mergedUser->id, $user->id); - } - - public function testMergeRemovedDocument(): void - { - $user = new CmsUser(); - $user->username = 'beberlei'; - $user->name = 'Benjamin'; - - $this->dm->persist($user); - $this->dm->flush(); - - $this->dm->remove($user); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("Removed document detected during merge at '/functional/beberlei'. Cannot merge with a removed document."); - $this->dm->merge($user); - } - - public function testMergeWithManagedDocument(): void - { - $user = new CmsUser(); - $user->username = 'beberlei'; - $user->name = 'Benjamin'; - - $this->dm->persist($user); - $this->dm->flush(); - - $mergableUser = new CmsUser(); - $mergableUser->id = $user->id; - $mergableUser->username = 'jgalt'; - $mergableUser->name = 'John Galt'; - - $mergedUser = $this->dm->merge($mergableUser); - - $this->assertSame($mergedUser, $user); - $this->assertEquals('jgalt', $mergedUser->username); - $this->assertInstanceOf(NodeInterface::class, $mergedUser->node); - } - - public function testMergeChangeDocumentClass(): void - { - $user = new CmsUser(); - $user->username = 'beberlei'; - $user->name = 'Benjamin'; - - $this->dm->persist($user); - $this->dm->flush(); - - $otherUser = new CmsUser(); - $otherUser->username = 'lukas'; - $otherUser->name = 'Lukas'; - - $mergableGroup = new CmsGroup(); - $mergableGroup->id = $user->id; - $mergableGroup->name = 'doctrine'; - - $this->expectException(InvalidArgumentException::class); - $this->dm->merge($mergableGroup); - } - - public function testMergeUnknownAssignedId(): void - { - $doc = new CmsArticle(); - $doc->id = '/foo'; - - $mergedDoc = $this->dm->merge($doc); - - $this->assertNotSame($mergedDoc, $doc); - $this->assertSame($mergedDoc->id, $doc->id); - } - - public function testMergeWithChild(): void - { - $user = new CmsUser(); - $user->username = 'beberlei'; - $user->name = 'Benjamin'; - - $teamuser = new CmsTeamUser(); - $teamuser->username = 'jwage'; - $teamuser->name = 'Jonathan Wage'; - $teamuser->parent = $user; - $user->child = $teamuser; - - $this->dm->persist($user); - $this->dm->flush(); - - $mergableUser = new CmsUser(); - $mergableUser->username = 'jgalt'; - $mergableUser->name = 'John Galt'; - $mergableUser->id = $user->id; - - $mergedUser = $this->dm->merge($mergableUser); - - $this->assertSame($mergedUser, $user); - $this->assertEquals('jgalt', $mergedUser->username); - $this->assertEquals('jwage', $mergedUser->child->username); - - $this->dm->flush(); - $mergedUser->children->count(); - - $mergableUser = new CmsUser(); - $mergableUser->id = $user->id; - $mergableUser->username = 'dbu'; - $mergableUser->name = 'David'; - - $mergedUser = $this->dm->merge($mergableUser); - - $this->assertSame($mergedUser, $user); - $this->assertEquals('dbu', $mergedUser->username); - $this->assertEquals('David', $mergedUser->name); - $this->assertEquals('jwage', $mergedUser->child->username); - - $this->dm->flush(); - } - - public function testMergeWithChildren(): void - { - $user = new CmsUser(); - $user->username = 'beberlei'; - $user->name = 'Benjamin'; - - $teamuser = new CmsTeamUser(); - $teamuser->username = 'jwage'; - $teamuser->name = 'Jonathan Wage'; - $teamuser->parent = $user; - - $this->dm->persist($user); - $this->dm->persist($teamuser); - $this->dm->flush(); - $this->dm->clear(); - - $user = $this->dm->find(null, '/functional/beberlei'); - $this->assertCount(1, $user->children); - - $mergableUser = new CmsUser(); - $mergableUser->username = 'jgalt'; - $mergableUser->name = 'John Galt'; - $mergableUser->id = $user->id; - - $mergedUser = $this->dm->merge($mergableUser); - - $this->assertSame($mergedUser, $user); - $this->assertEquals('jgalt', $mergedUser->username); - $this->assertCount(1, $mergedUser->children); - - $this->dm->flush(); - $mergedUser->children->count(); - - $mergableUser = new CmsUser(); - $mergableUser->id = $user->id; - $mergableUser->username = 'dbu'; - - $mergedUser = $this->dm->merge($mergableUser); - - $this->assertSame($mergedUser, $user); - $this->assertEquals('dbu', $mergedUser->username); - $this->assertNull($mergedUser->name); - $this->assertCount(1, $mergedUser->children); - - $this->dm->flush(); - - $mergedUser = $this->dm->find(null, $mergedUser->id); - $this->assertCount(1, $mergedUser->children); - } -} diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/QueryBuilderTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/QueryBuilderTest.php index bc25b56b8..634b20180 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/QueryBuilderTest.php @@ -114,11 +114,8 @@ public function testFrom(): void public function testFromWithAlias(): void { - $config = $this->dm->getConfiguration(); - $config->addDocumentNamespace('Foobar', 'Doctrine\Tests\Models\Blog'); - $qb = $this->createQb(); - $qb->from()->document('Foobar:User', 'a'); + $qb->from()->document(User::class, 'a'); // add where to stop rouge documents that havn't been stored in /functional/ from appearing. $qb->where()->eq()->field('a.status')->literal('query_builder')->end(); $res = $qb->getQuery()->execute(); diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/Versioning/VersioningTestAbstract.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/Versioning/VersioningTestAbstract.php index d02c31bee..ac60acde6 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/Versioning/VersioningTestAbstract.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/Versioning/VersioningTestAbstract.php @@ -86,24 +86,6 @@ public function testCheckinOnNonVersionableNode(): void $this->dm->checkin($contentNode); } - public function testMergeVersionable(): void - { - $versionableArticle = new FullVersionableArticle(); - $versionableArticle->setText('very interesting content'); - $versionableArticle->author = 'greg0ire'; - $versionableArticle->topic = 'whatever'; - $versionableArticle->id = '/functional/whatever'; - $versionableArticle->versionName = 'v1'; - - $this->dm->persist($versionableArticle); - $this->dm->flush(); - $this->dm->clear(); - $versionableArticle->versionName = 'v2'; - - $mergedVersionableArticle = $this->dm->merge($versionableArticle); - $this->assertEquals('v2', $mergedVersionableArticle->versionName); - } - public function testCheckin(): void { $user = $this->dm->find($this->typeVersion, '/functional/versionTestObj');