diff --git a/.gitignore b/.gitignore index f283645b..df05c4b5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ tests/Fixtures/App/var !tests/Fixtures/App/var/.gitempty composer.lock vendor +/.php_cs +.php_cs.cache diff --git a/.php_cs b/.php_cs new file mode 100644 index 00000000..97adafa4 --- /dev/null +++ b/.php_cs @@ -0,0 +1,3 @@ + 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 2bdb04b1..c721eb61 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 3b236f0b..58e7ced2 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,22 +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" - - KERNEL_CLASS=Symfony\Cmf\Bundle\SeoBundle\Tests\Fixtures\App\Kernel - - SYMFONY_PHPUNIT_VERSION=5.7.26 - - TEST_INSTALLATION=false + - SYMFONY_PHPUNIT_VERSION=7 + - PHPUNIT_VERSION=7 + - TARGET=test matrix: include: + - env: TARGET=lint + - php: 7.3 + env: STABILITY="dev" SYMFONY_VERSION=4.3.* - php: 7.3 - env: SYMFONY_VERSION=4.0.* + env: SYMFONY_VERSION=4.2.* + - php: 7.1 + env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_VERSION=3.4.* SYMFONY_DEPRECATIONS_HELPER="/.*each.*/" + - php: 7.2 - env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_VERSION=3.4.* SYMFONY_DEPRECATIONS_HELPER=weak + env: SYMFONY_VERSION=4.1.* + - env: TARGET=test_installation fast_finish: true allow_failures: + - php: 7.3 + env: STABILITY="dev" SYMFONY_VERSION=4.3.* + - env: TARGET=test_installation before_install: - phpenv config-rm xdebug.ini || true @@ -51,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 00000000..98374202 --- /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 00000000..864c751e --- /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 00000000..a0335009 --- /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/CHANGELOG.md b/CHANGELOG.md index f4858f45..485ea6d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Changelog 2.2.0 (unreleased) ------------------ - +* **2019-02-28**: Symfony 4.2 support without warnings 2.1.0 ----- diff --git a/Makefile b/Makefile index fc7d99ce..966e9c7f 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,72 @@ ifdef BRANCH VERSION=dev-${BRANCH} endif PACKAGE=symfony-cmf/seo-bundle -export KERNEL_CLASS=Symfony\Cmf\Bundle\SeoBundle\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 'functional_tests_orm: will run functional tests with ORM' - -include ${TESTING_SCRIPTS_DIR}/make/unit_tests.mk -include ${TESTING_SCRIPTS_DIR}/make/functional_tests_phpcr.mk -include ${TESTING_SCRIPTS_DIR}/make/functional_tests_orm.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/functional_tests_orm.mk) +ifneq ($(strip $(EXTRA_INCLUDES)),) + contents := $(shell echo including extra rules $(EXTRA_INCLUDES)) + include $(EXTRA_INCLUDES) + TEST_DEPENDENCIES := $(TEST_DEPENDENCIES)" functional_tests_orm" + 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 functional_tests_orm +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 +ifneq ($(strip $(wildcard ${TESTING_SCRIPTS_DIR}/make/functional_tests_orm.mk)),) + @make functional_tests_orm +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 68196bd3..7c4abc95 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ Branch | Travis | Coveralls | Scrutinizer | ------ | ------ | --------- | ----------- | -2.x | [![Build Status][travis_stable_badge]][travis_stable_link] | [![Coverage Status][coveralls_stable_badge]][coveralls_stable_link] | [![Scrutinizer Status][scrutinizer_stable_badge]][scrutinizer_stable_link] | -3.0-dev | [![Build Status][travis_unstable_badge]][travis_unstable_link] | [![Coverage Status][coveralls_unstable_badge]][coveralls_unstable_link] | [![Scrutinizer Status][scrutinizer_unstable_badge]][scrutinizer_unstable_link] | +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). It provides a solution to make content bundles @@ -23,24 +23,24 @@ aware for Search Engine Optimisation (SEO). ## Requirements -* PHP 7.2 / 7.3 -* Symfony 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/seo-bundle Documentation](http://symfony.com/doc/master/cmf/bundles/seo/index.html) +* [symfony-cmf/seo-bundle Documentation](https://symfony.com/doc/master/cmf/bundles/seo/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 @@ -49,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 @@ -59,17 +59,17 @@ Thanks to This package is available under the [MIT license](src/Resources/meta/LICENSE). -[travis_stable_badge]: https://travis-ci.org/symfony-cmf/seo-bundle.svg?branch=2.x +[travis_stable_badge]: https://travis-ci.org/symfony-cmf/seo-bundle.svg?branch=2.1 [travis_stable_link]: https://travis-ci.org/symfony-cmf/seo-bundle -[travis_unstable_badge]: https://travis-ci.org/symfony-cmf/seo-bundle.svg?branch=3.0-dev +[travis_unstable_badge]: https://travis-ci.org/symfony-cmf/seo-bundle.svg?branch=dev-master [travis_unstable_link]: https://travis-ci.org/symfony-cmf/seo-bundle -[coveralls_stable_badge]: https://coveralls.io/repos/github/symfony-cmf/seo-bundle/badge.svg?branch=2.x -[coveralls_stable_link]: https://coveralls.io/github/symfony-cmf/seo-bundle?branch=2.x -[coveralls_unstable_badge]: https://coveralls.io/repos/github/symfony-cmf/seo-bundle/badge.svg?branch=3.0-dev -[coveralls_unstable_link]: https://coveralls.io/github/symfony-cmf/seo-bundle?branch=3.0-dev +[coveralls_stable_badge]: https://coveralls.io/repos/github/symfony-cmf/seo-bundle/badge.svg?branch=2.1 +[coveralls_stable_link]: https://coveralls.io/github/symfony-cmf/seo-bundle?branch=2.1 +[coveralls_unstable_badge]: https://coveralls.io/repos/github/symfony-cmf/seo-bundle/badge.svg?branch=dev-master +[coveralls_unstable_link]: https://coveralls.io/github/symfony-cmf/seo-bundle?branch=dev-master -[scrutinizer_stable_badge]: https://scrutinizer-ci.com/g/symfony-cmf/seo-bundle/badges/quality-score.png?b=2.x -[scrutinizer_stable_link]: https://scrutinizer-ci.com/g/symfony-cmf/seo-bundle/?branch=2.x -[scrutinizer_unstable_badge]: https://scrutinizer-ci.com/g/symfony-cmf/seo-bundle/badges/quality-score.png?b=3.0-dev -[scrutinizer_unstable_link]: https://scrutinizer-ci.com/g/symfony-cmf/seo-bundle/?branch=3.0-dev +[scrutinizer_stable_badge]: https://scrutinizer-ci.com/g/symfony-cmf/seo-bundle/badges/quality-score.png?b=2.1 +[scrutinizer_stable_link]: https://scrutinizer-ci.com/g/symfony-cmf/seo-bundle/?branch=2.1 +[scrutinizer_unstable_badge]: https://scrutinizer-ci.com/g/symfony-cmf/seo-bundle/badges/quality-score.png?b=dev-master +[scrutinizer_unstable_link]: https://scrutinizer-ci.com/g/symfony-cmf/seo-bundle/?branch=dev-master diff --git a/build/xdebug-filter.php b/build/xdebug-filter.php new file mode 100644 index 00000000..346a4b7f --- /dev/null +++ b/build/xdebug-filter.php @@ -0,0 +1,24 @@ + 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, + 'php_unit_strict' => 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/phpunit.xml.dist b/phpunit.xml.dist index f1716d6c..2f383d3c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,32 +1,40 @@ + + + colors="true" + bootstrap="vendor/symfony-cmf/testing/bootstrap/bootstrap.php" +> + + - - + + ./tests/Unit - + - ./tests/WebTest - ./tests/Functional/Doctrine/Phpcr + ./tests/Functional + ./tests/Functional/Doctrine/Orm - + ./tests/Functional/Doctrine/Orm - + + + + + + src/ + + Resources/ + + + + + - - - . - - Resources/ - tests - vendor/ - - - + + diff --git a/src/AlternateLocaleProviderInterface.php b/src/AlternateLocaleProviderInterface.php index 7bbe983f..0bb3e298 100644 --- a/src/AlternateLocaleProviderInterface.php +++ b/src/AlternateLocaleProviderInterface.php @@ -1,9 +1,11 @@ dir = $baseDir.DIRECTORY_SEPARATOR.rtrim($dir, '\\/'); + $this->dir = $baseDir.\DIRECTORY_SEPARATOR.rtrim($dir, '\\/'); $this->umask = $umask; @@ -74,32 +76,6 @@ public function putExtractorsInCache($class, array $extractors) $this->renameFile($tmpFile, $path); } - /** - * Renames a file with fallback for windows. - * - * @param string $source - * @param string $target - * - * @throws \RuntimeException When the renaming can't be completed succesfully - * - * @author Johannes M. Schmitt - */ - private function renameFile($source, $target) - { - if (false === @rename($source, $target)) { - if (defined('PHP_WINDOWS_VERSION_BUILD')) { - if (false === copy($source, $target)) { - throw new \RuntimeException(sprintf('(WIN) Could not write new cache file to %s.', $target)); - } - if (false === unlink($source)) { - throw new \RuntimeException(sprintf('(WIN) Could not delete temp cache file to %s.', $source)); - } - } else { - throw new \RuntimeException(sprintf('Could not write new cache file to %s.', $target)); - } - } - } - /** * {@inheritdoc} */ @@ -128,4 +104,30 @@ public function clear($cacheDir) $filesystem->remove($this->dir); } } + + /** + * Renames a file with fallback for windows. + * + * @param string $source + * @param string $target + * + * @throws \RuntimeException When the renaming can't be completed succesfully + * + * @author Johannes M. Schmitt + */ + private function renameFile($source, $target) + { + if (false === @rename($source, $target)) { + if (\defined('PHP_WINDOWS_VERSION_BUILD')) { + if (false === copy($source, $target)) { + throw new \RuntimeException(sprintf('(WIN) Could not write new cache file to %s.', $target)); + } + if (false === unlink($source)) { + throw new \RuntimeException(sprintf('(WIN) Could not delete temp cache file to %s.', $source)); + } + } else { + throw new \RuntimeException(sprintf('Could not write new cache file to %s.', $target)); + } + } + } } diff --git a/src/CmfSeoBundle.php b/src/CmfSeoBundle.php index 3a00b9f4..5eebc1f0 100644 --- a/src/CmfSeoBundle.php +++ b/src/CmfSeoBundle.php @@ -1,9 +1,11 @@ configurations[$sitemap]['templates']; $supportedFormats = array_merge(['json'], array_keys($templates)); - if (!in_array($_format, $supportedFormats)) { + if (!\in_array($_format, $supportedFormats, true)) { $text = sprintf( 'Unknown format %s, use one of %s.', $_format, diff --git a/src/Controller/SuggestionProviderController.php b/src/Controller/SuggestionProviderController.php index 1014a739..64c7cd25 100644 --- a/src/Controller/SuggestionProviderController.php +++ b/src/Controller/SuggestionProviderController.php @@ -1,9 +1,11 @@ loadErrorHandling($errorConfig, $container); if ($this->isConfigEnabled($container, $config['sitemap'])) { @@ -116,7 +118,7 @@ public function loadSeoParameters(array $config, ContainerBuilder $container) $params = ['translation_domain', 'title', 'description', 'original_route_pattern']; foreach ($params as $param) { - $value = isset($config[$param]) ? $config[$param] : null; + $value = $config[$param] ?? null; $container->setParameter('cmf_seo.'.$param, $value); } } @@ -218,8 +220,8 @@ private function loadErrorHandling($config, ContainerBuilder $container) } } - $templates = isset($config['templates']) ? $config['templates'] : []; - $exclusionRules = isset($config['exclusion_rules']) ? $config['exclusion_rules'] : []; + $templates = $config['templates'] ?? []; + $exclusionRules = $config['exclusion_rules'] ?? []; $container->setParameter('cmf_seo.error.templates', $templates); $exclusionMatcherDefinition = $container->getDefinition('cmf_seo.error.exclusion_matcher'); @@ -305,7 +307,7 @@ private function loadSitemapHandling($config, XmlFileLoader $loader, ContainerBu } } foreach ($helperStatus as $helper => $map) { - $status = count($configuration[$helper]) ? $configuration[$helper] : $config['defaults'][$helper]; + $status = \count($configuration[$helper]) ? $configuration[$helper] : $config['defaults'][$helper]; foreach ($status as $s) { if ('_all' === $s) { @@ -344,7 +346,7 @@ private function handleSitemapHelper($helperStatus, ContainerBuilder $container) { foreach ($helperStatus as $type => $status) { foreach ($status as $id => $sitemaps) { - if (count($sitemaps)) { + if (\count($sitemaps)) { $definition = $container->getDefinition($id); $tags = $definition->getTag($this->sitemapHelperMap[$type]); $tag = reset($tags); @@ -380,10 +382,10 @@ private function loadFormConfiguration($config, ContainerBuilder $container, $st $genericMetadata = false; if ($config['options']['generic_metadata']) { $bundles = $container->getParameter('kernel.bundles'); - if (true === $config['options']['generic_metadata'] && !array_key_exists('BurgovKeyValueFormBundle', $bundles)) { + if (true === $config['options']['generic_metadata'] && !\array_key_exists('BurgovKeyValueFormBundle', $bundles)) { throw new InvalidConfigurationException('To edit generic fields for the HTML header, you need the burgov/key-value-form-bundle in your project.'); } - $genericMetadata = array_key_exists('BurgovKeyValueFormBundle', $bundles); + $genericMetadata = \array_key_exists('BurgovKeyValueFormBundle', $bundles); } $container->setParameter('cmf_seo.form.options', [ diff --git a/src/DependencyInjection/Compiler/RegisterExtractorsPass.php b/src/DependencyInjection/Compiler/RegisterExtractorsPass.php index e1551d33..69f17eef 100644 --- a/src/DependencyInjection/Compiler/RegisterExtractorsPass.php +++ b/src/DependencyInjection/Compiler/RegisterExtractorsPass.php @@ -1,9 +1,11 @@ root('cmf_seo'); + } else { + $rootNode = $treeBuilder->getRootNode(); + } - $nodeBuilder = $treeBuilder->root('cmf_seo') + $rootNode ->addDefaultsIfNotSet() ->beforeNormalization() ->ifTrue(function ($config) { return isset($config['sitemap']) && (!isset($config['sitemap']['configurations']) - || 0 === count($config['sitemap']['configurations']) + || 0 === \count($config['sitemap']['configurations']) ) && !isset($config['sitemap']['configuration']) // xml configuration ; @@ -51,7 +58,7 @@ public function getConfigTreeBuilder() 'sitemap' => [], ], ]; - } elseif (is_array($config['sitemap'])) { + } elseif (\is_array($config['sitemap'])) { $config['sitemap']['configurations'] = ['sitemap' => []]; } @@ -81,16 +88,15 @@ public function getConfigTreeBuilder() ->scalarNode('title')->end() ->scalarNode('description')->end() ->scalarNode('original_route_pattern')->defaultValue(SeoPresentation::ORIGINAL_URL_CANONICAL)->end() + ->end() ; - $this->addPersistenceSection($nodeBuilder); - $this->addAlternateLocaleSection($nodeBuilder); - $this->addErrorHandlerSection($nodeBuilder); - $this->addSitemapSection($nodeBuilder); - $this->addContentListenerSection($nodeBuilder); - $this->addFormSection($nodeBuilder); - - $nodeBuilder->end(); + $this->addPersistenceSection($rootNode); + $this->addAlternateLocaleSection($rootNode); + $this->addErrorHandlerSection($rootNode); + $this->addSitemapSection($rootNode); + $this->addContentListenerSection($rootNode); + $this->addFormSection($rootNode); return $treeBuilder; } @@ -98,28 +104,30 @@ public function getConfigTreeBuilder() /** * Attach the persistence node to the tree. * - * @param NodeBuilder $treeBuilder + * @param ArrayNodeDefinition $root */ - private function addPersistenceSection(NodeBuilder $treeBuilder) + private function addPersistenceSection(ArrayNodeDefinition $root) { - $treeBuilder - ->arrayNode('persistence') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('phpcr') - ->addDefaultsIfNotSet() - ->canBeEnabled() - ->children() - ->scalarNode('manager_name')->defaultNull()->end() - ->scalarNode('content_basepath')->defaultValue('/cms/content')->end() + $root + ->children() + ->arrayNode('persistence') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('phpcr') + ->addDefaultsIfNotSet() + ->canBeEnabled() + ->children() + ->scalarNode('manager_name')->defaultNull()->end() + ->scalarNode('content_basepath')->defaultValue('/cms/content')->end() + ->end() ->end() - ->end() - ->arrayNode('orm') - ->addDefaultsIfNotSet() - ->canBeEnabled() - ->children() - ->scalarNode('manager_name')->defaultNull()->end() + ->arrayNode('orm') + ->addDefaultsIfNotSet() + ->canBeEnabled() + ->children() + ->scalarNode('manager_name')->defaultNull()->end() + ->end() ->end() ->end() ->end() @@ -130,16 +138,18 @@ private function addPersistenceSection(NodeBuilder $treeBuilder) /** * Attach the alternate locale node to the tree. * - * @param NodeBuilder $nodeBuilder + * @param ArrayNodeDefinition $root */ - private function addAlternateLocaleSection(NodeBuilder $nodeBuilder) + private function addAlternateLocaleSection(ArrayNodeDefinition $root) { - $nodeBuilder - ->arrayNode('alternate_locale') - ->addDefaultsIfNotSet() - ->canBeEnabled() - ->children() - ->scalarNode('provider_id')->defaultNull()->end() + $root + ->children() + ->arrayNode('alternate_locale') + ->addDefaultsIfNotSet() + ->canBeEnabled() + ->children() + ->scalarNode('provider_id')->defaultNull()->end() + ->end() ->end() ->end() ; @@ -148,31 +158,33 @@ private function addAlternateLocaleSection(NodeBuilder $nodeBuilder) /** * Attach the error node to the tree. * - * @param NodeBuilder $nodeBuilder + * @param ArrayNodeDefinition $root */ - private function addErrorHandlerSection(NodeBuilder $nodeBuilder) + private function addErrorHandlerSection(ArrayNodeDefinition $root) { - $nodeBuilder - ->arrayNode('error') - ->fixXmlConfig('template') - ->fixXmlConfig('exclusion_rule') - ->children() - ->booleanNode('enable_parent_provider')->defaultFalse()->end() - ->booleanNode('enable_sibling_provider')->defaultFalse()->end() - ->arrayNode('templates') - ->useAttributeAsKey('format') - ->requiresAtLeastOneElement() - ->defaultValue(['html' => 'CmfSeoBundle:Exception:error.html.twig']) - ->prototype('scalar')->end() - ->end() - ->arrayNode('exclusion_rules') - ->info('Rules to exclude error handling from specific matches.') - ->prototype('array') - ->children() - ->scalarNode('path')->defaultNull()->info('Path to exclude')->end() - ->scalarNode('host')->defaultNull()->info('Host to exclude')->end() - ->scalarNode('methods')->defaultNull()->info('Methods to exclude')->end() - ->scalarNode('ips')->defaultNull()->info('Ips to exclude')->end() + $root + ->children() + ->arrayNode('error') + ->fixXmlConfig('template') + ->fixXmlConfig('exclusion_rule') + ->children() + ->booleanNode('enable_parent_provider')->defaultFalse()->end() + ->booleanNode('enable_sibling_provider')->defaultFalse()->end() + ->arrayNode('templates') + ->useAttributeAsKey('format') + ->requiresAtLeastOneElement() + ->defaultValue(['html' => 'CmfSeoBundle:Exception:error.html.twig']) + ->prototype('scalar')->end() + ->end() + ->arrayNode('exclusion_rules') + ->info('Rules to exclude error handling from specific matches.') + ->prototype('array') + ->children() + ->scalarNode('path')->defaultNull()->info('Path to exclude')->end() + ->scalarNode('host')->defaultNull()->info('Host to exclude')->end() + ->scalarNode('methods')->defaultNull()->info('Methods to exclude')->end() + ->scalarNode('ips')->defaultNull()->info('Ips to exclude')->end() + ->end() ->end() ->end() ->end() @@ -185,52 +197,54 @@ private function addErrorHandlerSection(NodeBuilder $nodeBuilder) /** * Attach the sitemap node to the tree. * - * @param NodeBuilder $nodeBuilder + * @param ArrayNodeDefinition $root */ - private function addSitemapSection(NodeBuilder $nodeBuilder) + private function addSitemapSection(ArrayNodeDefinition $root) { - $nodeBuilder - ->arrayNode('sitemap') - ->fixXmlConfig('configuration') - ->addDefaultsIfNotSet() - ->canBeEnabled() - ->children() - ->arrayNode('defaults') - ->fixXmlConfig('template') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('default_change_frequency')->defaultValue('always')->end() - ->arrayNode('templates') - ->useAttributeAsKey('format') - ->requiresAtLeastOneElement() - ->defaultValue([ - 'html' => 'CmfSeoBundle:Sitemap:index.html.twig', - 'xml' => 'CmfSeoBundle:Sitemap:index.xml.twig', - ]) - ->prototype('scalar')->end() - ->end() - ->append($this->getSitemapHelperNode('loaders', ['_all'])) - ->append($this->getSitemapHelperNode('guessers', ['_all'])) - ->append($this->getSitemapHelperNode('voters', ['_all'])) - ->end() - ->end() - ->arrayNode('configurations') - ->useAttributeAsKey('name') - ->prototype('array') + $root + ->children() + ->arrayNode('sitemap') + ->fixXmlConfig('configuration') + ->addDefaultsIfNotSet() + ->canBeEnabled() + ->children() + ->arrayNode('defaults') ->fixXmlConfig('template') - ->fixXmlConfig('loader') - ->fixXmlConfig('guesser') - ->fixXmlConfig('voter') + ->addDefaultsIfNotSet() ->children() - ->scalarNode('default_change_frequency')->defaultNull()->end() + ->scalarNode('default_change_frequency')->defaultValue('always')->end() ->arrayNode('templates') ->useAttributeAsKey('format') ->requiresAtLeastOneElement() + ->defaultValue([ + 'html' => 'CmfSeoBundle:Sitemap:index.html.twig', + 'xml' => 'CmfSeoBundle:Sitemap:index.xml.twig', + ]) ->prototype('scalar')->end() ->end() - ->append($this->getSitemapHelperNode('loaders', [])) - ->append($this->getSitemapHelperNode('guessers', [])) - ->append($this->getSitemapHelperNode('voters', [])) + ->append($this->getSitemapHelperNode('loaders', ['_all'])) + ->append($this->getSitemapHelperNode('guessers', ['_all'])) + ->append($this->getSitemapHelperNode('voters', ['_all'])) + ->end() + ->end() + ->arrayNode('configurations') + ->useAttributeAsKey('name') + ->prototype('array') + ->fixXmlConfig('template') + ->fixXmlConfig('loader') + ->fixXmlConfig('guesser') + ->fixXmlConfig('voter') + ->children() + ->scalarNode('default_change_frequency')->defaultNull()->end() + ->arrayNode('templates') + ->useAttributeAsKey('format') + ->requiresAtLeastOneElement() + ->prototype('scalar')->end() + ->end() + ->append($this->getSitemapHelperNode('loaders', [])) + ->append($this->getSitemapHelperNode('guessers', [])) + ->append($this->getSitemapHelperNode('voters', [])) + ->end() ->end() ->end() ->end() @@ -239,13 +253,19 @@ private function addSitemapSection(NodeBuilder $nodeBuilder) ; } - private function getSitemapHelperNode($type, $default) + /** + * @param string $type + * @param string $default + * + * @return ArrayNodeDefinition + */ + private function getSitemapHelperNode($type, $default): ArrayNodeDefinition { $node = new ArrayNodeDefinition($type); $node ->beforeNormalization() ->ifTrue(function ($config) { - return is_string($config); + return \is_string($config); }) ->then(function ($config) { return [$config]; @@ -262,16 +282,18 @@ private function getSitemapHelperNode($type, $default) /** * Attach the content listener node to the tree. * - * @param NodeBuilder $nodeBuilder + * @param ArrayNodeDefinition $root */ - private function addContentListenerSection(NodeBuilder $nodeBuilder) + private function addContentListenerSection(ArrayNodeDefinition $root) { - $nodeBuilder - ->arrayNode('content_listener') - ->canBeDisabled() - ->children() - ->scalarNode('content_key') - ->defaultValue(class_exists('Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter') ? DynamicRouter::CONTENT_KEY : '') + $root + ->children() + ->arrayNode('content_listener') + ->canBeDisabled() + ->children() + ->scalarNode('content_key') + ->defaultValue(class_exists('Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter') ? DynamicRouter::CONTENT_KEY : '') + ->end() ->end() ->end() ; @@ -280,28 +302,30 @@ private function addContentListenerSection(NodeBuilder $nodeBuilder) /** * Attach the form node to the tree. * - * @param NodeBuilder $nodeBuilder + * @param ArrayNodeDefinition $root */ - private function addFormSection($nodeBuilder) + private function addFormSection(ArrayNodeDefinition $root) { - $nodeBuilder - ->arrayNode('form') - ->addDefaultsIfNotSet() - ->fixXmlConfig('option') - ->children() - ->arrayNode('data_class') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('seo_metadata')->defaultNull()->end() + $root + ->children() + ->arrayNode('form') + ->addDefaultsIfNotSet() + ->fixXmlConfig('option') + ->children() + ->arrayNode('data_class') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('seo_metadata')->defaultNull()->end() + ->end() ->end() - ->end() - ->arrayNode('options') - ->addDefaultsIfNotSet() - ->children() - ->enumNode('generic_metadata') - ->info('Whether to show fields to edit generic SEO information. Needs burgov/key-value-form-bundle.') - ->values([true, false, 'auto']) - ->defaultValue('auto') + ->arrayNode('options') + ->addDefaultsIfNotSet() + ->children() + ->enumNode('generic_metadata') + ->info('Whether to show fields to edit generic SEO information. Needs burgov/key-value-form-bundle.') + ->values([true, false, 'auto']) + ->defaultValue('auto') + ->end() ->end() ->end() ->end() diff --git a/src/Doctrine/Phpcr/AlternateLocaleProvider.php b/src/Doctrine/Phpcr/AlternateLocaleProvider.php index 84d793da..abd12a31 100644 --- a/src/Doctrine/Phpcr/AlternateLocaleProvider.php +++ b/src/Doctrine/Phpcr/AlternateLocaleProvider.php @@ -1,9 +1,11 @@ getDocumentManagerForClass(get_class($content)); + $documentManager = $this->getDocumentManagerForClass(\get_class($content)); if (null === $documentManager) { return $alternateLocaleCollection; } @@ -111,7 +113,7 @@ public function createForContents(array $contents) * * @param $class * - * @return DocumentManager|null|object + * @return DocumentManager|object|null */ private function getDocumentManagerForClass($class) { diff --git a/src/Doctrine/Phpcr/BaseSuggestionProvider.php b/src/Doctrine/Phpcr/BaseSuggestionProvider.php index 6e575a2b..ce8e454c 100644 --- a/src/Doctrine/Phpcr/BaseSuggestionProvider.php +++ b/src/Doctrine/Phpcr/BaseSuggestionProvider.php @@ -1,9 +1,11 @@ findMany(null, $parentPaths); - if (0 === count($parentRoutes)) { + if (0 === \count($parentRoutes)) { return; } diff --git a/src/Doctrine/Phpcr/ParentSuggestionProvider.php b/src/Doctrine/Phpcr/ParentSuggestionProvider.php index 9463d1d6..9d82f8e2 100644 --- a/src/Doctrine/Phpcr/ParentSuggestionProvider.php +++ b/src/Doctrine/Phpcr/ParentSuggestionProvider.php @@ -1,9 +1,11 @@ alternateLocaleProvider = $alternateLocaleProvider; + } + protected function canBeRedirected(Request $request, RedirectResponse $response) { $targetRequest = Request::create($response->getTargetUrl()); @@ -86,12 +96,4 @@ protected function canBeRedirected(Request $request, RedirectResponse $response) return $targetPath !== $currentPath; } - - /** - * @param AlternateLocaleProviderInterface $alternateLocaleProvider - */ - public function setAlternateLocaleProvider($alternateLocaleProvider) - { - $this->alternateLocaleProvider = $alternateLocaleProvider; - } } diff --git a/src/EventListener/LanguageListener.php b/src/EventListener/LanguageListener.php index 046a914f..4eebe585 100644 --- a/src/EventListener/LanguageListener.php +++ b/src/EventListener/LanguageListener.php @@ -1,9 +1,11 @@ getSeoExtras(); foreach ($contentExtras as $type => $extras) { - if (!array_key_exists($type, $allowedTypesMethodMapping)) { + if (!\array_key_exists($type, $allowedTypesMethodMapping)) { throw new InvalidArgumentException( printf( 'Extras type %s not in the list of allowed ones %s.', diff --git a/src/Extractor/ExtrasReadInterface.php b/src/Extractor/ExtrasReadInterface.php index 5492b1d6..6fdaac94 100644 --- a/src/Extractor/ExtrasReadInterface.php +++ b/src/Extractor/ExtrasReadInterface.php @@ -1,9 +1,11 @@ getSeoKeywords(); - if (is_array($keywords)) { + if (\is_array($keywords)) { $keywords = implode(', ', $keywords); } diff --git a/src/Extractor/KeywordsReadInterface.php b/src/Extractor/KeywordsReadInterface.php index ec070822..f7914cc0 100644 --- a/src/Extractor/KeywordsReadInterface.php +++ b/src/Extractor/KeywordsReadInterface.php @@ -1,9 +1,11 @@ extraProperties)) { + if (\array_key_exists($key, $this->extraProperties)) { unset($this->extraProperties[$key]); } } @@ -256,7 +258,7 @@ public function addExtraName($key, $value) */ public function removeExtraName($key) { - if (array_key_exists($key, $this->extraNames)) { + if (\array_key_exists($key, $this->extraNames)) { unset($this->extraNames[$key]); } } @@ -292,7 +294,7 @@ public function addExtraHttp($key, $value) */ public function removeExtraHttp($key) { - if (array_key_exists($key, $this->extraHttp)) { + if (\array_key_exists($key, $this->extraHttp)) { unset($this->extraHttp[$key]); } } @@ -302,13 +304,13 @@ public function removeExtraHttp($key) * * @param array|KeyValueContainer|\Traversable $data something that can be converted to an array * - * @return array Native array representation of $data - * * @throws InvalidArgumentException if $data can not be converted to an array + * + * @return array Native array representation of $data */ private function toArray($data) { - if (is_array($data)) { + if (\is_array($data)) { return $data; } @@ -322,6 +324,6 @@ private function toArray($data) throw new InvalidArgumentException( sprintf('Expected array, Traversable or KeyValueContainer, got "%s"', - is_object($data) ? get_class($data) : gettype($data))); + \is_object($data) ? \get_class($data) : \gettype($data))); } } diff --git a/src/Model/SeoMetadataInterface.php b/src/Model/SeoMetadataInterface.php index ce0a1d51..4d087597 100644 --- a/src/Model/SeoMetadataInterface.php +++ b/src/Model/SeoMetadataInterface.php @@ -1,9 +1,11 @@ allowedChangeFrequencies)) { + if (!\in_array($changeFrequency, $this->allowedChangeFrequencies, true)) { throw new InvalidArgumentException( sprintf('Invalid change frequency "%s", use one of %s.', $changeFrequency, implode(', ', $this->allowedChangeFrequencies)) ); diff --git a/src/Resources/meta/LICENSE b/src/Resources/meta/LICENSE index bb288424..4f97a0a1 100644 --- a/src/Resources/meta/LICENSE +++ b/src/Resources/meta/LICENSE @@ -2,7 +2,7 @@ Symfony CMF Seo 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/SeoAwareInterface.php b/src/SeoAwareInterface.php index 54f11305..d9a4f699 100644 --- a/src/SeoAwareInterface.php +++ b/src/SeoAwareInterface.php @@ -1,9 +1,11 @@ cache = $cache; } - /** - * @param RedirectResponse $redirect - */ - private function setRedirectResponse(RedirectResponse $redirect) - { - $this->redirectResponse = $redirect; - } - /** * {@inheritdoc} */ @@ -156,7 +150,7 @@ public function getSeoMetadata($content) throw new InvalidArgumentException( sprintf( 'getSeoMetadata must return either an instance of SeoMetadataInterface or null, "%s" given', - is_object($contentSeoMetadata) ? get_class($contentSeoMetadata) : gettype($contentSeoMetadata) + \is_object($contentSeoMetadata) ? \get_class($contentSeoMetadata) : \gettype($contentSeoMetadata) ) ); } @@ -166,11 +160,11 @@ public function getSeoMetadata($content) $cachingAvailable = (bool) $this->cache; if ($cachingAvailable) { - $extractors = $this->cache->loadExtractorsFromCache(get_class($content)); + $extractors = $this->cache->loadExtractorsFromCache(\get_class($content)); if (null === $extractors || !$extractors->isFresh()) { $extractors = $this->getExtractorsForContent($content); - $this->cache->putExtractorsInCache(get_class($content), $extractors); + $this->cache->putExtractorsInCache(\get_class($content), $extractors); } } else { $extractors = $this->getExtractorsForContent($content); @@ -183,28 +177,6 @@ public function getSeoMetadata($content) return $seoMetadata; } - /** - * Returns the extractors for content. - * - * @param object $content - * - * @return ExtractorInterface[] - */ - private function getExtractorsForContent($content) - { - $extractors = []; - ksort($this->extractors); - foreach ($this->extractors as $priority) { - $supportedExtractors = array_filter($priority, function (ExtractorInterface $extractor) use ($content) { - return $extractor->supports($content); - }); - - $extractors = array_merge($extractors, $supportedExtractors); - } - - return $extractors; - } - /** * {@inheritdoc} */ @@ -284,6 +256,49 @@ public function updateSeoPage($content) } } + /** + * {inheritDoc}. + */ + public function updateAlternateLocales(AlternateLocaleCollection $collection) + { + foreach ($collection as $alternateLocale) { + $this->sonataPage->addLangAlternate( + $alternateLocale->href, + $alternateLocale->hrefLocale + ); + } + } + + /** + * @param RedirectResponse $redirect + */ + private function setRedirectResponse(RedirectResponse $redirect) + { + $this->redirectResponse = $redirect; + } + + /** + * Returns the extractors for content. + * + * @param object $content + * + * @return ExtractorInterface[] + */ + private function getExtractorsForContent($content) + { + $extractors = []; + ksort($this->extractors); + foreach ($this->extractors as $priority) { + $supportedExtractors = array_filter($priority, function (ExtractorInterface $extractor) use ($content) { + return $extractor->supports($content); + }); + + $extractors = array_merge($extractors, $supportedExtractors); + } + + return $extractors; + } + /** * Creates a concatenated list of keywords based on sonatas default * values. @@ -295,9 +310,8 @@ public function updateSeoPage($content) private function createKeywords($contentKeywords) { $metas = $this->sonataPage->getMetas(); - $sonataKeywords = isset($metas['name']['keywords'][0]) - ? $metas['name']['keywords'][0] - : ''; + $sonataKeywords = $metas['name']['keywords'][0] + ?? ''; return ('' !== $sonataKeywords ? $sonataKeywords.', ' : '').$contentKeywords; } @@ -323,17 +337,4 @@ private function copyMetadata(SeoMetadataInterface $contentSeoMetadata) ->setExtraHttp($contentSeoMetadata->getExtraHttp() ?: []) ; } - - /** - * {inheritDoc}. - */ - public function updateAlternateLocales(AlternateLocaleCollection $collection) - { - foreach ($collection as $alternateLocale) { - $this->sonataPage->addLangAlternate( - $alternateLocale->href, - $alternateLocale->hrefLocale - ); - } - } } diff --git a/src/SeoPresentationInterface.php b/src/SeoPresentationInterface.php index b2b12d32..a05acb5a 100644 --- a/src/SeoPresentationInterface.php +++ b/src/SeoPresentationInterface.php @@ -1,9 +1,11 @@ managerRegistry->getManagerForClass(ClassUtils::getRealClass(get_class($object))); + $manager = $this->managerRegistry->getManagerForClass(ClassUtils::getRealClass(\get_class($object))); if (!$manager instanceof DocumentManager) { return; } diff --git a/src/Sitemap/GuesserChain.php b/src/Sitemap/GuesserChain.php index bd870178..3f74accc 100644 --- a/src/Sitemap/GuesserChain.php +++ b/src/Sitemap/GuesserChain.php @@ -1,9 +1,11 @@ managerRegistry->getManagerForClass($className); if (!$manager instanceof DocumentManager) { return; @@ -63,7 +65,7 @@ public function guessValues(UrlInformation $urlInformation, $object, $sitemap) $metadata = $manager->getClassMetadata($className); $mixins = $metadata->getMixins(); - if (!in_array('mix:lastModified', $mixins)) { + if (!\in_array('mix:lastModified', $mixins, true)) { return; } @@ -83,7 +85,5 @@ private function getFieldName(ClassMetadata $metadata) return $fieldName; } } - - return; } } diff --git a/src/Sitemap/LoaderChain.php b/src/Sitemap/LoaderChain.php index 8b4153d3..17ce075f 100644 --- a/src/Sitemap/LoaderChain.php +++ b/src/Sitemap/LoaderChain.php @@ -1,9 +1,11 @@ getDbManager('ORM')->getOm()))->purge(); } - protected function getKernelConfiguration() - { - return [ - 'environment' => 'orm', - ]; - } - - protected function getEm() - { - return $this->db('ORM')->getOm(); - } - public function testSeoMetadata() { $content = new SeoAwareOrmContent(); @@ -69,4 +59,16 @@ public function testSeoMetadata() $persistedSeoMetadata = $content->getSeoMetadata(); $this->assertEquals($seoMetadata, $persistedSeoMetadata); } + + protected function getKernelConfiguration() + { + return [ + 'environment' => 'orm', + ]; + } + + protected function getEm() + { + return $this->db('ORM')->getOm(); + } } diff --git a/tests/Functional/Doctrine/Phpcr/SeoMetadataTest.php b/tests/Functional/Doctrine/Phpcr/SeoMetadataTest.php index cb69aee8..34122ccc 100644 --- a/tests/Functional/Doctrine/Phpcr/SeoMetadataTest.php +++ b/tests/Functional/Doctrine/Phpcr/SeoMetadataTest.php @@ -1,9 +1,11 @@ assertEquals($seoMetadata->getExtraHttp(), $persistedSeoMetadata->getExtraHttp()); } - /** - * @expectedException \Doctrine\ODM\PHPCR\Exception\OutOfBoundsException - * @expectedExceptionMessage It cannot have children - */ public function testAddSeoMetadataChild() { + $this->expectException(\Doctrine\ODM\PHPCR\Exception\OutOfBoundsException::class); + $this->expectExceptionMessage('It cannot have children'); + $seoMetadata = new SeoMetadata(); $seoMetadata->setName('seo-metadata'); $seoMetadata->setParentDocument($this->dm->find(null, '/test')); diff --git a/tests/Functional/Doctrine/Phpcr/SitemapDocumentProviderTest.php b/tests/Functional/Doctrine/Phpcr/SitemapDocumentProviderTest.php index 3c6e32e1..29dfb61a 100644 --- a/tests/Functional/Doctrine/Phpcr/SitemapDocumentProviderTest.php +++ b/tests/Functional/Doctrine/Phpcr/SitemapDocumentProviderTest.php @@ -1,9 +1,11 @@ */ -class FileCacheTest extends \PHPUnit_Framework_TestCase +class FileCacheTest extends TestCase { public function testThrowingExceptionForUnknownBaseDir() { @@ -41,7 +44,7 @@ public function testDirectoryCreation() new FileCache($baseDir, $dir); $expectedDirectory = $baseDir.'/'.$dir; - $this->assertTrue(is_dir($expectedDirectory)); + $this->assertDirectoryExists($expectedDirectory); rmdir($expectedDirectory); rmdir($baseDir); diff --git a/tests/Unit/Controller/SitemapControllerTest.php b/tests/Unit/Controller/SitemapControllerTest.php index 3356892f..67629b90 100644 --- a/tests/Unit/Controller/SitemapControllerTest.php +++ b/tests/Unit/Controller/SitemapControllerTest.php @@ -1,9 +1,11 @@ */ -class SitemapControllerTest extends \PHPUnit_Framework_TestCase +class SitemapControllerTest extends TestCase { /** * @var EngineInterface diff --git a/tests/Unit/DependencyInjection/CmfSeoExtensionTest.php b/tests/Unit/DependencyInjection/CmfSeoExtensionTest.php index a80dd9c8..19439179 100644 --- a/tests/Unit/DependencyInjection/CmfSeoExtensionTest.php +++ b/tests/Unit/DependencyInjection/CmfSeoExtensionTest.php @@ -1,9 +1,11 @@ container->setParameter( @@ -225,25 +217,6 @@ public function testErrorHandlingPHPCR() $this->assertMatcherCreated($attributes); } - /** - * @param array $arguments - */ - private function assertMatcherCreated(array $arguments) - { - $count = 0; - foreach ($this->container->getDefinitions() as $id => $definition) { - if (($definition instanceof DefinitionDecorator || $definition instanceof ChildDefinition) - && 'cmf_seo.error.request_matcher' === $definition->getParent() - ) { - ++$count; - $this->assertNotNull($definition); - $this->assertEquals($arguments[$count - 1], $definition->getArguments()); - } - } - - $this->assertEquals(2, $count); - } - public function testSitemapConfiguration() { $this->container->setParameter( @@ -467,4 +440,33 @@ public function testDisableSeoContentListener() 'cmf_seo.event_listener.seo_content' ); } + + /** + * {@inheritdoc} + */ + protected function getContainerExtensions() + { + return [ + new CmfSeoExtension(), + ]; + } + + /** + * @param array $arguments + */ + private function assertMatcherCreated(array $arguments) + { + $count = 0; + foreach ($this->container->getDefinitions() as $id => $definition) { + if (($definition instanceof DefinitionDecorator || $definition instanceof ChildDefinition) + && 'cmf_seo.error.request_matcher' === $definition->getParent() + ) { + ++$count; + $this->assertNotNull($definition); + $this->assertEquals($arguments[$count - 1], $definition->getArguments()); + } + } + + $this->assertEquals(2, $count); + } } diff --git a/tests/Unit/DependencyInjection/Compiler/RegisterExtractorsPassTest.php b/tests/Unit/DependencyInjection/Compiler/RegisterExtractorsPassTest.php index 59dcfe59..7830b296 100644 --- a/tests/Unit/DependencyInjection/Compiler/RegisterExtractorsPassTest.php +++ b/tests/Unit/DependencyInjection/Compiler/RegisterExtractorsPassTest.php @@ -1,9 +1,11 @@ addCompilerPass(new RegisterExtractorsPass()); - } - public function testRegistersServicesWithExtractorTagAndDefaultPriority() { $nonExtractorService = new Definition(); @@ -65,4 +62,9 @@ public function testRegistersServicesWithExtractorTagAndPriority() [new Reference('extractor_service'), 1] ); } + + protected function registerCompilerPass(ContainerBuilder $container) + { + $container->addCompilerPass(new RegisterExtractorsPass()); + } } diff --git a/tests/Unit/DependencyInjection/Compiler/RegisterSuggestionProviderPassTest.php b/tests/Unit/DependencyInjection/Compiler/RegisterSuggestionProviderPassTest.php index 8bedd517..630a6eb5 100644 --- a/tests/Unit/DependencyInjection/Compiler/RegisterSuggestionProviderPassTest.php +++ b/tests/Unit/DependencyInjection/Compiler/RegisterSuggestionProviderPassTest.php @@ -1,9 +1,11 @@ addCompilerPass(new MyCompilerPass()); - */ - protected function registerCompilerPass(ContainerBuilder $container) - { - $container->addCompilerPass(new RegisterSuggestionProviderPass()); - } - public function testRegistersServicesWithMatcherTag() { $nonMatcherService = new Definition(); @@ -76,4 +67,15 @@ public function testRegistersServicesWithMatcherTagWithoutGroup() [['provider' => new Reference('matcher.without_group'), 'group' => 'default']] ); } + + /** + * Register the compiler pass under test, just like you would do inside a bundle's load() + * method:. + * + * $container->addCompilerPass(new MyCompilerPass()); + */ + protected function registerCompilerPass(ContainerBuilder $container) + { + $container->addCompilerPass(new RegisterSuggestionProviderPass()); + } } diff --git a/tests/Unit/DependencyInjection/Compiler/RegisterUrlInformationProviderPassTest.php b/tests/Unit/DependencyInjection/Compiler/RegisterUrlInformationProviderPassTest.php index ec5c8fef..03e203f6 100644 --- a/tests/Unit/DependencyInjection/Compiler/RegisterUrlInformationProviderPassTest.php +++ b/tests/Unit/DependencyInjection/Compiler/RegisterUrlInformationProviderPassTest.php @@ -1,9 +1,11 @@ addCompilerPass(new MyCompilerPass()); - */ - protected function registerCompilerPass(ContainerBuilder $container) - { - $container->addCompilerPass(new RegisterUrlInformationProviderPass()); - } - /** * @dataProvider tagProvider */ @@ -118,4 +109,15 @@ public function tagProvider() ['guesser', 'guesser_chain'], ]; } + + /** + * Register the compiler pass under test, just like you would do inside a bundle's load() + * method:. + * + * $container->addCompilerPass(new MyCompilerPass()); + */ + protected function registerCompilerPass(ContainerBuilder $container) + { + $container->addCompilerPass(new RegisterUrlInformationProviderPass()); + } } diff --git a/tests/Unit/DependencyInjection/ConfigValuesTest.php b/tests/Unit/DependencyInjection/ConfigValuesTest.php index 57d5baad..10aef671 100644 --- a/tests/Unit/DependencyInjection/ConfigValuesTest.php +++ b/tests/Unit/DependencyInjection/ConfigValuesTest.php @@ -1,9 +1,11 @@ expectException(\Symfony\Cmf\Bundle\SeoBundle\Exception\ExtractorStrategyException::class); + $configValues = new ConfigValues(); $configValues->setOriginalUrlBehaviour('nonexistent'); } diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index 9d16fcc4..a3e21646 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -1,9 +1,11 @@ assertProcessedConfigurationEquals($expectedConfiguration, $sources); } + + protected function getContainerExtension() + { + return new CmfSeoExtension(); + } + + protected function getConfiguration() + { + return new Configuration(); + } } diff --git a/tests/Unit/DependencyInjection/XmlSchemaTest.php b/tests/Unit/DependencyInjection/XmlSchemaTest.php index fae26f21..c1a0b1ec 100644 --- a/tests/Unit/DependencyInjection/XmlSchemaTest.php +++ b/tests/Unit/DependencyInjection/XmlSchemaTest.php @@ -1,9 +1,11 @@ validator), - new PreloadedExtension([ - new KeyValueType(), - new KeyValueRowType(), - new SeoMetadataType('Symfony\Cmf\Bundle\SeoBundle\Doctrine\Phpcr\SeoMetadata'), - new SeoMetadataTypeTest_OrmType('Symfony\Cmf\Bundle\SeoBundle\Model\SeoMetadata'), - ], []), - ] - ); - } - public function testDataClassCreationForPhpcr() { $this->validator->expects($this->any())->method('validate')->will($this->returnValue([])); @@ -110,6 +96,22 @@ public function testDataClassCreationForNonPhpcr() $this->assertTrue($form->isSynchronized()); $this->assertEquals($object, $form->getData()); } + + protected function getExtensions() + { + return array_merge( + parent::getExtensions(), + [ + new ValidatorExtension($this->validator), + new PreloadedExtension([ + new KeyValueType(), + new KeyValueRowType(), + new SeoMetadataType('Symfony\Cmf\Bundle\SeoBundle\Doctrine\Phpcr\SeoMetadata'), + new SeoMetadataTypeTest_OrmType('Symfony\Cmf\Bundle\SeoBundle\Model\SeoMetadata'), + ], []), + ] + ); + } } class SeoMetadataTypeTest_OrmType extends SeoMetadataType diff --git a/tests/Unit/Matcher/ExclusionMatcherTest.php b/tests/Unit/Matcher/ExclusionMatcherTest.php index d4407f66..9db33e5b 100644 --- a/tests/Unit/Matcher/ExclusionMatcherTest.php +++ b/tests/Unit/Matcher/ExclusionMatcherTest.php @@ -1,14 +1,17 @@ */ -class ExclusionMatcherTest extends PHPUnit_Framework_TestCase +class ExclusionMatcherTest extends TestCase { /** * @var RequestMatcherInterface diff --git a/tests/Unit/Model/UrlInformationTest.php b/tests/Unit/Model/UrlInformationTest.php index b14f7832..e6c2d4c8 100644 --- a/tests/Unit/Model/UrlInformationTest.php +++ b/tests/Unit/Model/UrlInformationTest.php @@ -1,9 +1,11 @@ */ -class UrlInformationTest extends \PHPUnit_Framework_Testcase +class UrlInformationTest extends TestCase { /** * @var UrlInformation @@ -28,12 +31,11 @@ public function setUp() $this->model = new UrlInformation(); } - /** - * @expectedException \Symfony\Cmf\Bundle\SeoBundle\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid change frequency "some one", use one of always, hourly, daily, weekly, monthly, yearly, never. - */ public function testSetChangeFrequencyShouldThrowExceptionForInvalidArguments() { + $this->expectException(\Symfony\Cmf\Bundle\SeoBundle\Exception\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid change frequency "some one", use one of always, hourly, daily, weekly, monthly, yearly, never.'); + $this->model->setChangeFrequency('some one'); } diff --git a/tests/Unit/SeoPresentationTest.php b/tests/Unit/SeoPresentationTest.php index 99b8cc1e..7530255b 100644 --- a/tests/Unit/SeoPresentationTest.php +++ b/tests/Unit/SeoPresentationTest.php @@ -1,9 +1,11 @@ */ -class AbstractChainTest extends \PHPUnit_Framework_Testcase +class AbstractChainTest extends TestCase { /** @var TestChain */ private $chain; diff --git a/tests/Unit/Sitemap/AlternateLocalesGuesserTest.php b/tests/Unit/Sitemap/AlternateLocalesGuesserTest.php index 9fbfe9d7..ecf05aaa 100644 --- a/tests/Unit/Sitemap/AlternateLocalesGuesserTest.php +++ b/tests/Unit/Sitemap/AlternateLocalesGuesserTest.php @@ -1,9 +1,11 @@ buildMocks(); - - $this->managerRegistry - ->expects($this->any()) - ->method('getManagerForClass') - ->with(get_class($this->object)) - ->will($this->returnValue($this->documentManager)); - $this->documentManager - ->expects($this->any()) - ->method('getNodeForDocument') - ->with($this->object) - ->willReturn($this->node); - $this->node - ->expects($this->any()) - ->method('getDepth') - ->will($this->returnValue(3)); - - return $this->guesser; - } - - /** - * @return object - */ - protected function createData() - { - return $this->object; - } - - /** - * Provide list of fields in UrlInformation covered by this guesser. - * - * @return array - */ - protected function getFields() - { - return ['depth']; - } - - /** - * Method to extract mock building. - * - * @param string $contentBasePath - */ - private function buildMocks($contentBasePath = '/cms/test') - { - $this->managerRegistry = $this->createMock(ManagerRegistry::class); - $this->documentManager = $this->createMock(DocumentManager::class); - $this->node = $this->createMock(NodeInterface::class); - $this->object = new \stdClass(); - $this->guesser = new DepthGuesser($this->managerRegistry, $contentBasePath); - } - public function testNullOnNoManager() { $this->buildMocks(); $this->managerRegistry ->expects($this->any()) ->method('getManagerForClass') - ->with(get_class($this->object)) + ->with(\get_class($this->object)) ->will($this->returnValue(null)); $urlInformation = new UrlInformation(); $this->guesser->guessValues($urlInformation, $this->object, 'default'); @@ -128,7 +71,7 @@ public function testDepthOffsetCalculation() $this->managerRegistry ->expects($this->any()) ->method('getManagerForClass') - ->with(get_class($this->object)) + ->with(\get_class($this->object)) ->will($this->returnValue($this->documentManager)); $this->documentManager ->expects($this->any()) @@ -152,7 +95,7 @@ public function testRootEdgeCase() $this->managerRegistry ->expects($this->any()) ->method('getManagerForClass') - ->with(get_class($this->object)) + ->with(\get_class($this->object)) ->will($this->returnValue($this->documentManager)); $this->documentManager ->expects($this->any()) @@ -168,4 +111,63 @@ public function testRootEdgeCase() $this->assertEquals(3, $urlInformation->getDepth()); } + + /** + * Create the guesser for this test. + * + * @return GuesserInterface + */ + protected function createGuesser() + { + $this->buildMocks(); + + $this->managerRegistry + ->expects($this->any()) + ->method('getManagerForClass') + ->with(\get_class($this->object)) + ->will($this->returnValue($this->documentManager)); + $this->documentManager + ->expects($this->any()) + ->method('getNodeForDocument') + ->with($this->object) + ->willReturn($this->node); + $this->node + ->expects($this->any()) + ->method('getDepth') + ->will($this->returnValue(3)); + + return $this->guesser; + } + + /** + * @return object + */ + protected function createData() + { + return $this->object; + } + + /** + * Provide list of fields in UrlInformation covered by this guesser. + * + * @return array + */ + protected function getFields() + { + return ['depth']; + } + + /** + * Method to extract mock building. + * + * @param string $contentBasePath + */ + private function buildMocks($contentBasePath = '/cms/test') + { + $this->managerRegistry = $this->createMock(ManagerRegistry::class); + $this->documentManager = $this->createMock(DocumentManager::class); + $this->node = $this->createMock(NodeInterface::class); + $this->object = new \stdClass(); + $this->guesser = new DepthGuesser($this->managerRegistry, $contentBasePath); + } } diff --git a/tests/Unit/Sitemap/GuesserTestCase.php b/tests/Unit/Sitemap/GuesserTestCase.php index d6b87075..39986255 100644 --- a/tests/Unit/Sitemap/GuesserTestCase.php +++ b/tests/Unit/Sitemap/GuesserTestCase.php @@ -1,9 +1,11 @@ assertEquals('2016-07-06T00:00:00+02:00', $urlInformation->getLastModification()); } + public function testGuessNoOverwrite() + { + $urlInformation = new UrlInformation(); + $urlInformation->setLastModification(new \DateTime('2016-06-06', new \DateTimeZone('Europe/Berlin'))); + + $this->guesser->guessValues($urlInformation, $this->data, 'default'); + $this->assertEquals('2016-06-06T00:00:00+02:00', $urlInformation->getLastModification()); + } + /** * Create the guesser for this test. * @@ -103,13 +114,4 @@ protected function getFields() { return ['LastModification']; } - - public function testGuessNoOverwrite() - { - $urlInformation = new UrlInformation(); - $urlInformation->setLastModification(new \DateTime('2016-06-06', new \DateTimeZone('Europe/Berlin'))); - - $this->guesser->guessValues($urlInformation, $this->data, 'default'); - $this->assertEquals('2016-06-06T00:00:00+02:00', $urlInformation->getLastModification()); - } } diff --git a/tests/Unit/Sitemap/LocationGuesserTest.php b/tests/Unit/Sitemap/LocationGuesserTest.php index 26b2c051..5444d76e 100644 --- a/tests/Unit/Sitemap/LocationGuesserTest.php +++ b/tests/Unit/Sitemap/LocationGuesserTest.php @@ -1,9 +1,11 @@ */ -class SitemapAwareDocumentVoterTest extends \PHPUnit_Framework_TestCase +class SitemapAwareDocumentVoterTest extends TestCase { /** * @var VoterInterface diff --git a/tests/Unit/Sitemap/UrlInformationProviderTest.php b/tests/Unit/Sitemap/UrlInformationProviderTest.php index 8a050fe4..0a5bc9bb 100644 --- a/tests/Unit/Sitemap/UrlInformationProviderTest.php +++ b/tests/Unit/Sitemap/UrlInformationProviderTest.php @@ -1,9 +1,11 @@ */ -class UrlInformationProviderTest extends \PHPUnit_Framework_Testcase +class UrlInformationProviderTest extends TestCase { /** * @var UrlInformationProvider diff --git a/tests/WebTest/SeoFrontendTest.php b/tests/WebTest/SeoFrontendTest.php index 8846d6e5..d3993370 100644 --- a/tests/WebTest/SeoFrontendTest.php +++ b/tests/WebTest/SeoFrontendTest.php @@ -1,9 +1,11 @@