diff --git a/.gitignore b/.gitignore index 3d29dee..c369729 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ Tests/Resources/data composer.lock vendor +.phpunit +build +.php_cs.cache diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..5759af5 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,64 @@ + true, + '@Symfony:risky' => true, + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'header_comment' => [ + 'header' => $header, + ], + 'no_extra_blank_lines' => true, + 'no_php4_constructor' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'phpdoc_order' => true, + '@PHP56Migration' => true, + '@PHP56Migration:risky' => true, + '@PHPUnit57Migration:risky' => true, + '@PHP70Migration' => true, + '@PHP70Migration:risky' => true, + '@PHPUnit60Migration:risky' => true, + '@PHP71Migration' => true, + '@PHP71Migration:risky' => true, + 'compact_nullable_typehint' => true, + 'void_return' => null, + 'strict_comparison' => true, + 'strict_param' => true, +]; + + +$finder = PhpCsFixer\Finder::create() + ->in(__DIR__) + ->exclude('Tests/Fixtures') + ->exclude('tests/Fixtures') + ->exclude('Resources/skeleton') + ->exclude('Resources/public/vendor') +; + +return PhpCsFixer\Config::create() + ->setFinder($finder) + ->setRiskyAllowed(true) + ->setRules($rules) + ->setUsingCache(true) +; diff --git a/.styleci.yml b/.styleci.yml index 2bdb04b..c721eb6 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -7,7 +7,7 @@ ############################################################################ # This file is part of the Symfony CMF package. # # # -# (c) 2011-2017 Symfony CMF # +# (c) Symfony CMF # # # # For the full copyright and license information, please view the LICENSE # # file that was distributed with this source code. # diff --git a/.travis.yml b/.travis.yml index 6738e1d..6e1e86b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,39 +1,65 @@ +####################################################### +# DO NOT EDIT THIS FILE! # +# # +# It's auto-generated by symfony-cmf/dev-kit package. # +####################################################### + +############################################################################ +# This file is part of the Symfony CMF package. # +# # +# (c) Symfony CMF # +# # +# For the full copyright and license information, please view the LICENSE # +# file that was distributed with this source code. # +############################################################################ + language: php php: - 7.1 - + - 7.2 + - 7.3 sudo: false cache: directories: - - $HOME/.composer/cache/files - .phpunit + - $HOME/.composer/cache/files env: - global: - - SYMFONY_DEPRECATIONS_HELPER="/.*each.*/" - - SYMFONY_PHPUNIT_DIR=.phpunit SYMFONY_PHPUNIT_REMOVE="symfony/yaml" - - SYMFONY_PHPUNIT_VERSION=5.7 + - SYMFONY_DEPRECATIONS_HELPER="/.*each.*/" + - SYMFONY_PHPUNIT_DIR=.phpunit SYMFONY_PHPUNIT_REMOVE="symfony/yaml" + - SYMFONY_PHPUNIT_VERSION=7 + - PHPUNIT_VERSION=7 + - TARGET=test matrix: - matrix: SYMFONY_VERSION=4.0.* include: + - env: TARGET=lint + - php: 7.3 + env: SYMFONY_VERSION= - php: 7.1 - - php: 7.1 - env: COMPOSER_FLAGS="--prefer-lowest" REQUIREMENTS="phpcr/phpcr:2.1.2" + env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_VERSION= SYMFONY_DEPRECATIONS_HELPER="/.*each.*/" + fast_finish: true before_install: - - if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then echo "memory_limit = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi - phpenv config-rm xdebug.ini || true - composer self-update - - if [ "$REQUIREMENTS" != "" ]; then composer require --no-update $REQUIREMENTS; fi - - if [ "$DEPS" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi + - composer validate --no-check-all --ansi + - if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; composer config prefer-stable true; fi; + - if [ "$SYMFONY_VERSION" != "" ]; then composer require symfony/symfony:${SYMFONY_VERSION} --no-update; fi + - export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi) + +install: + - phpenv config-add travis.php.ini + - php -ini | grep memory_limit + - if [ -x .travis/install_${TARGET}.sh ]; then .travis/install_${TARGET}.sh; fi; -install: travis_wait composer update --prefer-dist $COMPOSER_FLAGS +script: make $TARGET -script: vendor/bin/simple-phpunit +after_success: + - if [ -x .travis/after_success_${TARGET}.sh ]; then .travis/after_success_${TARGET}.sh; fi; notifications: irc: "irc.freenode.org#symfony-cmf" diff --git a/.travis/after_success_test.sh b/.travis/after_success_test.sh new file mode 100755 index 0000000..9837420 --- /dev/null +++ b/.travis/after_success_test.sh @@ -0,0 +1,5 @@ + +#!/usr/bin/env sh +set -ev + +coveralls -v diff --git a/.travis/install_lint.sh b/.travis/install_lint.sh new file mode 100755 index 0000000..864c751 --- /dev/null +++ b/.travis/install_lint.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh +set -ev + +mkdir --parents "${HOME}/bin" + +wget "http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar" --output-document="${HOME}/bin/php-cs-fixer" +chmod u+x "${HOME}/bin/php-cs-fixer" + +composer global require sllh/composer-lint:@stable --prefer-dist --no-interaction + +gem install yaml-lint diff --git a/.travis/install_test.sh b/.travis/install_test.sh new file mode 100755 index 0000000..a033500 --- /dev/null +++ b/.travis/install_test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh +set -ev + +mkdir --parents "${HOME}/bin" + +wget "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" --output-document="${HOME}/bin/phpunit" +chmod u+x "${HOME}/bin/phpunit" + +# Coveralls client install +wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar --output-document="${HOME}/bin/coveralls" +chmod u+x "${HOME}/bin/coveralls" + +# To be removed when these issues are resolved: +# https://github.com/composer/composer/issues/5355 +if [ "${COMPOSER_FLAGS}" = '--prefer-lowest' ]; then + composer update --prefer-dist --no-interaction --prefer-stable --quiet +fi + +composer update --prefer-dist --no-interaction --prefer-stable ${COMPOSER_FLAGS} diff --git a/Makefile b/Makefile index de4efc6..887095d 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ ############################################################################ # This file is part of the Symfony CMF package. # # # -# (c) 2011-2017 Symfony CMF # +# (c) Symfony CMF # # # # For the full copyright and license information, please view the LICENSE # # file that was distributed with this source code. # @@ -20,13 +20,49 @@ ifdef BRANCH VERSION=dev-${BRANCH} endif PACKAGE=symfony-cmf/resource +HAS_XDEBUG=$(shell php --modules|grep --quiet xdebug;echo $$?) + list: @echo 'test: will run all tests' @echo 'unit_tests: will run unit tests only' - -include ${TESTING_SCRIPTS_DIR}/make/unit_tests.mk +TEST_DEPENDENCIES := "" +EXTRA_INCLUDES:=$(wildcard ${TESTING_SCRIPTS_DIR}/make/unit_tests.mk) +ifneq ($(strip $(EXTRA_INCLUDES)),) + contents := $(shell echo including extra rules $(EXTRA_INCLUDES)) + include $(EXTRA_INCLUDES) + TEST_DEPENDENCIES := $(TEST_DEPENDENCIES)" unit_tests" + endif .PHONY: test -test: unit_tests +test: build/xdebug-filter.php$ +ifneq ($(strip $(wildcard ${TESTING_SCRIPTS_DIR}/make/unit_tests.mk)),) + @make unit_tests +endif + +lint-php: + php-cs-fixer fix --ansi --verbose --diff --dry-run +.PHONY: lint-php + +lint: lint-composer lint-php +.PHONY: lint + +lint-composer: + composer validate +.PHONY: lint-composer + +cs-fix: cs-fix-php +.PHONY: cs-fix + +cs-fix-php: + php-cs-fixer fix --verbose +.PHONY: cs-fix-php + +build: + mkdir $@ + +build/xdebug-filter.php: phpunit.xml.dist build +ifeq ($(HAS_XDEBUG), 0) + phpunit --dump-xdebug-filter $@ +endif diff --git a/README.md b/README.md index f7744b6..35f0576 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,13 @@ [![Monthly Downloads](https://poser.pugx.org/symfony-cmf/resource/d/monthly)](https://packagist.org/packages/symfony-cmf/resource) [![Daily Downloads](https://poser.pugx.org/symfony-cmf/resource/d/daily)](https://packagist.org/packages/symfony-cmf/resource) -Branch | Travis | Coveralls | ------- | ------ | --------- | -master | [![Build Status][travis_unstable_badge]][travis_link] | [![Coverage Status][coveralls_unstable_badge]][coveralls_unstable_link] | +Branch | Travis | Coveralls | Scrutinizer | +------ | ------ | --------- | ----------- | +1.1 | [![Build Status][travis_stable_badge]][travis_stable_link] | [![Coverage Status][coveralls_stable_badge]][coveralls_stable_link] | [![Scrutinizer Status][scrutinizer_stable_badge]][scrutinizer_stable_link] | +dev-master | [![Build Status][travis_unstable_badge]][travis_unstable_link] | [![Coverage Status][coveralls_unstable_badge]][coveralls_unstable_link] | [![Scrutinizer Status][scrutinizer_unstable_badge]][scrutinizer_unstable_link] | -This package is part of the [Symfony Content Management Framework (CMF)](http://cmf.symfony.com/) and licensed + +This package is part of the [Symfony Content Management Framework (CMF)](https://cmf.symfony.com/) and licensed under the [MIT License](LICENSE). The Resource component provides PHPCR/ODM integration with Puli. @@ -24,7 +26,7 @@ The Resource component provides PHPCR/ODM integration with Puli. ## Requirements -* PHP 7.1 / 7.2 +* PHP 7.1 / 7.2 / 7.3 * Symfony * See also the `require` section of [composer.json](composer.json) @@ -32,16 +34,16 @@ The Resource component provides PHPCR/ODM integration with Puli. For the install guide and reference, see: -* [symfony-cmf/resource Documentation](http://symfony.com/doc/master/cmf/components/resource/index.html) +* [symfony-cmf/resource Documentation](https://symfony.com/doc/master/cmf/components/resource/index.html) See also: -* [All Symfony CMF documentation](http://symfony.com/doc/master/cmf/index.html) - complete Symfony CMF reference -* [Symfony CMF Website](http://cmf.symfony.com/) - introduction, live demo, support and community links +* [All Symfony CMF documentation](https://symfony.com/doc/master/cmf/index.html) - complete Symfony CMF reference +* [Symfony CMF Website](https://cmf.symfony.com/) - introduction, live demo, support and community links ## Support -For general support and questions, please use [StackOverflow](http://stackoverflow.com/questions/tagged/symfony-cmf). +For general support and questions, please use [StackOverflow](https://stackoverflow.com/questions/tagged/symfony-cmf). ## Contributing @@ -50,7 +52,7 @@ Pull requests are welcome. Please see our guide. Unit and/or functional tests exist for this package. See the -[Testing documentation](http://symfony.com/doc/master/cmf/components/testing.html) +[Testing documentation](https://symfony.com/doc/master/cmf/components/testing.html) for a guide to running the tests. Thanks to @@ -60,14 +62,17 @@ Thanks to This package is available under the [MIT license](src/Resources/meta/LICENSE). -[travis_legacy_badge]: https://travis-ci.org/symfony-cmf/resource.svg?branch=master -[travis_stable_badge]: https://travis-ci.org/symfony-cmf/resource.svg?branch=master -[travis_unstable_badge]: https://travis-ci.org/symfony-cmf/resource.svg?branch=master -[travis_link]: https://travis-ci.org/symfony-cmf/resource - -[coveralls_legacy_badge]: https://coveralls.io/repos/github/symfony-cmf/resource/badge.svg?branch=master -[coveralls_legacy_link]: https://coveralls.io/github/symfony-cmf/resource?branch=master -[coveralls_stable_badge]: https://coveralls.io/repos/github/symfony-cmf/resource/badge.svg?branch=master -[coveralls_stable_link]: https://coveralls.io/github/symfony-cmf/resource?branch=master -[coveralls_unstable_badge]: https://coveralls.io/repos/github/symfony-cmf/resource/badge.svg?branch=master -[coveralls_unstable_link]: https://coveralls.io/github/symfony-cmf/resource?branch=master +[travis_stable_badge]: https://travis-ci.org/symfony-cmf/resource.svg?branch=1.1 +[travis_stable_link]: https://travis-ci.org/symfony-cmf/resource +[travis_unstable_badge]: https://travis-ci.org/symfony-cmf/resource.svg?branch=dev-master +[travis_unstable_link]: https://travis-ci.org/symfony-cmf/resource + +[coveralls_stable_badge]: https://coveralls.io/repos/github/symfony-cmf/resource/badge.svg?branch=1.1 +[coveralls_stable_link]: https://coveralls.io/github/symfony-cmf/resource?branch=1.1 +[coveralls_unstable_badge]: https://coveralls.io/repos/github/symfony-cmf/resource/badge.svg?branch=dev-master +[coveralls_unstable_link]: https://coveralls.io/github/symfony-cmf/resource?branch=dev-master + +[scrutinizer_stable_badge]: https://scrutinizer-ci.com/g/symfony-cmf/resource/badges/quality-score.png?b=1.1 +[scrutinizer_stable_link]: https://scrutinizer-ci.com/g/symfony-cmf/resource/?branch=1.1 +[scrutinizer_unstable_badge]: https://scrutinizer-ci.com/g/symfony-cmf/resource/badges/quality-score.png?b=dev-master +[scrutinizer_unstable_link]: https://scrutinizer-ci.com/g/symfony-cmf/resource/?branch=dev-master diff --git a/composer.json b/composer.json index fa10c7a..0e566dc 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "name": "symfony-cmf/resource", + "type": "library", "description": "Bundle which facilitates document resource location via Puli", "homepage": "http://cmf.symfony.com", "license": "MIT", @@ -11,16 +12,16 @@ ], "require": { "php": "^7.1", - "dantleech/glob-finder": "~1.0", + "dantleech/glob-finder": "^1.0", "webmozart/assert": "^1.2", "webmozart/path-util": "^2.3" }, "require-dev": { - "jackalope/jackalope-doctrine-dbal": "^1.2", - "sonata-project/admin-bundle": "^3.1", + "jackalope/jackalope-doctrine-dbal": "^1.3", "sylius/resource-bundle": "^0.18", - "symfony/phpunit-bridge": "^3.3 || ^4.0", - "doctrine/phpcr-odm": "^1.4|^2.0" + "symfony/phpunit-bridge": "4.2.2", + "doctrine/phpcr-odm": "^1.4 || ^2.0", + "symfony-cmf/testing": "^2.1.11" }, "suggest": { "doctrine/phpcr-odm": "To enable support for the PHPCR ODM documents", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 635d7db..015b9f6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,14 +2,30 @@ + colors="true" + bootstrap="vendor/symfony-cmf/testing/bootstrap/bootstrap.php" +> - - - ./tests + + + + + ./tests/Unit - + + + + + + src/ + + Resources/ + + + + + + + diff --git a/puli/AbstractRepository.php b/puli/AbstractRepository.php index 0419d79..7bcf1c7 100644 --- a/puli/AbstractRepository.php +++ b/puli/AbstractRepository.php @@ -1,9 +1,11 @@ resources = is_array($resources) ? $resources : iterator_to_array($resources); + $this->resources = \is_array($resources) ? $resources : iterator_to_array($resources); } /** @@ -136,7 +138,7 @@ public function merge($resources) */ public function isEmpty() { - return 0 === count($this->resources); + return 0 === \count($this->resources); } /** @@ -203,7 +205,7 @@ function (PuliResource $resource) { public function count() { - return count($this->resources); + return \count($this->resources); } public function getIterator($mode = ResourceCollectionIterator::KEY_AS_CURSOR) diff --git a/puli/GenericResource.php b/puli/GenericResource.php index fd21f1a..f723bf4 100644 --- a/puli/GenericResource.php +++ b/puli/GenericResource.php @@ -1,9 +1,11 @@ getRepository()) { - throw \RuntimeException(sprintf( + throw RuntimeException(sprintf( 'The resource %s does not exist.', $this->getRepositoryPath().'/'.$relPath )); diff --git a/puli/ResourceCollectionIterator.php b/puli/ResourceCollectionIterator.php index 8ed5c83..6738a18 100644 --- a/puli/ResourceCollectionIterator.php +++ b/puli/ResourceCollectionIterator.php @@ -1,9 +1,11 @@ resource->getPath(), - get_class($this->resource), + \get_class($this->resource), implode('", "', array_keys($this->descriptors)) )); } @@ -97,10 +99,10 @@ public function all() */ public function set($descriptor, $value) { - if (null !== $value && !is_scalar($value) && !is_array($value)) { + if (null !== $value && !is_scalar($value) && !\is_array($value)) { throw new \InvalidArgumentException(sprintf( 'Only scalar and array values are allowed as descriptor values, got "%s" when setting descriptor "%s"', - gettype($value), $descriptor + \gettype($value), $descriptor )); } diff --git a/src/Description/DescriptionEnhancerInterface.php b/src/Description/DescriptionEnhancerInterface.php index 4e281fd..eb8553e 100644 --- a/src/Description/DescriptionEnhancerInterface.php +++ b/src/Description/DescriptionEnhancerInterface.php @@ -1,9 +1,11 @@ listChildren($path); - return (bool) count($children); + return (bool) \count($children); } /** @@ -72,10 +72,12 @@ public function hasChildren($path) public function find($query, $language = 'glob') { if ('glob' !== $language) { - throw new \RuntimeException(sprintf( - 'The language "%s" is not supported.', - $language - )); + throw new \RuntimeException( + sprintf( + 'The language "%s" is not supported.', + $language + ) + ); } $nodes = $this->finder->find($this->resolvePath($query)); @@ -91,7 +93,7 @@ public function remove($query, $language = 'glob') $this->failUnlessGlob($language); $nodes = $this->finder->find($this->resolvePath($query)); - if (0 === count($nodes)) { + if (0 === \count($nodes)) { return 0; } @@ -99,13 +101,17 @@ public function remove($query, $language = 'glob') // delegate remove nodes to the implementation $this->removeNodes($nodes); } catch (\Exception $e) { - throw new \RuntimeException(sprintf( - 'Error encountered when removing resource(s) using query "%s"', - $query - ), null, $e); + throw new \RuntimeException( + sprintf( + 'Error encountered when removing resource(s) using query "%s"', + $query + ), + 0, + $e + ); } - return count($nodes); + return \count($nodes); } /** @@ -116,7 +122,7 @@ public function move($query, $targetPath, $language = 'glob') $this->failUnlessGlob($language); $nodes = $this->finder->find($this->resolvePath($query)); - if (0 === count($nodes)) { + if (0 === \count($nodes)) { return 0; } @@ -126,13 +132,17 @@ public function move($query, $targetPath, $language = 'glob') // delegate moving to the implementation $this->moveNodes($nodes, $query, $targetPath); } catch (\Exception $e) { - throw new \RuntimeException(sprintf( - 'Error encountered when moving resource(s) using query "%s"', - $query - ), null, $e); + throw new \RuntimeException( + sprintf( + 'Error encountered when moving resource(s) using query "%s"', + $query + ), + 0, + $e + ); } - return count($nodes); + return \count($nodes); } /** @@ -190,9 +200,11 @@ public function resolvePath($path) */ protected function unresolvePath($path) { - $path = substr($path, strlen($this->basePath)); + if (null === $this->basePath) { + return $path; + } - return $path; + return substr($path, \strlen($this->basePath)); } protected function isGlobbed($string) diff --git a/src/Repository/Api/EditableRepository.php b/src/Repository/Api/EditableRepository.php index 6c4347a..cc5243d 100644 --- a/src/Repository/Api/EditableRepository.php +++ b/src/Repository/Api/EditableRepository.php @@ -1,9 +1,11 @@ managerRegistry = $managerRegistry; } - /** - * @return DocumentManagerInterface - */ - protected function getManager() - { - return $this->managerRegistry->getManager(); - } - /** * {@inheritdoc} */ @@ -71,7 +65,7 @@ public function listChildren($path) */ public function contains($selector, $language = 'glob') { - return count($this->find($selector, $language)) > 0; + return \count($this->find($selector, $language)) > 0; } /** @@ -113,6 +107,14 @@ public function reorderNode($sourcePath, $position) $this->getManager()->flush(); } + /** + * @return DocumentManagerInterface + */ + protected function getManager() + { + return $this->managerRegistry->getManager(); + } + /** * {@inheritdoc} */ diff --git a/src/Repository/PhpcrRepository.php b/src/Repository/PhpcrRepository.php index aa14daf..f016b82 100644 --- a/src/Repository/PhpcrRepository.php +++ b/src/Repository/PhpcrRepository.php @@ -1,9 +1,11 @@ find($selector, $language)) > 0; + return \count($this->find($selector, $language)) > 0; } /** @@ -90,6 +92,28 @@ public function getTags() return []; } + /** + * {@inheritdoc} + */ + public function reorderNode($sourcePath, $position) + { + $node = $this->getNode($sourcePath); + $parent = $node->getParent(); + $nodeNames = $parent->getNodeNames(); + + if (0 === $position) { + $parent->orderBefore($node->getName(), $nodeNames[$position]); + } elseif (isset($nodeNames[$position + 1])) { + $parent->orderBefore($node->getName(), $nodeNames[$position + 1]); + } else { + $lastName = $nodeNames[\count($nodeNames) - 1]; + $parent->orderBefore($node->getName(), $lastName); + $parent->orderBefore($lastName, $node->getName()); + } + + $this->session->save(); + } + /** * {@inheritdoc} */ @@ -132,28 +156,6 @@ protected function moveNodes(array $nodes, $sourceQuery, $targetPath) $this->session->save(); } - /** - * {@inheritdoc} - */ - public function reorderNode($sourcePath, $position) - { - $node = $this->getNode($sourcePath); - $parent = $node->getParent(); - $nodeNames = $parent->getNodeNames(); - - if (0 === $position) { - $parent->orderBefore($node->getName(), $nodeNames[$position]); - } elseif (isset($nodeNames[$position + 1])) { - $parent->orderBefore($node->getName(), $nodeNames[$position + 1]); - } else { - $lastName = $nodeNames[count($nodeNames) - 1]; - $parent->orderBefore($node->getName(), $lastName); - $parent->orderBefore($lastName, $node->getName()); - } - - $this->session->save(); - } - private function doMoveNodes(array $nodes, $sourceQuery, $targetPath) { if (false === $this->isGlobbed($sourceQuery)) { @@ -172,10 +174,14 @@ private function getNode($path) try { $node = $this->session->getNode($resolvedPath); } catch (\PHPCR\PathNotFoundException $e) { - throw new \RuntimeException(sprintf( - 'No PHPCR node could be found at "%s"', - $resolvedPath - ), null, $e); + throw new \RuntimeException( + sprintf( + 'No PHPCR node could be found at "%s"', + $resolvedPath + ), + 0, + $e + ); } if (null === $node) { diff --git a/src/Repository/Resource/CmfResource.php b/src/Repository/Resource/CmfResource.php index 316db01..e71ef1a 100644 --- a/src/Repository/Resource/CmfResource.php +++ b/src/Repository/Resource/CmfResource.php @@ -1,9 +1,11 @@ document)); + return ClassUtils::getRealClass(\get_class($this->document)); } /** diff --git a/src/Repository/Resource/PhpcrResource.php b/src/Repository/Resource/PhpcrResource.php index cd783fd..21d81a7 100644 --- a/src/Repository/Resource/PhpcrResource.php +++ b/src/Repository/Resource/PhpcrResource.php @@ -1,9 +1,11 @@ expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Only scalar and array values are allowed as descriptor values, got "object" when setting descriptor "hello"'); + $this->description->set('hello', new \stdClass()); } /** * It should throw an exception when requesting an unsupported descriptor. - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Supported descriptors: "foo", "bar" */ public function testGetUnsupported() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Supported descriptors: "foo", "bar"'); + $this->description->set('foo', 'bar'); $this->description->set('bar', 'foo'); $this->description->get('not there'); diff --git a/tests/Unit/Description/Enhancer/Doctrine/PhpcrOdmEnhancerTest.php b/tests/Unit/Description/Enhancer/Doctrine/PhpcrOdmEnhancerTest.php index b49843a..521f9f6 100644 --- a/tests/Unit/Description/Enhancer/Doctrine/PhpcrOdmEnhancerTest.php +++ b/tests/Unit/Description/Enhancer/Doctrine/PhpcrOdmEnhancerTest.php @@ -1,9 +1,11 @@ prophesize(); $mappedObject1->willImplement(FooInterface::class); $metadata1 = $this->prophesize(ClassMetadata::class); - $metadata1->name = get_class($mappedObject1->reveal()); + $metadata1->name = \get_class($mappedObject1->reveal()); $metadata1->getReflectionClass()->willReturn(new \ReflectionClass($metadata1->name)); // object the extends an allowed abstract class $mappedObject2 = $this->prophesize(); $mappedObject2->willExtend(AbstractFoo::class); $metadata2 = $this->prophesize(ClassMetadata::class); - $metadata2->name = get_class($mappedObject2->reveal()); + $metadata2->name = \get_class($mappedObject2->reveal()); $metadata2->getReflectionClass()->willReturn(new \ReflectionClass($metadata2->name)); // object of exact type that is allowed $mappedObject3 = $this->prophesize(); $metadata3 = $this->prophesize(ClassMetadata::class); - $metadata3->name = get_class($mappedObject3->reveal()); + $metadata3->name = \get_class($mappedObject3->reveal()); $metadata3->getReflectionClass()->willReturn(new \ReflectionClass($metadata3->reveal())); // object that is not permitted diff --git a/tests/Unit/Description/Enhancer/Sylius/ResourceEnhancerTest.php b/tests/Unit/Description/Enhancer/Sylius/ResourceEnhancerTest.php index db3ffdf..bebcbf7 100644 --- a/tests/Unit/Description/Enhancer/Sylius/ResourceEnhancerTest.php +++ b/tests/Unit/Description/Enhancer/Sylius/ResourceEnhancerTest.php @@ -1,9 +1,11 @@ expectException(\InvalidArgumentException::class); + $this->getRepository($basePath)->get($requestedPath); } @@ -100,11 +98,11 @@ public function provideGetInvalid() /** * Clear is not supported. - * - * @expectedException \Exception */ public function testClearShouldThrow() { + $this->expectException(\Exception::class); + $this->getRepository()->clear(); } @@ -128,6 +126,11 @@ public function testMoveZeroNodes() $this->assertEquals(0, $numberOfNodes); } + /** + * @param string $path + */ + abstract protected function getRepository($path = null); + protected function assertWrappedException($outerClass, $outerMessage, $innerClass, $innerMessage, \Exception $e) { $this->assertInstanceOf($outerClass, $e); diff --git a/tests/Unit/Repository/PhpcrOdmRepositoryTest.php b/tests/Unit/Repository/PhpcrOdmRepositoryTest.php index 8dec10e..e27832f 100644 --- a/tests/Unit/Repository/PhpcrOdmRepositoryTest.php +++ b/tests/Unit/Repository/PhpcrOdmRepositoryTest.php @@ -1,9 +1,11 @@ expectException(\RuntimeException::class); + $this->expectExceptionMessage('No PHPCR-ODM document could be found at "/test"'); + $this->documentManager->find(null, '/test')->willReturn(null); $this->getRepository()->get('/test'); } @@ -274,6 +276,13 @@ public function testReorderToLast() $this->doTestReorder(66, false); } + protected function getRepository($path = null) + { + $repository = new PhpcrOdmRepository($this->managerRegistry->reveal(), $path, $this->finder->reveal()); + + return $repository; + } + private function doTestReorder($position, $before) { $evaluatedPath = '/test/foo'; @@ -292,13 +301,6 @@ private function doTestReorder($position, $before) $this->getRepository('/test')->reorder('/foo', $position); } - - protected function getRepository($path = null) - { - $repository = new PhpcrOdmRepository($this->managerRegistry->reveal(), $path, $this->finder->reveal()); - - return $repository; - } } class stdClass2 extends \stdClass diff --git a/tests/Unit/Repository/PhpcrRepositoryTest.php b/tests/Unit/Repository/PhpcrRepositoryTest.php index e98ab1a..9471bcb 100644 --- a/tests/Unit/Repository/PhpcrRepositoryTest.php +++ b/tests/Unit/Repository/PhpcrRepositoryTest.php @@ -1,9 +1,11 @@ expectException(\RuntimeException::class); + $this->expectExceptionMessage('No PHPCR node could be found at "/test"'); + $this->session->getNode('/test')->willThrow(new \PHPCR\PathNotFoundException()); $this->getRepository()->get('/test'); } @@ -274,7 +276,11 @@ public function testReorderToLast() */ protected function getRepository($path = null) { - $repository = new PhpcrRepository($this->session->reveal(), $path, $this->finder->reveal()); + $repository = new PhpcrRepository( + $this->session->reveal(), + $path, + $this->finder->reveal() + ); return $repository; } diff --git a/tests/Unit/Repository/Resource/Metadata/PhpcrMetadataTest.php b/tests/Unit/Repository/Resource/Metadata/PhpcrMetadataTest.php index 21ca7ee..f5e766f 100644 --- a/tests/Unit/Repository/Resource/Metadata/PhpcrMetadataTest.php +++ b/tests/Unit/Repository/Resource/Metadata/PhpcrMetadataTest.php @@ -1,9 +1,11 @@