diff --git a/.gitignore b/.gitignore index 7463ccd..d6b12dd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ tests/Fixtures/App/var/ !tests/Fixtures/App/var/.gitempty 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 2013814..f5b27da 100644 --- a/.travis.yml +++ b/.travis.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. # @@ -17,7 +17,8 @@ language: php php: - 7.1 - + - 7.2 + - 7.3 sudo: false cache: @@ -26,28 +27,27 @@ cache: - $HOME/.composer/cache/files env: - matrix: SYMFONY_VERSION=4.0.* + matrix: SYMFONY_VERSION=4.2.* global: - SYMFONY_DEPRECATIONS_HELPER="/.*each.*/" - SYMFONY_PHPUNIT_DIR=.phpunit SYMFONY_PHPUNIT_REMOVE="symfony/yaml" - - KERNEL_CLASS=Symfony\Cmf\Bundle\ResourceBundle\Tests\Fixtures\App\Kernel - - SYMFONY_PHPUNIT_VERSION=5.7 - - TEST_INSTALLATION=false + - SYMFONY_PHPUNIT_VERSION=7 + - PHPUNIT_VERSION=7 + - TARGET=test matrix: include: - - php: 7.2 - env: SYMFONY_VERSION=4.0.* + - env: TARGET=lint + - php: 7.3 + env: SYMFONY_VERSION=4.2.* - php: 7.1 - env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_VERSION=2.8.* SYMFONY_DEPRECATIONS_HELPER=weak - - php: 7.2 - env: SYMFONY_VERSION=3.3.* + env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_VERSION=3.4.* SYMFONY_DEPRECATIONS_HELPER="/.*each.*/" + - php: 7.2 - env: SYMFONY_VERSION=3.4.* - - env: TEST_INSTALLATION=true + env: SYMFONY_VERSION=4.1.* + - env: TARGET=test_installation fast_finish: true - allow_failures: - - env: TEST_INSTALLATION=true + - env: TARGET=test_installation before_install: - phpenv config-rm xdebug.ini || true @@ -57,9 +57,13 @@ before_install: - 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: travis_wait composer update --prefer-dist $COMPOSER_FLAGS -script: - - if [ "${TEST_INSTALLATION}" == true ]; then make test_installation; else make test; fi +install: + - if [ -x .travis/install_${TARGET}.sh ]; then .travis/install_${TARGET}.sh; fi; + +script: make $TARGET + +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 a9e461f..3fb73b8 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,16 +20,63 @@ ifdef BRANCH VERSION=dev-${BRANCH} endif PACKAGE=symfony-cmf/resource-bundle -export KERNEL_CLASS=Symfony\Cmf\Bundle\ResourceBundle\Tests\Fixtures\App\Kernel +HAS_XDEBUG=$(shell php --modules|grep --quiet xdebug;echo $$?) + list: @echo 'test: will run all tests' @echo 'unit_tests: will run unit tests only' @echo 'functional_tests_phpcr: will run functional tests with PHPCR' - @echo 'test_installation: will run installation test' -include ${TESTING_SCRIPTS_DIR}/make/unit_tests.mk -include ${TESTING_SCRIPTS_DIR}/make/functional_tests_phpcr.mk -include ${TESTING_SCRIPTS_DIR}/make/test_installation.mk + @echo 'test_installation: will run installation test'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 +EXTRA_INCLUDES:=$(wildcard ${TESTING_SCRIPTS_DIR}/make/functional_tests_phpcr.mk) +ifneq ($(strip $(EXTRA_INCLUDES)),) + contents := $(shell echo including extra rules $(EXTRA_INCLUDES)) + include $(EXTRA_INCLUDES) + TEST_DEPENDENCIES := $(TEST_DEPENDENCIES)" functional_tests_phpcr" + endif +EXTRA_INCLUDES:=$(wildcard ${TESTING_SCRIPTS_DIR}/make/test_installation.mk) +ifneq ($(strip $(EXTRA_INCLUDES)),) + contents := $(shell echo including extra rules $(EXTRA_INCLUDES)) + include $(EXTRA_INCLUDES) + endif .PHONY: test -test: unit_tests functional_tests_phpcr +test: build/xdebug-filter.php$ +ifneq ($(strip $(wildcard ${TESTING_SCRIPTS_DIR}/make/unit_tests.mk)),) + @make unit_tests +endif +ifneq ($(strip $(wildcard ${TESTING_SCRIPTS_DIR}/make/functional_tests_phpcr.mk)),) + @make functional_tests_phpcr +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 d80fa4c..e6ffc4a 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,13 @@ [![Monthly Downloads](https://poser.pugx.org/symfony-cmf/resource-bundle/d/monthly)](https://packagist.org/packages/symfony-cmf/resource-bundle) [![Daily Downloads](https://poser.pugx.org/symfony-cmf/resource-bundle/d/daily)](https://packagist.org/packages/symfony-cmf/resource-bundle) -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). This bundle provides *object* resource location services based on Puli. @@ -36,24 +38,24 @@ provide the context with which to resolve the documents. ## Requirements -* PHP 7.1 / 7.2 -* Symfony 2.8 / 3.3 / 3.4 / 4.0 +* PHP 7.1 / 7.2 / 7.3 +* Symfony 3.4 / 4.1 / 4.2 * See also the `require` section of [composer.json](composer.json) ## Documentation For the install guide and reference, see: -* [symfony-cmf/resource-bundle Documentation](http://symfony.com/doc/master/cmf/bundles/resource-rest/index.html) +* [symfony-cmf/resource-bundle Documentation](https://symfony.com/doc/master/cmf/bundles/resource-rest/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 @@ -62,7 +64,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 @@ -72,14 +74,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-bundle.svg?branch=master -[travis_stable_badge]: https://travis-ci.org/symfony-cmf/resource-bundle.svg?branch=master -[travis_unstable_badge]: https://travis-ci.org/symfony-cmf/resource-bundle.svg?branch=master -[travis_link]: https://travis-ci.org/symfony-cmf/resource-bundle - -[coveralls_legacy_badge]: https://coveralls.io/repos/github/symfony-cmf/resource-bundle/badge.svg?branch=master -[coveralls_legacy_link]: https://coveralls.io/github/symfony-cmf/resource-bundle?branch=master -[coveralls_stable_badge]: https://coveralls.io/repos/github/symfony-cmf/resource-bundle/badge.svg?branch=master -[coveralls_stable_link]: https://coveralls.io/github/symfony-cmf/resource-bundle?branch=master -[coveralls_unstable_badge]: https://coveralls.io/repos/github/symfony-cmf/resource-bundle/badge.svg?branch=master -[coveralls_unstable_link]: https://coveralls.io/github/symfony-cmf/resource-bundle?branch=master +[travis_stable_badge]: https://travis-ci.org/symfony-cmf/resource-bundle.svg?branch=1.1 +[travis_stable_link]: https://travis-ci.org/symfony-cmf/resource-bundle +[travis_unstable_badge]: https://travis-ci.org/symfony-cmf/resource-bundle.svg?branch=dev-master +[travis_unstable_link]: https://travis-ci.org/symfony-cmf/resource-bundle + +[coveralls_stable_badge]: https://coveralls.io/repos/github/symfony-cmf/resource-bundle/badge.svg?branch=1.1 +[coveralls_stable_link]: https://coveralls.io/github/symfony-cmf/resource-bundle?branch=1.1 +[coveralls_unstable_badge]: https://coveralls.io/repos/github/symfony-cmf/resource-bundle/badge.svg?branch=dev-master +[coveralls_unstable_link]: https://coveralls.io/github/symfony-cmf/resource-bundle?branch=dev-master + +[scrutinizer_stable_badge]: https://scrutinizer-ci.com/g/symfony-cmf/resource-bundle/badges/quality-score.png?b=1.1 +[scrutinizer_stable_link]: https://scrutinizer-ci.com/g/symfony-cmf/resource-bundle/?branch=1.1 +[scrutinizer_unstable_badge]: https://scrutinizer-ci.com/g/symfony-cmf/resource-bundle/badges/quality-score.png?b=dev-master +[scrutinizer_unstable_link]: https://scrutinizer-ci.com/g/symfony-cmf/resource-bundle/?branch=dev-master diff --git a/composer.json b/composer.json index c14b037..6e4e8e4 100644 --- a/composer.json +++ b/composer.json @@ -11,14 +11,19 @@ ], "require": { "php": "^7.1", - "symfony/framework-bundle": "^2.8 || ^3.3 || ^4.0", - "symfony/options-resolver": "^2.8 || ^3.3 || ^4.0", - "symfony-cmf/resource": "^1.0" + "symfony/framework-bundle": "^3.4 || ^4.1", + "symfony/options-resolver": "^3.4 || ^4.1", + "symfony-cmf/resource": "^1.0", + "symfony/translation": "^3.4 || ^4.1", + "symfony/form": "^3.4 || ^4.1", + "symfony/templating": "^3.4 || ^4.1", + "symfony/validator": "^3.4 || ^4.1" }, "require-dev": { "symfony-cmf/testing": "^2.1.8", - "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/yaml": "^3.4 || ^4.1" }, "suggest": { "doctrine/phpcr-odm": "To enable support for the PHPCR ODM documents (^1.3)", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 218721f..ba7feb0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,36 @@ + + colors="true" + bootstrap="vendor/symfony-cmf/testing/bootstrap/bootstrap.php" +> - - + + + + ./tests/Unit - + ./tests/Functional + ./tests/Functional/Doctrine/Orm - + + + + + + src/ + + Resources/ + + + + + - - - src/ - - *Bundle.php - Resources/ - - - + + diff --git a/src/CmfResourceBundle.php b/src/CmfResourceBundle.php index 71873ea..fcdf7a0 100644 --- a/src/CmfResourceBundle.php +++ b/src/CmfResourceBundle.php @@ -1,9 +1,11 @@ loadRepositories($container, $config['repositories'], $config['default_repository']); } + public function addRepositoryFactory($name, RepositoryFactoryInterface $factory) + { + $this->repositoryFactories[$name] = $factory; + } + + /** + * {@inheritdoc} + */ + public function getNamespace() + { + return 'http://cmf.symfony.com/schema/dic/cmf_resource'; + } + private function loadRepositories(ContainerBuilder $container, array $configs, $defaultRepositoryName) { $repositoryTypes = array_keys($this->repositoryFactories); @@ -61,11 +76,13 @@ private function loadRepositories(ContainerBuilder $container, array $configs, $ $type = $config['type']; if (!isset($this->repositoryFactories[$type])) { - throw new InvalidArgumentException(sprintf( - 'Unknown repository type "%s", known repository types: "%s"', - $type, - implode('", "', $repositoryTypes) - )); + throw new InvalidArgumentException( + sprintf( + 'Unknown repository type "%s", known repository types: "%s"', + $type, + implode('", "', $repositoryTypes) + ) + ); } $factory = $this->repositoryFactories[$type]; @@ -76,10 +93,14 @@ private function loadRepositories(ContainerBuilder $container, array $configs, $ try { $config = $optionsResolver->resolve($config['options']); } catch (\Exception $e) { - throw new InvalidArgumentException(sprintf( - 'Invalid configuration for repository "%s"', - $repositoryName - ), null, $e); + throw new InvalidArgumentException( + sprintf( + 'Invalid configuration for repository "%s"', + $repositoryName + ), + 0, + $e + ); } $serviceId = self::getRepositoryServiceId($repositoryName); @@ -98,17 +119,4 @@ private function loadRepositories(ContainerBuilder $container, array $configs, $ $registry->replaceArgument(1, $serviceMap); $registry->replaceArgument(2, $typeMap); } - - public function addRepositoryFactory($name, RepositoryFactoryInterface $factory) - { - $this->repositoryFactories[$name] = $factory; - } - - /** - * {@inheritdoc} - */ - public function getNamespace() - { - return 'http://cmf.symfony.com/schema/dic/cmf_resource'; - } } diff --git a/src/DependencyInjection/Compiler/DescriptionEnhancerPass.php b/src/DependencyInjection/Compiler/DescriptionEnhancerPass.php index c8bac89..1946cc3 100644 --- a/src/DependencyInjection/Compiler/DescriptionEnhancerPass.php +++ b/src/DependencyInjection/Compiler/DescriptionEnhancerPass.php @@ -1,9 +1,11 @@ addDefaultsIfNotSet() ->beforeNormalization() ->ifTrue(function ($n) { - return is_array($n) && !isset($n['options']) && !isset($n['option']); + return \is_array($n) && !isset($n['options']) && !isset($n['option']); }) ->then(function ($n) { $options = []; @@ -68,13 +70,13 @@ public function getConfigTreeBuilder() ->arrayNode('options') ->beforeNormalization() ->ifTrue(function ($n) { - return is_array($n) && 0 !== count(array_filter($n, function ($i) { + return \is_array($n) && 0 !== \count(array_filter($n, function ($i) { return isset($i['collection']); })); }) ->then(function ($n) { foreach ($n as $id => $item) { - if (!is_array($item) || !isset($item['collection'])) { + if (!\is_array($item) || !isset($item['collection'])) { continue; } diff --git a/src/DependencyInjection/Repository/Factory/DoctrinePhpcrOdmFactory.php b/src/DependencyInjection/Repository/Factory/DoctrinePhpcrOdmFactory.php index 7b04bba..9e5e415 100644 --- a/src/DependencyInjection/Repository/Factory/DoctrinePhpcrOdmFactory.php +++ b/src/DependencyInjection/Repository/Factory/DoctrinePhpcrOdmFactory.php @@ -1,9 +1,11 @@ typeMap[$class])) { throw new \RuntimeException(sprintf( 'Repository of class "%s" is not known, could not determine its type.', diff --git a/src/Resources/meta/LICENSE b/src/Resources/meta/LICENSE index 99f8144..b8106e1 100644 --- a/src/Resources/meta/LICENSE +++ b/src/Resources/meta/LICENSE @@ -1,8 +1,8 @@ -Symfony Cmf Resource Bundle +Symfony CMF Resource Bundle The MIT License - Copyright (c) 2011-2017 Symfony CMF + Copyright (c) Symfony CMF Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/Twig/DescriptionExtension.php b/src/Twig/DescriptionExtension.php index 87db11c..9f47875 100644 --- a/src/Twig/DescriptionExtension.php +++ b/src/Twig/DescriptionExtension.php @@ -1,9 +1,11 @@ baseNode->addNode('node-2'); $this->session->save(); - $expectedNbMoved = count($expectedPaths); + $expectedNbMoved = \count($expectedPaths); $nbMoved = $this->getRepository()->move($sourcePath, $targetPath); $this->assertEquals($expectedNbMoved, $nbMoved); @@ -144,7 +146,7 @@ public function testRemove($path, $expectedRemovedPaths) $this->baseNode->addNode('node-2'); $this->session->save(); - $expectedNbRemoved = count($expectedRemovedPaths); + $expectedNbRemoved = \count($expectedRemovedPaths); $nbRemoved = $this->getRepository()->remove($path); $this->assertEquals($expectedNbRemoved, $nbRemoved); @@ -199,12 +201,12 @@ public function provideReorder() /** * It should throw an exception if the reorder index is less than zero. - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Reorder position cannot be negative, got: -5 */ public function testReorderNegative() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Reorder position cannot be negative, got: -5'); + $this->getRepository()->reorder('/foo', -5); } } diff --git a/tests/Functional/RepositoryTestCase.php b/tests/Functional/RepositoryTestCase.php index 81d70e3..d3e7d6e 100644 --- a/tests/Functional/RepositoryTestCase.php +++ b/tests/Functional/RepositoryTestCase.php @@ -1,9 +1,11 @@ prophesize(ResourceRepository::class); $this->extension->addRepositoryFactory('foobar', $this->repositoryFactory->reveal()); - $this->repositoryFactory->create([])->willReturn(new Definition(get_class($repository->reveal()))); + $this->repositoryFactory->create([])->willReturn(new Definition(\get_class($repository->reveal()))); $this->repositoryFactory->configure(Argument::type(OptionsResolver::class))->willReturn(null); } @@ -66,12 +68,12 @@ public function testLoadRegistry() /** * Repositories: It should throw an exception if an unknown type is specified. - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Unknown repository type "bar", known repository types: "foobar" */ public function testConfigRepositoryNoType() { + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown repository type "bar", known repository types: "foobar"'); + $this->extension->load([ [ 'repositories' => [ diff --git a/tests/Unit/DependencyInjection/Compiler/DescriptionEnhancerPassTest.php b/tests/Unit/DependencyInjection/Compiler/DescriptionEnhancerPassTest.php index 63eee2e..90dfede 100644 --- a/tests/Unit/DependencyInjection/Compiler/DescriptionEnhancerPassTest.php +++ b/tests/Unit/DependencyInjection/Compiler/DescriptionEnhancerPassTest.php @@ -1,9 +1,11 @@ expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('has no "alias" attribute'); + $this->container->has('cmf_resource.description.factory')->willReturn(true); $this->container->getParameter('cmf_resource.description.enabled_enhancers')->willReturn([ 'enhancer_1', @@ -82,12 +84,12 @@ public function testHasNoAlias() /** * It should throw an exception if two tags have the same alias. - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage has already been registered */ public function testDuplicatedAlias() { + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('has already been registered'); + $this->container->has('cmf_resource.description.factory')->willReturn(true); $this->container->getParameter('cmf_resource.description.enabled_enhancers')->willReturn([ 'enhancer_1', @@ -102,12 +104,12 @@ public function testDuplicatedAlias() /** * It should throw an exception if an unknown enhancer is enabled. - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Unknown description enhancer(s) "three" were enabled, available enhancers: "one", "two" */ public function testUnknownEnhancer() { + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown description enhancer(s) "three" were enabled, available enhancers: "one", "two"'); + $this->container->has('cmf_resource.description.factory')->willReturn(true); $this->container->getParameter('cmf_resource.description.enabled_enhancers')->willReturn([ 'three', @@ -122,12 +124,12 @@ public function testUnknownEnhancer() /** * It should throw an exception if an invalid tag attributes is used. - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage Unknown tag attributes "foobar" for service "service_1", valid attributes: "name", "alias", "priority */ public function testInvalidAttribute() { + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown tag attributes "foobar" for service "service_1", valid attributes: "name", "alias", "priority'); + $this->container->has('cmf_resource.description.factory')->willReturn(true); $this->container->getParameter('cmf_resource.description.enabled_enhancers')->willReturn([ 'service_1', @@ -153,9 +155,9 @@ public function testSortDescriptionEnhancers() ]); $this->container->findTaggedServiceIds('cmf_resource.description.enhancer')->willReturn([ 'service_1' => [['alias' => 'enhancer_1']], - 'service_2' => [['alias' => 'enhancer_2', 'priority' => 255]], - 'service_3' => [['alias' => 'enhancer_3', 'priority' => -250]], - 'service_4' => [['alias' => 'enhancer_4', 'priority' => -255]], + 'service_2' => [['alias' => 'enhancer_2', 'priority' => '255']], + 'service_3' => [['alias' => 'enhancer_3', 'priority' => '-250']], + 'service_4' => [['alias' => 'enhancer_4', 'priority' => '-255']], ]); $this->container->getDefinition('cmf_resource.description.factory')->willReturn($this->factoryDefinition->reveal()); diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index efe2505..c4c016c 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -1,9 +1,11 @@ expectException(\Symfony\Component\OptionsResolver\Exception\MissingOptionsException::class); + $this->expectExceptionMessage('The required option "base_dir" is missing.'); + $this->buildContainer( $this->resolveOptions([ ]) diff --git a/tests/Unit/DependencyInjection/Repository/Factory/PhpcrFactoryTest.php b/tests/Unit/DependencyInjection/Repository/Factory/PhpcrFactoryTest.php index aa1ce52..38a4a14 100644 --- a/tests/Unit/DependencyInjection/Repository/Factory/PhpcrFactoryTest.php +++ b/tests/Unit/DependencyInjection/Repository/Factory/PhpcrFactoryTest.php @@ -1,9 +1,11 @@ expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Repository "barbar" has not been registered, available repositories: "test"'); + $registry = $this->createRegistry( [ 'test' => 'test_repository', @@ -65,12 +67,12 @@ public function testUnknownRepositoryName() /** * It should throw an exception if an name is requested for an unknown repository. - * - * @expectedException \RuntimeException - * @expectedExceptionMessage I don't know what its name is */ public function testGetNameUnknownRepository() { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('I don\'t know what its name is'); + $registry = $this->createRegistry([]); $repository = $this->prophesize(ResourceRepository::class); @@ -79,12 +81,12 @@ public function testGetNameUnknownRepository() /** * It should throw an exception if a type is requsted for an unknown repository. - * - * @expectedException \RuntimeException - * @expectedExceptionMessage could not determine its type */ public function testGetTypeUnknownRepository() { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('could not determine its type'); + $registry = $this->createRegistry([]); $repository = $this->prophesize(ResourceRepository::class); @@ -131,9 +133,9 @@ private function createRegistry(array $serviceMap) $repository = $this->prophesize(ResourceRepository::class); $this->container->register( $serviceId, - get_class($repository->reveal()) + \get_class($repository->reveal()) ); - $typeMap[get_class($repository->reveal())] = 'test/type'; + $typeMap[\get_class($repository->reveal())] = 'test/type'; } return new RepositoryRegistry( diff --git a/tests/Unit/Twig/DescriptionExtensionTest.php b/tests/Unit/Twig/DescriptionExtensionTest.php index 13640b2..d2d3ec4 100644 --- a/tests/Unit/Twig/DescriptionExtensionTest.php +++ b/tests/Unit/Twig/DescriptionExtensionTest.php @@ -1,9 +1,11 @@