diff --git a/.travis.yml b/.travis.yml index 2d37a308..1d04f682 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,7 @@ before_install: - git config --global user.name "John Doe" - composer self-update - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/console:${SYMFONY_VERSION}" "symfony/yaml:${SYMFONY_VERSION}" "symfony/process:${SYMFONY_VERSION}" --no-update; fi; + - composer require "phpunit/phpunit:<6" --no-update install: composer update --prefer-source $COMPOSER_FLAGS diff --git a/composer.lock b/composer.lock index d5adcf5e..4f52a815 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "735f2e82e0e6ff545811a2b12e370700", + "hash": "deb3427f835567ee08b3b7b0ee6907d7", + "content-hash": "06c5291e8de679735a9547652ca4bbd9", "packages": [ { "name": "psr/log", @@ -51,7 +52,7 @@ "psr", "psr-3" ], - "time": "2016-10-10T12:19:37+00:00" + "time": "2016-10-10 12:19:37" }, { "name": "sensiolabs/security-checker", @@ -95,7 +96,7 @@ } ], "description": "A security checker for your composer.lock", - "time": "2016-09-23T18:09:57+00:00" + "time": "2016-09-23 18:09:57" }, { "name": "symfony/console", @@ -156,7 +157,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-11-15T23:02:12+00:00" + "time": "2016-11-15 23:02:12" }, { "name": "symfony/debug", @@ -213,7 +214,7 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2016-11-15T12:53:17+00:00" + "time": "2016-11-15 12:53:17" }, { "name": "symfony/polyfill-mbstring", @@ -272,7 +273,7 @@ "portable", "shim" ], - "time": "2016-11-14T01:06:16+00:00" + "time": "2016-11-14 01:06:16" }, { "name": "symfony/process", @@ -321,7 +322,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-09-29T14:03:54+00:00" + "time": "2016-09-29 14:03:54" }, { "name": "symfony/yaml", @@ -370,7 +371,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-11-14T16:15:57+00:00" + "time": "2016-11-14 16:15:57" }, { "name": "vierbergenlars/php-semver", @@ -422,7 +423,7 @@ "semver", "versioning" ], - "time": "2015-05-02T19:28:54+00:00" + "time": "2015-05-02 19:28:54" } ], "packages-dev": [], diff --git a/src/Liip/RMT/Config/Handler.php b/src/Liip/RMT/Config/Handler.php index 83687f6b..10f4960d 100644 --- a/src/Liip/RMT/Config/Handler.php +++ b/src/Liip/RMT/Config/Handler.php @@ -168,6 +168,10 @@ protected function getClassAndOptions($rawConfig, $sectionName) */ protected function findClass($name, $sectionName) { + if (class_exists($name)) { + return $name; + } + $file = $this->projectRoot.DIRECTORY_SEPARATOR.$name; if (strpos($file, '.php') > 0) { if (file_exists($file)) { @@ -217,8 +221,14 @@ protected function findInternalClass($name, $sectionName) 'version-persister' => 'Persister', ); $nameSpace = $namespacesByType[$classType]; - $className = str_replace(' ', '', ucwords(str_replace('-', ' ', $name))).$suffixByType[$classType]; + $classNameWithoutSuffix = str_replace(' ', '', ucwords(str_replace('-', ' ', $name))); + $classNameSuffix = $suffixByType[$classType]; + $className = $nameSpace.'\\'.$classNameWithoutSuffix; + + if (substr($classNameWithoutSuffix, -strlen($classNameSuffix)) != $classNameSuffix) { + $className .= $classNameSuffix; + } - return $nameSpace.'\\'.$className; + return $className; } } diff --git a/test/Liip/RMT/Tests/Unit/Config/ExternalClasses/CustomVersionGenerator.php b/test/Liip/RMT/Tests/Unit/Config/ExternalClasses/CustomVersionGenerator.php new file mode 100644 index 00000000..172ad27b --- /dev/null +++ b/test/Liip/RMT/Tests/Unit/Config/ExternalClasses/CustomVersionGenerator.php @@ -0,0 +1,19 @@ +<?php + +/* + * This file is part of the project RMT + * + * Copyright (c) 2013, Liip AG, http://www.liip.ch + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + + +namespace Liip\RMT\Tests\Unit\Config\ExternalClasses; + +use Liip\RMT\Version\Generator\SimpleGenerator; + +class CustomVersionGenerator extends SimpleGenerator +{ +} diff --git a/test/Liip/RMT/Tests/Unit/Config/ExternalClasses/CustomVersionPersister.php b/test/Liip/RMT/Tests/Unit/Config/ExternalClasses/CustomVersionPersister.php new file mode 100644 index 00000000..0b4d91b9 --- /dev/null +++ b/test/Liip/RMT/Tests/Unit/Config/ExternalClasses/CustomVersionPersister.php @@ -0,0 +1,19 @@ +<?php + +/* + * This file is part of the project RMT + * + * Copyright (c) 2013, Liip AG, http://www.liip.ch + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + + +namespace Liip\RMT\Tests\Unit\Config\ExternalClasses; + +use Liip\RMT\Version\Persister\VcsTagPersister; + +class CustomVersionPersister extends VcsTagPersister +{ +} diff --git a/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php b/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php index e90900d9..ef20677f 100644 --- a/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php +++ b/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php @@ -12,6 +12,8 @@ namespace Liip\RMT\Tests\Unit\Config; use Liip\RMT\Config\Handler; +use Liip\RMT\Tests\Unit\Config\ExternalClasses\CustomVersionGenerator; +use Liip\RMT\Tests\Unit\Config\ExternalClasses\CustomVersionPersister; class HandlerTest extends \PHPUnit_Framework_TestCase { @@ -225,4 +227,36 @@ public function getDataForTestingGetClassAndOptions() array('prerequisites_1', 'vcs-clean-check', 'Liip\RMT\Prerequisite\VcsCleanCheck', array()), ); } + + /** + * @dataProvider getDataForTestingGetClassForClassConfigurationInVersionGenerator + */ + public function testGetClassForClassConfigurationInVersionGenerator($configKey, $configClass, $expectedClass) + { + $configHandler = new Handler(array( + 'version-persister' => $configClass, + 'version-generator' => $configClass, + )); + + $method = new \ReflectionMethod('Liip\RMT\Config\Handler', 'getClassAndOptions'); + $method->setAccessible(true); + + $classAndOptions = $method->invokeArgs($configHandler, array($configClass, $configKey)); + + $this->assertEquals($expectedClass, $classAndOptions['class']); + } + + public function getDataForTestingGetClassForClassConfigurationInVersionGenerator() + { + return array( + // version persister + array('version-persister', 'Liip\RMT\Tests\Unit\Config\ExternalClasses\CustomVersionPersister', 'Liip\RMT\Tests\Unit\Config\ExternalClasses\CustomVersionPersister'), + array('version-persister', 'CustomVersion', 'Liip\RMT\Version\Persister\CustomVersionPersister'), + array('version-persister', 'CustomVersionPersister', 'Liip\RMT\Version\Persister\CustomVersionPersister'), + // version generator + array('version-generator', 'Liip\RMT\Tests\Unit\Config\ExternalClasses\CustomVersionGenerator', 'Liip\RMT\Tests\Unit\Config\ExternalClasses\CustomVersionGenerator'), + array('version-generator', 'CustomVersion', 'Liip\RMT\Version\Generator\CustomVersionGenerator'), + array('version-generator', 'CustomVersionGenerator', 'Liip\RMT\Version\Generator\CustomVersionGenerator'), + ); + } }