Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add class configuration functionality instead of php files #122

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 10 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/Liip/RMT/Config/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
{
}
Original file line number Diff line number Diff line change
@@ -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
{
}
34 changes: 34 additions & 0 deletions test/Liip/RMT/Tests/Unit/Config/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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'),
);
}
}