Skip to content

Commit

Permalink
[TASK] #8 | Add ability to set fixed version via extension configuration
Browse files Browse the repository at this point in the history
* [TASK] #8 | Add ability to set fixed version via extension configuration

* [TASK] #8 | Remove line to satisfy StyleCI

* [TASK] #8 | Rename constant to avoid php foo on windows machines
  • Loading branch information
KamiYang committed Oct 5, 2018
1 parent b36babb commit 6ab2343
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
14 changes: 14 additions & 0 deletions Classes/Configuration/ExtensionConfiguration.php
Expand Up @@ -52,6 +52,11 @@ final class ExtensionConfiguration implements SingletonInterface
*/
private static $gitFormat = '';

/**
* @var string
*/
private static $staticVersion = '';

/**
* Fetch absolute version filename.
*
Expand Down Expand Up @@ -86,13 +91,22 @@ public static function getGitFormat(): string
return self::$gitFormat;
}

/**
* @return string
*/
public static function getStaticVersion(): string
{
return self::$staticVersion;
}

public function __construct()
{
self::$configuration = $this->getExtensionConfigurationFromGlobals();

self::$versionFilePath = $this->resolveVersionFilePath();
self::$mode = self::$configuration['mode'];
self::$gitFormat = self::$configuration['gitFormat'];
self::$staticVersion = self::$configuration['staticVersion'];
}

/**
Expand Down
1 change: 1 addition & 0 deletions Classes/Enumeration/ProjectVersionModeEnumeration.php
Expand Up @@ -23,4 +23,5 @@ final class ProjectVersionModeEnumeration
const FILE = '0';
const GIT = '1';
const GIT_FILE_FALLBACK = '2';
const STATIC_VERSION = '3';
}
11 changes: 11 additions & 0 deletions Classes/Service/ProjectVersionService.php
Expand Up @@ -45,6 +45,9 @@ public function getProjectVersion(): ProjectVersion
$projectVersion = GeneralUtility::makeInstance(ProjectVersion::class);

switch (ExtensionConfiguration::getMode()) {
case ProjectVersionModeEnumeration::STATIC_VERSION:
$this->setStaticVersion($projectVersion);
break;
case ProjectVersionModeEnumeration::GIT:
$this->setVersionFromGit($projectVersion);
break;
Expand Down Expand Up @@ -124,6 +127,14 @@ protected function isGitAvailable(): bool
$returnCode === 0;
}

/**
* @param \KamiYang\ProjectVersion\Service\ProjectVersion $projectVersion
*/
private function setStaticVersion(ProjectVersion $projectVersion)
{
$projectVersion->setVersion(ExtensionConfiguration::getStaticVersion());
}

/**
* Resolve version by common VERSION-file.
*
Expand Down
7 changes: 3 additions & 4 deletions README.md
Expand Up @@ -12,7 +12,7 @@ First make sure you match the requirements:

| Requirement | Version |
| --- | --- |
| TYPO3 | \>=8.7.0 \<=8.7.19 &#124;&#124; >=9.4.0 <9.5 |
| TYPO3 | \>=8.7 <9.6 |
| php | \>= 7.0 |

### Composer
Expand Down Expand Up @@ -89,15 +89,14 @@ The new configuration screen will look like this:
- [x] Upload extension to packagist.org
- [x] Upload extension to TER
- [x] Support TYPO3 v9.4
- [ ] Support TYPO3 v9 LTS
- [x] Support TYPO3 v9 LTS
- [x] Achieve overall test coverage above 95%
- [x] Configure [TravisCI](https://travis-ci.org/KamiYang/project_version)
- [x] Configure [StyleCI](https://github.styleci.io/repos/134700322)
- [x] Configure [Coveralls](https://coveralls.io/github/KamiYang/project_version)
- [ ] Automate release to TER using [Travis-CI](https://travis-ci.org/) and [helhum/ter-client](https://github.com/helhum/ter-client)
- [x] Static VERSION value via extension configuration

### Milestone for v0.6.0
- Automated release management and upload to TER.
- Ability to "hardcode" static project version via the TYPO3 backend

## Note
Expand Down
56 changes: 54 additions & 2 deletions Tests/Unit/Service/ProjectVersionServiceTest.php
Expand Up @@ -37,8 +37,10 @@ class ProjectVersionServiceTest extends UnitTestCase
private $subject;

private $extensionConfiguration = [
'versionFilePath' => 'VERSION',
'mode' => ProjectVersionModeEnumeration::FILE
'gitFormat' => GitCommandEnumeration::FORMAT_REVISION_BRANCH,
'mode' => ProjectVersionModeEnumeration::FILE,
'staticVersion' => '',
'versionFilePath' => 'VERSION'
];

/**
Expand Down Expand Up @@ -263,6 +265,56 @@ public function gitFormatDataProvider(): array
];
}

/**
* @test
*/
public function getProjectVersionShouldAlwaysSetStaticVersionIfSelected()
{
$this->extensionConfiguration['mode'] = ProjectVersionModeEnumeration::STATIC_VERSION;
$this->setUpExtensionConfiguration();

$projectVersionProphecy = $this->prophesize(ProjectVersion::class);
GeneralUtility::setSingletonInstance(ProjectVersion::class, $projectVersionProphecy->reveal());

$this->subject->getProjectVersion();

$projectVersionProphecy->setVersion('')->shouldHaveBeenCalledTimes(1);
}

/**
* @test
* @param string $staticVersion
* @dataProvider staticVersionDataProvider
*/
public function getProjectVersionShouldSetStaticVersionFromExtensionConfigurationIfSelected(string $staticVersion)
{
$this->extensionConfiguration['mode'] = ProjectVersionModeEnumeration::STATIC_VERSION;
$this->extensionConfiguration['staticVersion'] = $staticVersion;
$this->setUpExtensionConfiguration();

$projectVersionProphecy = $this->prophesize(ProjectVersion::class);
GeneralUtility::setSingletonInstance(ProjectVersion::class, $projectVersionProphecy->reveal());

$this->subject->getProjectVersion();

$projectVersionProphecy->setVersion($staticVersion)->shouldHaveBeenCalledTimes(1);
}

public function staticVersionDataProvider(): array
{
return [
'empty static version (default value)' => [
'staticVersion' => ''
],
'some value' => [
'staticVersion' => 'some value'
],
'some extreme long value' => [
'staticVersion' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos hic ipsa labore molestiae nesciunt quo repellendus similique tenetur vitae voluptatem! Dicta dolor minus nostrum ratione voluptas? Ad animi iste sunt!'
]
];
}

protected function setUp()
{
$this->systemEnvironmentBuilderFacadeProphecy = $this->prophesize(SystemEnvironmentBuilderFacade::class);
Expand Down
5 changes: 4 additions & 1 deletion ext_conf_template.txt
@@ -1,8 +1,11 @@
# cat=basic/enable; type=string; label=VERSION file path
versionFilePath = VERSION

# cat=basic/enable; type=options[VERSION File=0,GIT=1,GIT (VERSION file as fallback)=2]; label=Get project version by:
# cat=basic/enable; type=options[VERSION File=0,GIT=1,GIT (VERSION file as fallback)=2,Static Version=3]; label=Get project version by:
mode = 0

# cat=basic/enable; type=options[Revision=0,[revision] branch=1,[revision] tag=2,Branch=3,Tag=4]; label=Get project version by:
gitFormat = 1

# cat=basic/enable; type=string; label=Static version value (will only have effect if 'basic.mode' is set to 'Static Version')
staticVersion =

0 comments on commit 6ab2343

Please sign in to comment.