diff --git a/.gitignore b/.gitignore index 987e2a2..3903b34 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ composer.lock vendor +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 30c7fcf..956bb96 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,25 +27,32 @@ 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" - - 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: STABILITY="dev" SYMFONY_VERSION=4.3.* + - php: 7.3 + env: SYMFONY_VERSION=4.2.* - php: 7.1 - env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_VERSION=2.8.* SYMFONY_DEPRECATIONS_HELPER=weak + env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_VERSION=3.4.* SYMFONY_DEPRECATIONS_HELPER="/.*each.*/" + - php: 7.2 - env: SYMFONY_VERSION=3.3.* + env: SYMFONY_VERSION=4.0.* - php: 7.2 - env: SYMFONY_VERSION=3.4.* + env: SYMFONY_VERSION=4.1.* fast_finish: true allow_failures: + - php: 7.3 + env: STABILITY="dev" SYMFONY_VERSION=4.3.* before_install: - phpenv config-rm xdebug.ini || true @@ -54,9 +62,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 03ce323..85ea37d 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/routing-auto +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 7b17c1e..38f15de 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,13 @@ [![Monthly Downloads](https://poser.pugx.org/symfony-cmf/routing-auto/d/monthly)](https://packagist.org/packages/symfony-cmf/routing-auto) [![Daily Downloads](https://poser.pugx.org/symfony-cmf/routing-auto/d/daily)](https://packagist.org/packages/symfony-cmf/routing-auto) -Branch | Travis | Coveralls | ------- | ------ | --------- | -master | [![Build Status][travis_unstable_badge]][travis_link] | [![Coverage Status][coveralls_unstable_badge]][coveralls_unstable_link] | +Branch | Travis | Coveralls | Scrutinizer | +------ | ------ | --------- | ----------- | +2.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 component automatically creates and manages routes for configured persisted document classes. @@ -21,24 +23,24 @@ This library contains all implementation agnostic code. ## 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.0 / 4.1 / 4.2 * See also the `require` section of [composer.json](composer.json) ## Documentation For the install guide and reference, see: -* [symfony-cmf/routing-auto Documentation](http://symfony.com/doc/master/cmf/components/routing/index.html) +* [symfony-cmf/routing-auto Documentation](https://symfony.com/doc/master/cmf/components/routing/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 @@ -47,7 +49,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 @@ -57,14 +59,17 @@ Thanks to This package is available under the [MIT license](src/Resources/meta/LICENSE). -[travis_legacy_badge]: https://travis-ci.org/symfony-cmf/routing-auto.svg?branch=master -[travis_stable_badge]: https://travis-ci.org/symfony-cmf/routing-auto.svg?branch=master -[travis_unstable_badge]: https://travis-ci.org/symfony-cmf/routing-auto.svg?branch=master -[travis_link]: https://travis-ci.org/symfony-cmf/routing-auto - -[coveralls_legacy_badge]: https://coveralls.io/repos/github/symfony-cmf/routing-auto/badge.svg?branch=master -[coveralls_legacy_link]: https://coveralls.io/github/symfony-cmf/routing-auto?branch=master -[coveralls_stable_badge]: https://coveralls.io/repos/github/symfony-cmf/routing-auto/badge.svg?branch=master -[coveralls_stable_link]: https://coveralls.io/github/symfony-cmf/routing-auto?branch=master -[coveralls_unstable_badge]: https://coveralls.io/repos/github/symfony-cmf/routing-auto/badge.svg?branch=master -[coveralls_unstable_link]: https://coveralls.io/github/symfony-cmf/routing-auto?branch=master +[travis_stable_badge]: https://travis-ci.org/symfony-cmf/routing-auto.svg?branch=2.1 +[travis_stable_link]: https://travis-ci.org/symfony-cmf/routing-auto +[travis_unstable_badge]: https://travis-ci.org/symfony-cmf/routing-auto.svg?branch=dev-master +[travis_unstable_link]: https://travis-ci.org/symfony-cmf/routing-auto + +[coveralls_stable_badge]: https://coveralls.io/repos/github/symfony-cmf/routing-auto/badge.svg?branch=2.1 +[coveralls_stable_link]: https://coveralls.io/github/symfony-cmf/routing-auto?branch=2.1 +[coveralls_unstable_badge]: https://coveralls.io/repos/github/symfony-cmf/routing-auto/badge.svg?branch=dev-master +[coveralls_unstable_link]: https://coveralls.io/github/symfony-cmf/routing-auto?branch=dev-master + +[scrutinizer_stable_badge]: https://scrutinizer-ci.com/g/symfony-cmf/routing-auto/badges/quality-score.png?b=2.1 +[scrutinizer_stable_link]: https://scrutinizer-ci.com/g/symfony-cmf/routing-auto/?branch=2.1 +[scrutinizer_unstable_badge]: https://scrutinizer-ci.com/g/symfony-cmf/routing-auto/badges/quality-score.png?b=dev-master +[scrutinizer_unstable_link]: https://scrutinizer-ci.com/g/symfony-cmf/routing-auto/?branch=dev-master diff --git a/composer.json b/composer.json index 62f81c0..2c0f929 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,7 @@ { "name": "symfony-cmf/routing-auto", + + "type": "library", "description": "Component for automatically creating and managing routes for persisted objects", "homepage": "http://cmf.symfony.com", "license": "MIT", @@ -13,15 +15,15 @@ "php": "^7.1", "symfony-cmf/slugifier-api": "^1.0 || ^2.0", "symfony-cmf/routing": "^1.2 || ^2.0", - "symfony/options-resolver": "^2.8 || ^3.3 || ^4.0", - "symfony/config": "^2.8 || ^3.3 || ^4.0", + "symfony/options-resolver": "^3.4 || ^4.0", + "symfony/config": "^3.4 || ^4.0", "jms/metadata": "^1.5" }, "require-dev": { - "symfony/yaml": "^2.8 || ^3.3 || ^4.0", - "symfony/dependency-injection": "^2.8 || ^3.3 || ^4.0", - "symfony/event-dispatcher": "^2.8 || ^3.3 || ^4.0", - "symfony/phpunit-bridge": "^3.3 || ^4.0", + "symfony/yaml": "^3.4 || ^4.0", + "symfony/dependency-injection": "^3.4 || ^4.0", + "symfony/event-dispatcher": "^3.4 || ^4.0", + "symfony/phpunit-bridge": "^4.2.2", "symfony-cmf/testing": "^2.1.8" }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 231fd4a..015b9f6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,19 +2,30 @@ + colors="true" + bootstrap="vendor/symfony-cmf/testing/bootstrap/bootstrap.php" +> - - - ./tests + + + + + ./tests/Unit - + + + + + + src/ + + Resources/ + + + - - - + + + diff --git a/src/Adapter/EventDispatchingAdapter.php b/src/Adapter/EventDispatchingAdapter.php index d214fbf..b70ab1f 100644 --- a/src/Adapter/EventDispatchingAdapter.php +++ b/src/Adapter/EventDispatchingAdapter.php @@ -1,9 +1,11 @@ getSubject(); - $realClassName = $this->adapter->getRealClassName(get_class($uriContextCollection->getSubject())); + $realClassName = $this->adapter->getRealClassName(\get_class($uriContextCollection->getSubject())); $metadata = $this->metadataFactory->getMetadataForClass($realClassName); $defunctRouteHandlerConfig = $metadata->getDefunctRouteHandler(); diff --git a/src/DefunctRouteHandler/LeaveRedirectDefunctRouteHandler.php b/src/DefunctRouteHandler/LeaveRedirectDefunctRouteHandler.php index e02c879..9884a5b 100644 --- a/src/DefunctRouteHandler/LeaveRedirectDefunctRouteHandler.php +++ b/src/DefunctRouteHandler/LeaveRedirectDefunctRouteHandler.php @@ -1,9 +1,11 @@ 'throw_exception', 'options' => []]; - /** * Defunct route handler, default to remove. * @@ -47,6 +39,15 @@ class ClassMetadata extends MergeableClassMetadata * @var AutoRouteDefinition[] */ protected $definitions = []; + /** + * @var array + */ + private $tokenProviders = []; + + /** + * @var array + */ + private $conflictResolver = ['name' => 'throw_exception', 'options' => []]; /** * Add a new auto route definition for this class. diff --git a/src/Mapping/Exception/CircularReferenceException.php b/src/Mapping/Exception/CircularReferenceException.php index 2e34fab..676d23a 100644 --- a/src/Mapping/Exception/CircularReferenceException.php +++ b/src/Mapping/Exception/CircularReferenceException.php @@ -1,9 +1,11 @@ getElementsByTagNameNS(self::NAMESPACE_URI, 'token-provider'); // token providers can be omitted if the schema is constructed of // global token providers only - if (0 !== count($tokenProviders)) { + if (0 !== \count($tokenProviders)) { foreach ($tokenProviders as $tokenNode) { $this->parseTokenProviderNode($tokenNode, $classMetadata, $path); } @@ -205,20 +221,6 @@ protected function parseOptionNode(\DOMNodeList $nodes, $path) return $options; } - /** - * {@inheritdoc} - */ - public function supports($resource, $type = null) - { - if (!is_string($resource)) { - return false; - } - - $extension = pathinfo($resource, PATHINFO_EXTENSION); - - return 'xml' === $extension && (null === $type || 'xml' === $type); - } - protected function getParser() { if (null === $this->parser) { diff --git a/src/Mapping/Loader/YmlFileLoader.php b/src/Mapping/Loader/YmlFileLoader.php index 0184c21..5966c78 100644 --- a/src/Mapping/Loader/YmlFileLoader.php +++ b/src/Mapping/Loader/YmlFileLoader.php @@ -1,9 +1,11 @@ $name, 'options' => $options]; } - /** - * {@inheritdoc} - */ - public function supports($resource, $type = null) - { - if (!is_string($resource)) { - return false; - } - - $extension = pathinfo($resource, PATHINFO_EXTENSION); - - return ('yml' === $extension || 'yaml' === $extension) && (null === $type || 'yaml' === $type); - } - protected function getParser() { if (null === $this->parser) { @@ -201,10 +203,10 @@ protected function getParser() protected function getAutoRouteDefinitions($definitionsNode) { - if (!is_array($definitionsNode)) { + if (!\is_array($definitionsNode)) { throw new \InvalidArgumentException(sprintf( 'Expected array or scalar definitionNode, got "%s"', - is_object($definitionsNode) ? get_class($definitionsNode) : gettype($definitionsNode) + \is_object($definitionsNode) ? \get_class($definitionsNode) : \gettype($definitionsNode) )); } diff --git a/src/Mapping/MetadataFactory.php b/src/Mapping/MetadataFactory.php index 70c8249..37b82c9 100644 --- a/src/Mapping/MetadataFactory.php +++ b/src/Mapping/MetadataFactory.php @@ -1,9 +1,11 @@ resolvedMetadatas[$class]; } + public function getIterator() + { + return new \ArrayIterator($this->metadatas); + } + /** * Resolves the metadata of parent classes of the given class. * @@ -107,7 +114,7 @@ protected function resolveMetadata($class) throw new Exception\CircularReferenceException(sprintf($e->getMessage(), $class), $e->getCode(), $e->getPrevious()); } - if (0 === count($metadatas)) { + if (0 === \count($metadatas)) { throw new Exception\ClassNotMappedException($class); } @@ -127,7 +134,7 @@ protected function doResolve($classFqn, array &$addedClasses) { $metadatas = []; - if (in_array($classFqn, $addedClasses)) { + if (\in_array($classFqn, $addedClasses, true)) { throw new Exception\CircularReferenceException('Circular reference detected for "%s", make sure you don\'t mix PHP extends and mapping extends.'); } @@ -146,9 +153,4 @@ protected function doResolve($classFqn, array &$addedClasses) return $metadatas; } - - public function getIterator() - { - return new \ArrayIterator($this->metadatas); - } } diff --git a/src/Mapping/MetadataFactoryBuilder.php b/src/Mapping/MetadataFactoryBuilder.php index 1194857..ab2aa63 100644 --- a/src/Mapping/MetadataFactoryBuilder.php +++ b/src/Mapping/MetadataFactoryBuilder.php @@ -1,9 +1,11 @@ normalizeValue($object->$method(), $uriContext, $options); } + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $optionsResolver) + { + $optionsResolver->setRequired('method'); + } + protected function checkMethodExists($object, $method) { if (!method_exists($object, $method)) { throw new \InvalidArgumentException(sprintf( 'Method "%s" does not exist on object "%s"', $method, - get_class($object) + \get_class($object) )); } } - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $optionsResolver) - { - $optionsResolver->setRequired('method'); - } - /** * Normalizes the value (e.g. slugifying). * diff --git a/src/TokenProvider/ContentDateTimeProvider.php b/src/TokenProvider/ContentDateTimeProvider.php index 8eb6325..a507959 100644 --- a/src/TokenProvider/ContentDateTimeProvider.php +++ b/src/TokenProvider/ContentDateTimeProvider.php @@ -1,9 +1,11 @@ getSubject()), - $options['method'] - )); - } + parent::configureOptions($optionsResolver); - return $date->format($options['date_format']); + $optionsResolver->setDefault('date_format', 'Y-m-d'); + + $optionsResolver->setAllowedTypes('date_format', 'string'); } /** * {@inheritdoc} */ - public function configureOptions(OptionsResolver $optionsResolver) + protected function normalizeValue($date, UriContext $uriContext, $options) { - parent::configureOptions($optionsResolver); - - $optionsResolver->setDefault('date_format', 'Y-m-d'); + if (!$date instanceof \DateTime) { + throw new \RuntimeException(sprintf('Method %s:%s must return an instance of DateTime.', + \get_class($uriContext->getSubject()), + $options['method'] + )); + } - $optionsResolver->setAllowedTypes('date_format', 'string'); + return $date->format($options['date_format']); } } diff --git a/src/TokenProvider/ContentLocaleProvider.php b/src/TokenProvider/ContentLocaleProvider.php index ce6ca74..90d227d 100644 --- a/src/TokenProvider/ContentLocaleProvider.php +++ b/src/TokenProvider/ContentLocaleProvider.php @@ -1,9 +1,11 @@ slugifier->slugify($value); - } + parent::configureOptions($optionsResolver); - return $value; + $optionsResolver->setDefault('slugify', true); + + $optionsResolver->setAllowedTypes('slugify', 'bool'); } /** * {@inheritdoc} */ - public function configureOptions(OptionsResolver $optionsResolver) + protected function normalizeValue($value, UriContext $uriContext, $options) { - parent::configureOptions($optionsResolver); - - $optionsResolver->setDefault('slugify', true); + if ($options['slugify']) { + $value = $this->slugifier->slugify($value); + } - $optionsResolver->setAllowedTypes('slugify', 'bool'); + return $value; } } diff --git a/src/TokenProvider/SymfonyContainerParameterProvider.php b/src/TokenProvider/SymfonyContainerParameterProvider.php index 268194a..7f3f8de 100644 --- a/src/TokenProvider/SymfonyContainerParameterProvider.php +++ b/src/TokenProvider/SymfonyContainerParameterProvider.php @@ -1,9 +1,11 @@ getSubject(); - $realClassName = $this->adapter->getRealClassName(get_class($subject)); + $realClassName = $this->adapter->getRealClassName(\get_class($subject)); $metadata = $this->metadataFactory->getMetadataForClass($realClassName); // TODO: This is where we will call $metadata->getUriSchemas() which will return an diff --git a/src/UriGenerator.php b/src/UriGenerator.php index 79dc694..e9696fd 100644 --- a/src/UriGenerator.php +++ b/src/UriGenerator.php @@ -1,9 +1,11 @@ getSubject()) + $uri, \get_class($uriContext->getSubject()) )); } diff --git a/src/UriGeneratorInterface.php b/src/UriGeneratorInterface.php index da055ea..8082c34 100644 --- a/src/UriGeneratorInterface.php +++ b/src/UriGeneratorInterface.php @@ -1,9 +1,11 @@ uriContext = $this->prophesize(UriContext::class); } - /** - * @expectedException \Symfony\Cmf\Component\RoutingAuto\ConflictResolver\Exception\ExistingUriException - * @expectedExceptionMessage There already exists an auto route for URL "/foobar" - */ public function testResolveConflict() { + $this->expectException(\Symfony\Cmf\Component\RoutingAuto\ConflictResolver\Exception\ExistingUriException::class); + $this->expectExceptionMessage('There already exists an auto route for URL "/foobar"'); + $this->uriContext->getUri()->willReturn('/foobar'); $this->conflictResolver->resolveConflict($this->uriContext->reveal()); } diff --git a/tests/Unit/DefunctRouteHandler/DelegatingDefunctRouteHandlerTest.php b/tests/Unit/DefunctRouteHandler/DelegatingDefunctRouteHandlerTest.php index 452fb04..5bf376f 100644 --- a/tests/Unit/DefunctRouteHandler/DelegatingDefunctRouteHandlerTest.php +++ b/tests/Unit/DefunctRouteHandler/DelegatingDefunctRouteHandlerTest.php @@ -1,9 +1,11 @@ expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('No definition'); + $metadata = new ClassMetadata('stdClass'); $metadata->getAutoRouteDefinition(123); } diff --git a/tests/Unit/Mapping/Loader/XmlFileLoaderTest.php b/tests/Unit/Mapping/Loader/XmlFileLoaderTest.php index 3aa8a56..d1d4cbb 100644 --- a/tests/Unit/Mapping/Loader/XmlFileLoaderTest.php +++ b/tests/Unit/Mapping/Loader/XmlFileLoaderTest.php @@ -1,9 +1,11 @@ expectException(\InvalidArgumentException::class); + $this->locator->locate($file)->willReturn($this->getFixturesPath($file)); $this->loader->load($file); diff --git a/tests/Unit/Mapping/Loader/YmlFileLoaderTest.php b/tests/Unit/Mapping/Loader/YmlFileLoaderTest.php index 880c44e..e13c21b 100644 --- a/tests/Unit/Mapping/Loader/YmlFileLoaderTest.php +++ b/tests/Unit/Mapping/Loader/YmlFileLoaderTest.php @@ -1,9 +1,11 @@ setExpectedException('InvalidArgumentException', $expectedMessage); + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage($expectedMessage); } else { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException('InvalidArgumentException'); } $this->locator->locate($file)->willReturn($this->getFixturesPath($file)); diff --git a/tests/Unit/Mapping/MetadataFactoryTest.php b/tests/Unit/Mapping/MetadataFactoryTest.php index d981d9e..2af9192 100644 --- a/tests/Unit/Mapping/MetadataFactoryTest.php +++ b/tests/Unit/Mapping/MetadataFactoryTest.php @@ -1,9 +1,11 @@ assertEquals('{title}', $resolvedMetadata->getAutoRouteDefinition('one')->getUriSchema()); } - /** - * @expectedException \Symfony\Cmf\Component\RoutingAuto\Mapping\Exception\CircularReferenceException - * @expectedExceptionMessage "Symfony\Cmf\Component\RoutingAuto\Tests\Resources\Fixtures\ParentClass" - */ public function testFailsWithCircularReference() { + $this->expectException(\Symfony\Cmf\Component\RoutingAuto\Mapping\Exception\CircularReferenceException::class); + $this->expectExceptionMessage('"Symfony\\Cmf\\Component\\RoutingAuto\\Tests\\Resources\\Fixtures\\ParentClass"'); + $parentMetadata = new ClassMetadata(ParentClass::class); $parentMetadata->setAutoRouteDefinition('one', new AutoRouteDefinition('{title}')); $parentMetadata->setExtendedClass(Parent1Class::class); @@ -185,12 +187,11 @@ public function testFailsWithCircularReference() $this->factory->getMetadataForClass(ParentClass::class); } - /** - * @expectedException \Symfony\Cmf\Component\RoutingAuto\Mapping\Exception\CircularReferenceException - * @expectedExceptionMessage "Symfony\Cmf\Component\RoutingAuto\Tests\Resources\Fixtures\ChildClass" - */ public function testsFailsWithPhpCircularReference() { + $this->expectException(\Symfony\Cmf\Component\RoutingAuto\Mapping\Exception\CircularReferenceException::class); + $this->expectExceptionMessage('"Symfony\\Cmf\\Component\\RoutingAuto\\Tests\\Resources\\Fixtures\\ChildClass"'); + $childMetadata = new ClassMetadata(ChildClass::class); $childMetadata->setAutoRouteDefinition('one', new AutoRouteDefinition('{title}')); diff --git a/tests/Unit/ServiceRegistryTest.php b/tests/Unit/ServiceRegistryTest.php index c6d5222..09d4fb6 100644 --- a/tests/Unit/ServiceRegistryTest.php +++ b/tests/Unit/ServiceRegistryTest.php @@ -1,9 +1,11 @@ uriContext->getSubject()->willReturn($this->article); if (!$methodExists) { - $this->setExpectedException( - 'InvalidArgumentException', 'Method "'.$options['method'].'" does not exist' + $this->expectException( + 'InvalidArgumentException'); + $this->expectExceptionMessage('Method "'.$options['method'].'" does not exist' ); } else { $expectedResult = 'This is value'; diff --git a/tests/Unit/TokenProvider/SymfonyContainerParameterProviderTest.php b/tests/Unit/TokenProvider/SymfonyContainerParameterProviderTest.php index c440a47..f9d5a4d 100644 --- a/tests/Unit/TokenProvider/SymfonyContainerParameterProviderTest.php +++ b/tests/Unit/TokenProvider/SymfonyContainerParameterProviderTest.php @@ -1,9 +1,11 @@ setExpectedException($expectedException); + $this->expectException($expectedException); } $this->container->getParameter('foobar')->willReturn('barfoo'); diff --git a/tests/Unit/UriContextCollectionBuilderTest.php b/tests/Unit/UriContextCollectionBuilderTest.php index 303e0d9..23704d2 100644 --- a/tests/Unit/UriContextCollectionBuilderTest.php +++ b/tests/Unit/UriContextCollectionBuilderTest.php @@ -1,9 +1,11 @@ setExpectedException($exceptionType, $exceptionMessage); + $this->expectException($exceptionType); + $this->expectExceptionMessage($exceptionMessage); } $document = new \stdClass();