diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ea9fe6e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,68 @@ +name: Unit tests + +on: + push: + branches: [ "master" ] + pull_request: + +jobs: + test: + runs-on: ubuntu-18.04 + strategy: + matrix: + typo3_version: + - 10.4.20 + - 10.4.21 + - 10.4.22 + - 10.4.23 + - 10.4.24 + - 10.4.25 + - 10.4.26 + - 10.4.27 + - 10.4.28 + # - 11.5.0 + # - 11.5.1 + # - 11.5.2 + # - 11.5.3 + # - 11.5.4 + # - 11.5.5 + # - 11.5.6 + # - 11.5.7 + # - 11.5.8 + # - 11.5.9 + # - 11.5.10 + # - dev-master + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 7.2 + tools: composer:v1 + coverage: xdebug + + - name: Validate composer.json + run: composer validate --strict + + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.typo3_version }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies for TYPO3 version "${{ matrix.typo3_version }}" + run: composer require typo3/cms-backend:${{ matrix.typo3_version }} typo3/cms-core:${{ matrix.typo3_version }} typo3/cms-extbase:${{ matrix.typo3_version }} typo3/cms-extensionmanager:${{ matrix.typo3_version }} typo3/cms-filelist:${{ matrix.typo3_version }} typo3/cms-fluid:${{ matrix.typo3_version }} typo3/cms-frontend:${{ matrix.typo3_version }} typo3/cms-install:${{ matrix.typo3_version }} typo3/cms-recordlist:${{ matrix.typo3_version }} typo3/cms-lowlevel:${{ matrix.typo3_version }} typo3/cms-about:${{ matrix.typo3_version }} typo3/cms-belog:${{ matrix.typo3_version }} typo3/cms-beuser:${{ matrix.typo3_version }} typo3/cms-felogin:${{ matrix.typo3_version }} typo3/cms-fluid-styled-content:${{ matrix.typo3_version }} typo3/cms-form:${{ matrix.typo3_version }} typo3/cms-impexp:${{ matrix.typo3_version }} typo3/cms-info:${{ matrix.typo3_version }} typo3/cms-rte-ckeditor:${{ matrix.typo3_version }} typo3/cms-setup:${{ matrix.typo3_version }} typo3/cms-seo:${{ matrix.typo3_version }} typo3/cms-sys-note:${{ matrix.typo3_version }} typo3/cms-t3editor:${{ matrix.typo3_version }} typo3/cms-tstemplate:${{ matrix.typo3_version }} typo3/cms-viewpage:${{ matrix.typo3_version }} typo3/cms-adminpanel:${{ matrix.typo3_version }} typo3/cms-redirects:${{ matrix.typo3_version }} typo3/cms-workspaces:${{ matrix.typo3_version }} typo3/cms-reports:${{ matrix.typo3_version }} typo3/cms-scheduler:${{ matrix.typo3_version }} typo3/cms-recycler:${{ matrix.typo3_version }} typo3/cms-opendocs:${{ matrix.typo3_version }} typo3/cms-linkvalidator:${{ matrix.typo3_version }} + + - name: Unit tests + run: .Build/bin/phpunit --colors -c phpunit.xml --coverage-text diff --git a/.gitignore b/.gitignore index 752bd8e..0fcd87d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.ddev /.Build/ /.idea/ /composer.lock diff --git a/.travis.yml b/.travis.yml index d361cb9..e2b0854 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,10 @@ # .travis.yml language: php - sudo: false - php: - 7.2 - matrix: fast_finish: true - addons: apt: packages: @@ -16,12 +12,10 @@ addons: cache: directories: - $HOME/.composer/cache - install: - composer require typo3/cms-backend:${TYPO3_VERSION} typo3/cms-core:${TYPO3_VERSION} typo3/cms-extbase:${TYPO3_VERSION} typo3/cms-extensionmanager:${TYPO3_VERSION} typo3/cms-filelist:${TYPO3_VERSION} typo3/cms-fluid:${TYPO3_VERSION} typo3/cms-frontend:${TYPO3_VERSION} typo3/cms-install:${TYPO3_VERSION} typo3/cms-recordlist:${TYPO3_VERSION} typo3/cms-lowlevel:${TYPO3_VERSION} typo3/cms-about:${TYPO3_VERSION} typo3/cms-belog:${TYPO3_VERSION} typo3/cms-beuser:${TYPO3_VERSION} typo3/cms-felogin:${TYPO3_VERSION} typo3/cms-fluid-styled-content:${TYPO3_VERSION} typo3/cms-form:${TYPO3_VERSION} typo3/cms-impexp:${TYPO3_VERSION} typo3/cms-info:${TYPO3_VERSION} typo3/cms-rte-ckeditor:${TYPO3_VERSION} typo3/cms-setup:${TYPO3_VERSION} typo3/cms-seo:${TYPO3_VERSION} typo3/cms-sys-note:${TYPO3_VERSION} typo3/cms-t3editor:${TYPO3_VERSION} typo3/cms-tstemplate:${TYPO3_VERSION} typo3/cms-viewpage:${TYPO3_VERSION} typo3/cms-adminpanel:${TYPO3_VERSION} typo3/cms-redirects:${TYPO3_VERSION} typo3/cms-workspaces:${TYPO3_VERSION} typo3/cms-reports:${TYPO3_VERSION} typo3/cms-scheduler:${TYPO3_VERSION} typo3/cms-recycler:${TYPO3_VERSION} typo3/cms-opendocs:${TYPO3_VERSION} typo3/cms-linkvalidator:${TYPO3_VERSION} - - git checkout composer.json - - export TYPO3_PATH_WEB="$PWD/.Build/web" + - export TYPO3_PATH_WEB="$PWD/.Build/public" script: - > @@ -46,30 +40,48 @@ jobs: allow_failures: - env: TYPO3_VERSION=dev-master include: - - stage: test - php: 7.2 - env: TYPO3_VERSION=9.5.0 - - stage: test - php: 7.2 - env: TYPO3_VERSION=9.5.1 - - stage: test - php: 7.2 - env: TYPO3_VERSION=9.5.2 - - stage: test - php: 7.2 - env: TYPO3_VERSION=9.5.3 - - stage: test - php: 7.2 - env: TYPO3_VERSION=9.5.4 - - stage: test - php: 7.2 - env: TYPO3_VERSION=9.5.5 - - stage: test - php: 7.2 - env: TYPO3_VERSION=9.5.6 - - stage: test + - &test + stage: test php: 7.2 - env: TYPO3_VERSION=9.5.7 + env: TYPO3_VERSION=10.5.20 + - *test + env: TYPO3_VERSION=10.5.21 + - *test + env: TYPO3_VERSION=10.5.22 + - *test + env: TYPO3_VERSION=10.5.23 + - *test + env: TYPO3_VERSION=10.5.24 + - *test + env: TYPO3_VERSION=10.5.25 + - *test + env: TYPO3_VERSION=10.5.26 + - *test + env: TYPO3_VERSION=10.5.27 + - *test + env: TYPO3_VERSION=10.5.28 + - *test + env: TYPO3_VERSION=11.5.0 + - *test + env: TYPO3_VERSION=11.5.1 + - *test + env: TYPO3_VERSION=11.5.2 + - *test + env: TYPO3_VERSION=11.5.3 + - *test + env: TYPO3_VERSION=11.5.4 + - *test + env: TYPO3_VERSION=11.5.5 + - *test + env: TYPO3_VERSION=11.5.6 + - *test + env: TYPO3_VERSION=11.5.7 + - *test + env: TYPO3_VERSION=11.5.8 + - *test + env: TYPO3_VERSION=11.5.9 + - *test + env: TYPO3_VERSION=11.5.10 - stage: test php: 7.2 env: TYPO3_VERSION=dev-master diff --git a/Classes/Backend/ToolbarItems/ProjectVersionSlot.php b/Classes/Backend/ToolbarItems/ProjectVersionSlot.php deleted file mode 100644 index 4a9a6ea..0000000 --- a/Classes/Backend/ToolbarItems/ProjectVersionSlot.php +++ /dev/null @@ -1,52 +0,0 @@ -get(ProjectVersionService::class) - ->getProjectVersion(); - - $version = $projectVersion->getVersion(); - - if (StringUtility::beginsWith($version, 'LLL:')) { - $version = GeneralUtility::makeInstance(LocalizationUtilityFacade::class)->translate($version); - } - - $pObj->addSystemInformation( - $projectVersion->getTitle(), - $version, - $projectVersion->getIconIdentifier() - ); - } -} diff --git a/Classes/Configuration/ExtensionConfiguration.php b/Classes/Configuration/ExtensionConfiguration.php index be11951..cb3cccb 100644 --- a/Classes/Configuration/ExtensionConfiguration.php +++ b/Classes/Configuration/ExtensionConfiguration.php @@ -1,7 +1,6 @@ getVersionFilePath()); } - /** - * @return string - */ - public static function getVersionFilePath(): string + public function getVersionFilePath(): string { - return self::$versionFilePath; + return $this->versionFilePath; } - /** - * @return string - */ - public static function getMode(): string + public function getMode(): string { - return self::$mode; + return $this->mode; } - /** - * @return string - */ - public static function getGitFormat(): string + public function getGitFormat(): string { - return self::$gitFormat; + return $this->gitFormat; } - /** - * @return string - */ - public static function getStaticVersion(): string + public function getStaticVersion(): string { - return self::$staticVersion; + return $this->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']; + $this->configuration = $this->getExtensionConfigurationFromGlobals(); + $this->versionFilePath = $this->resolveVersionFilePath(); + $this->mode = $this->configuration['mode'] ?? ProjectVersionModeEnumeration::FILE; + $this->gitFormat = $this->configuration['gitFormat'] ?? ''; + $this->staticVersion = $this->configuration['staticVersion'] ?? ''; } - /** - * @return array - */ private function getExtensionConfigurationFromGlobals(): array { - $configuration = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['project_version']; - - if (is_string($configuration)) { - $configuration = @unserialize($configuration); - } - - return $configuration ?? []; + return $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['project_version'] ?? []; } - /** - * @return string - */ private function resolveVersionFilePath(): string { - $pathFromConfiguration = self::$configuration['versionFilePath'] ?? ''; - + $pathFromConfiguration = $this->configuration['versionFilePath'] ?? ''; if (empty($pathFromConfiguration) || $this->isDirectory($pathFromConfiguration)) { - $pathFromConfiguration .= 'VERSION'; + $pathFromConfiguration .= self::DEFAULT_VERSION_FILE; } return $pathFromConfiguration; } - /** - * @param string $pathFromConfiguration - * @return bool - */ private function isDirectory(string $pathFromConfiguration): bool { - return StringUtility::endsWith($pathFromConfiguration, '/') === true; + return StringUtility::endsWith($pathFromConfiguration, '/'); } } diff --git a/Classes/Enumeration/GitCommandEnumeration.php b/Classes/Enumeration/GitCommandEnumeration.php index a39dd1e..ebe101a 100644 --- a/Classes/Enumeration/GitCommandEnumeration.php +++ b/Classes/Enumeration/GitCommandEnumeration.php @@ -1,7 +1,6 @@ projectVersionService = $projectVersionService; + $this->languageService = $languageService; + } + + public function __invoke(SystemInformationToolbarCollectorEvent $event) + { + $projectVersion = $this->projectVersionService->getProjectVersion(); + $version = $projectVersion->getVersion(); + if (StringUtility::beginsWith($version, 'LLL:')) { + $version = $this->languageService->sL($version); + } + + $event->getToolbarItem()->addSystemInformation( + $projectVersion->getTitle(), + $version, + $projectVersion->getIconIdentifier() + ); + } +} diff --git a/Classes/Facade/CommandUtilityFacade.php b/Classes/Facade/CommandUtilityFacade.php index c293bf0..af172f4 100644 --- a/Classes/Facade/CommandUtilityFacade.php +++ b/Classes/Facade/CommandUtilityFacade.php @@ -1,7 +1,6 @@ title = $title; } @@ -66,9 +70,9 @@ public function getVersion(): string /** * @param string $version */ - public function setVersion(string $version) + public function setVersion(string $version): void { - $this->version = $version; + $this->version = trim($version); } /** @@ -82,7 +86,7 @@ public function getIconIdentifier(): string /** * @param string $iconIdentifier */ - public function setIconIdentifier(string $iconIdentifier) + public function setIconIdentifier(string $iconIdentifier): void { $this->iconIdentifier = $iconIdentifier; } diff --git a/Classes/Service/ProjectVersionService.php b/Classes/Service/ProjectVersionService.php index aff0541..5ee973d 100644 --- a/Classes/Service/ProjectVersionService.php +++ b/Classes/Service/ProjectVersionService.php @@ -1,7 +1,6 @@ commandUtilityFacade = $commandUtilityFacade; + $this->extensionConfiguration = $extensionConfiguration; + } /** * @api @@ -43,8 +56,7 @@ class ProjectVersionService implements SingletonInterface public function getProjectVersion(): ProjectVersion { $projectVersion = GeneralUtility::makeInstance(ProjectVersion::class); - - switch (ExtensionConfiguration::getMode()) { + switch ($this->extensionConfiguration->getMode()) { case ProjectVersionModeEnumeration::STATIC_VERSION: $this->setStaticVersion($projectVersion); break; @@ -53,7 +65,6 @@ public function getProjectVersion(): ProjectVersion break; case ProjectVersionModeEnumeration::GIT_FILE_FALLBACK: $this->setVersionFromGit($projectVersion); - if ($projectVersion->getVersion() === ProjectVersion::UNKNOWN_VERSION) { //if version is still unknown, try to resolve version by file $this->setVersionFromFile($projectVersion); @@ -68,19 +79,25 @@ public function getProjectVersion(): ProjectVersion } /** - * @param $revision - * @param $tag - * @param $branch - * @return string + * @internal protected so we can mock it in unit tests. + * @return bool */ - private function formatVersionBasedOnConfiguration($revision, $tag, $branch): string + protected function isGitAvailable(): bool + { + return $this->isExecEnabled() && + // check if git exists + $this->commandUtilityFacade->exec('git --version', $_, $returnCode) && + $returnCode === 0; + } + + private function formatVersion($revision, $tag, $branch): string { - switch (ExtensionConfiguration::getGitFormat()) { + switch ($this->extensionConfiguration->getGitFormat()) { case GitCommandEnumeration::FORMAT_REVISION: $format = $revision; break; case GitCommandEnumeration::FORMAT_REVISION_TAG: - $format = \sprintf('[%s] %s', $revision, $tag); + $format = sprintf('[%s] %s', $revision, $tag); break; case GitCommandEnumeration::FORMAT_BRANCH: $format = $branch; @@ -90,102 +107,57 @@ private function formatVersionBasedOnConfiguration($revision, $tag, $branch): st break; case GitCommandEnumeration::FORMAT_REVISION_BRANCH: default: - $format = \sprintf('[%s] %s', $revision, $branch); + $format = sprintf('[%s] %s', $revision, $branch); } return $format; } - /** - * SystemEnvironmentBuilderFacade injector. - * - * @param \KamiYang\ProjectVersion\Facade\SystemEnvironmentBuilderFacade $systemEnvironmentBuilderFacade - */ - public function injectSystemEnvironmentBuilderFacade(SystemEnvironmentBuilderFacade $systemEnvironmentBuilderFacade) + private function setStaticVersion(ProjectVersion $projectVersion): void { - $this->systemEnvironmentBuilderFacade = $systemEnvironmentBuilderFacade; + $projectVersion->setVersion($this->extensionConfiguration->getStaticVersion()); } - /** - * CommandUtilityFacade injector. - * - * @param \KamiYang\ProjectVersion\Facade\CommandUtilityFacade $commandUtilityFacade - */ - public function injectCommandUtilityFacade(CommandUtilityFacade $commandUtilityFacade) + private function setVersionFromFile(ProjectVersion $projectVersion): void { - $this->commandUtilityFacade = $commandUtilityFacade; - } - - /** - * @return bool - */ - protected function isGitAvailable(): bool - { - return $this->systemEnvironmentBuilderFacade->isFunctionDisabled('exec') === false && - // check if git exists - $this->commandUtilityFacade->exec('git --version', $_, $returnCode) && - $returnCode === 0; - } - - /** - * @param \KamiYang\ProjectVersion\Service\ProjectVersion $projectVersion - */ - private function setStaticVersion(ProjectVersion $projectVersion) - { - $projectVersion->setVersion(ExtensionConfiguration::getStaticVersion()); - } - - /** - * Resolve version by common VERSION-file. - * - * @param \KamiYang\ProjectVersion\Service\ProjectVersion $projectVersion - */ - private function setVersionFromFile(ProjectVersion $projectVersion) - { - $versionFilePath = ExtensionConfiguration::getAbsVersionFilePath(); - if (\file_exists($versionFilePath)) { - $versionFileContent = \file_get_contents($versionFilePath); + $versionFilePath = $this->extensionConfiguration->getAbsVersionFilePath(); + if (file_exists($versionFilePath)) { + $versionFileContent = file_get_contents($versionFilePath); $projectVersion->setVersion($versionFileContent); } } - /** - * @param \KamiYang\ProjectVersion\Service\ProjectVersion $projectVersion - */ - private function setVersionFromGit(ProjectVersion $projectVersion) + private function setVersionFromGit(ProjectVersion $projectVersion): void { - if ($this->isGitAvailable() === false) { + if (!$this->isGitAvailable()) { return; } $version = $this->getVersionByFormat(); - if (!empty($version)) { - /* - * The icon identifier for "git" changed between TYPO3 v8 and v9. - * For TYPO3 v8 it's "sysinfo-git" and for v9 it's "information-git" - */ - $gitIconIdentifier = (float)TYPO3_version < 9 ? 'sysinfo-git' : 'information-git'; + $gitIconIdentifier = 'information-git'; $projectVersion->setVersion($version); $projectVersion->setIconIdentifier($gitIconIdentifier); } } - /** - * @return string - */ private function getVersionByFormat(): string { - $branch = \trim($this->commandUtilityFacade->exec(GitCommandEnumeration::CMD_BRANCH)); - $revision = \trim($this->commandUtilityFacade->exec(GitCommandEnumeration::CMD_REVISION)); - $tag = \trim($this->commandUtilityFacade->exec(GitCommandEnumeration::CMD_TAG)); + $branch = trim($this->commandUtilityFacade->exec(GitCommandEnumeration::CMD_BRANCH)); + $revision = trim($this->commandUtilityFacade->exec(GitCommandEnumeration::CMD_REVISION)); + $tag = trim($this->commandUtilityFacade->exec(GitCommandEnumeration::CMD_TAG)); $format = ''; if ($branch || $revision || $tag) { - $format = $this->formatVersionBasedOnConfiguration($revision, $tag, $branch); + $format = $this->formatVersion($revision, $tag, $branch); } return $format; } + + private function isExecEnabled(): bool + { + return !in_array('exec', GeneralUtility::trimExplode(',', ini_get('disable_functions')), true); + } } diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..0068b13 --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,14 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + KamiYang\ProjectVersion\: + resource: '../Classes/*' + + KamiYang\ProjectVersion\EventListener\ProjectVersionEventListener: + tags: + - name: event.listener + identifier: 'kamiyang-project-version' + event: TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent diff --git a/README.md b/README.md index 1d6d3cd..89b8ccc 100644 --- a/README.md +++ b/README.md @@ -6,55 +6,67 @@ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/KamiYang/project_version/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/KamiYang/project_version/?branch=master) ## What is project version? -Project version is a TYPO3 extension that adds an entry to the TYPO3 system information in the toolbar. This entry is based either on the common 'VERSION' file or on the local GIT revision. -## How do I install it? +Project version is a TYPO3 extension that adds an entry to the TYPO3 system information in the toolbar. This entry is +based either on the common 'VERSION' file or on the local GIT revision. + +## How do I install it? + First make sure you match the requirements: -| Requirement | Version | -| --- | --- | -| TYPO3 | \>=8.7 <9.6 | -| php | \>= 7.0 | +| Requirement | Version | +|-------------|---------------| +| TYPO3 | \>=10.4 <11.5 | +| php | \>= 7.2 | ### Composer -Simply require the extension from packagist: + +Simply require the extension from packagist: `composer require kamiyang/ext-projectversion` Or if you prefer typo3-ter: `composer require typo3-ter/projectversion` -### TER -No composer available? No problem! You also can find this extension at TYPO3's Extension Repository (TER). -You can straight download it from inside your TYPO3 as long, as your TYPO3 is not in composer mode. - ## How do I use it? + ### "VERSION"-file -Now, this is the easiest part. Create a file called `VERSION` (case sensitive) in your TYPO3 frontend docroot with the project version. This can be done like this: -`$ echo 1.0.0-rc.3 > /var/www/html/VERSION` + +Now, this is the easiest part. Create a file called `VERSION` (case sensitive) in your TYPO3 frontend docroot with the +project version. This can be done like this: +`echo 1.0.0-rc.3 > /var/www/html/VERSION` + +Thats it. In the typo3 backend the version "1.0.0-rc.3" will now be shown. ### Custom Path + You can use your own filename and path. Note that this path still has to be accessible from your web docroot. -The configuration can be done in the ExtensionConfiguration. It is also possible to change the directory of the 'VERSION'-file. Only provide a directory path (with trailing slash '/') and it will automatically search for an file called 'VERSION'. +The configuration can be done in the ExtensionConfiguration. It is also possible to change the directory of the ' +VERSION'-file. Only provide a directory path (with trailing slash '/') and it will automatically search for an file +called 'VERSION'. Examples: We assume that the web document root (`PATH_site`) is `/var/www/html`. -| Configured Path | Absolute filename | -| --- | --- | -| (empty - default) | /var/www/html/VERSION | -| MyVersion | /var/www/html/MyVersion | -| typo3conf/ | /var/www/html/typo3conf/VERSION | -| ./My/Custom/Version/File/In/Some/Nested/File/Structure | /var/www/html/./My/Custom/Version/File/In/Some/Nested/File/Structure| +| Configured Path | Absolute filename | +|--------------------------------------------------------|----------------------------------------------------------------------| +| (empty - default) | /var/www/html/VERSION | +| MyVersion | /var/www/html/MyVersion | +| typo3conf/ | /var/www/html/typo3conf/VERSION | +| ./My/Custom/Version/File/In/Some/Nested/File/Structure | /var/www/html/./My/Custom/Version/File/In/Some/Nested/File/Structure | ### GIT + Since release 0.3.0 git is supported. This must be manually activated. In order to use git, make sure it's available! -Common case is that the local development environment is based on docker images. Many docker images do not have git out of the box available. -To activate it, simply move via your preferred web browser into the TYPO3 backend. For TYPO3 v8.7 - go to "Extensions > Project Version" and configure the extension. -The configuration screen will look like this on default: +Common case is that the local development environment is based on docker images. Many docker images do not have git out +of the box available. +To activate it, simply move via your preferred web browser into the TYPO3 backend. For TYPO3 v8.7 - go to "Extensions > +Project Version" and configure the extension. +The configuration screen will look like this on default: ![default extension configuration](Documentation/Images/DefaultConfig.png) -This has changed a bit in TYPO3 v9. To configure the extension go to "Settings > Configure extensions" and filter for "project version". +This has changed a bit in TYPO3 v9. To configure the extension go to "Settings > Configure extensions" and filter for " +project version". The new configuration screen will look like this: ![new default extension configuration screen](Documentation/Images/DefaultConfigTYPO3v9.png) @@ -63,45 +75,18 @@ The new configuration screen will look like this: ##### basic.mode -| Configuration | Description | -| --- | --- | -| VERSION File (default)| Fetches the current project version based on the path configured in `basic.versionFilePath` | -| GIT | Uses GIT if available to resolve the project version in the format configured in `basic.gitFormat` | -| GIT (VERSION file as fallback) | Will use GIT as preferred resolving method. If not available will fallback to VERSION file. | - +| Configuration | Description | +|--------------------------------|----------------------------------------------------------------------------------------------------| +| VERSION File (default) | Fetches the current project version based on the path configured in `basic.versionFilePath` | +| GIT | Uses GIT if available to resolve the project version in the format configured in `basic.gitFormat` | +| GIT (VERSION file as fallback) | Will use GIT as preferred resolving method. If not available will fallback to VERSION file. | ##### basic.gitFormat -| Configuration | Description | Example | -| --- | --- | --- | -| Revision | Will only fetch the revision as project version | ![git revision example ](Documentation/Images/BasicGitFormatRevision.png) | -| \[revision] Branch (default) | Will fetch the current revision and branch | ![git revision and branch example ](Documentation/Images/BasicGitFormatRevisionAndBranch.png) | -| \[revision] Tag | Will fetch the current revision and tag | ![git revision and tag example ](Documentation/Images/BasicGitFormatRevisionAndTag.png) | -| Branch | Will only fetch the current branch | ![git branch example ](Documentation/Images/BasicGitFormatRevisionBranch.png) | -| Tag | Will only fetch the current tag | ![git tag example ](Documentation/Images/BasicGitFormatRevisionTag.png) | - -## Roadmap to v1.0.0 - - - [x] Static VERSION file support - - [x] Add ability to configure "VERSION"-file path - - [x] GIT revision support - - [x] GIT tag/branch based on revision support - - [x] Add documentation of this extensions features - - [x] Upload extension to packagist.org - - [x] Upload extension to TER - - [x] Support TYPO3 v9.4 - - [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) - - [x] Static VERSION value via extension configuration - -### Milestone for v0.6.0 - - Ability to "hardcode" static project version via the TYPO3 backend - -## Note -The TYPO3 v8 version of this extension will not be maintained after release 1.0.0! But this should be no problem because TYPO3 v8 only gets bugfixes. -This means, version 1.0.0 should stay compatible with all further TYPO3 v8 releases! - -After releasing version 1.0.0, which will be around the release of the first TYPO3 v9 LTS version, EXT:project_version will be refactored to php7.2 and will integrate TYPO3 v9 features. +| Configuration | Description | Example | +|------------------------------|-------------------------------------------------|-----------------------------------------------------------------------------------------------| +| Revision | Will only fetch the revision as project version | ![git revision example ](Documentation/Images/BasicGitFormatRevision.png) | +| \[revision] Branch (default) | Will fetch the current revision and branch | ![git revision and branch example ](Documentation/Images/BasicGitFormatRevisionAndBranch.png) | +| \[revision] Tag | Will fetch the current revision and tag | ![git revision and tag example ](Documentation/Images/BasicGitFormatRevisionAndTag.png) | +| Branch | Will only fetch the current branch | ![git branch example ](Documentation/Images/BasicGitFormatRevisionBranch.png) | +| Tag | Will only fetch the current tag | ![git tag example ](Documentation/Images/BasicGitFormatRevisionTag.png) | diff --git a/Resources/Private/Language/Backend.xlf b/Resources/Private/Language/Backend.xlf index 9581d1c..04a596f 100644 --- a/Resources/Private/Language/Backend.xlf +++ b/Resources/Private/Language/Backend.xlf @@ -1,6 +1,6 @@ - - +
diff --git a/Tests/Unit/Backend/ToolbarItems/ProjectVersionSlotTest.php b/Tests/Unit/EventListener/ProjectVersionEventListenerTest.php similarity index 54% rename from Tests/Unit/Backend/ToolbarItems/ProjectVersionSlotTest.php rename to Tests/Unit/EventListener/ProjectVersionEventListenerTest.php index 36b8b88..1d2c69c 100644 --- a/Tests/Unit/Backend/ToolbarItems/ProjectVersionSlotTest.php +++ b/Tests/Unit/EventListener/ProjectVersionEventListenerTest.php @@ -1,7 +1,6 @@ subject = new ProjectVersionSlot(); + $this->languageServiceProphecy = $this->prophesize(LanguageService::class); } - protected function tearDown() + protected function tearDown(): void { GeneralUtility::purgeInstances(); @@ -49,7 +50,7 @@ protected function tearDown() /** * @test */ - public function getProjectVersionShouldAddProjectVersionAsSystemInformation() + public function getProjectVersionShouldAddProjectVersionAsSystemInformation(): void { $version = '9000-rc.69'; $title = 'Project Version'; @@ -60,17 +61,9 @@ public function getProjectVersionShouldAddProjectVersionAsSystemInformation() $projectVersion->setTitle($title); $systemInformationToolbarItemProphecy = $this->prophesize(SystemInformationToolbarItem::class); - - $projectVersionServiceProphecy = $this->prophesize(ProjectVersionService::class); - $projectVersionServiceProphecy->getProjectVersion()->willReturn($projectVersion); - - $objectManagerProphecy = $this->prophesize(ObjectManager::class); - $objectManagerProphecy->get(ProjectVersionService::class)->willReturn($projectVersionServiceProphecy->reveal()); - - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); - GeneralUtility::setSingletonInstance(ProjectVersionService::class, $projectVersionServiceProphecy->reveal()); - - $this->subject->getProjectVersion($systemInformationToolbarItemProphecy->reveal()); + $event = new SystemInformationToolbarCollectorEvent($systemInformationToolbarItemProphecy->reveal()); + $subject = $this->getSubject($projectVersion); + $subject($event); $systemInformationToolbarItemProphecy->addSystemInformation($title, $version, $iconIdentifier) ->shouldHaveBeenCalledTimes(1); @@ -79,28 +72,19 @@ public function getProjectVersionShouldAddProjectVersionAsSystemInformation() /** * @test */ - public function getProjectVersionShouldResolveCurrentVersionAndLocalizeItIfNecessary() + public function getProjectVersionShouldResolveCurrentVersionAndLocalizeItIfNecessary(): void { $initialVersionValue = 'LLL:EXT:project_version/Resources/Private/Language/Backend.xlf:toolbarItems.sysinfo.project-version.unknown'; $projectVersion = new ProjectVersion(); $projectVersion->setVersion($initialVersionValue); $expectedVersion = 'Unknown project version'; - $projectVersionServiceProphecy = $this->prophesize(ProjectVersionService::class); - $projectVersionServiceProphecy->getProjectVersion()->willReturn($projectVersion); - - $objectManagerProphecy = $this->prophesize(ObjectManager::class); - $objectManagerProphecy->get(ProjectVersionService::class)->willReturn($projectVersionServiceProphecy->reveal()); - - $localizationUtilityFacadeProphecy = $this->prophesize(LocalizationUtilityFacade::class); - $localizationUtilityFacadeProphecy->translate($initialVersionValue)->willReturn($expectedVersion); - - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); - GeneralUtility::setSingletonInstance(ProjectVersionService::class, $projectVersionServiceProphecy->reveal()); - GeneralUtility::addInstance(LocalizationUtilityFacade::class, $localizationUtilityFacadeProphecy->reveal()); + $this->languageServiceProphecy->sL($initialVersionValue)->willReturn($expectedVersion); $systemInformationToolbarItemProphecy = $this->prophesize(SystemInformationToolbarItem::class); - $actual = $this->subject->getProjectVersion($systemInformationToolbarItemProphecy->reveal()); + $event = new SystemInformationToolbarCollectorEvent($systemInformationToolbarItemProphecy->reveal()); + $subject = $this->getSubject($projectVersion); + $subject($event); $systemInformationToolbarItemProphecy->addSystemInformation( $projectVersion->getTitle(), @@ -109,4 +93,15 @@ public function getProjectVersionShouldResolveCurrentVersionAndLocalizeItIfNeces ) ->shouldHaveBeenCalledTimes(1); } + + private function getSubject(ProjectVersion $projectVersion): ProjectVersionEventListener + { + $projectVersionServiceProphecy = $this->prophesize(ProjectVersionService::class); + $projectVersionServiceProphecy->getProjectVersion()->willReturn($projectVersion); + + return new ProjectVersionEventListener( + $projectVersionServiceProphecy->reveal(), + $this->languageServiceProphecy->reveal() + ); + } } diff --git a/Tests/Unit/Service/ProjectVersionServiceTest.php b/Tests/Unit/Service/ProjectVersionServiceTest.php index f2bab82..a91cd02 100644 --- a/Tests/Unit/Service/ProjectVersionServiceTest.php +++ b/Tests/Unit/Service/ProjectVersionServiceTest.php @@ -1,7 +1,6 @@ GitCommandEnumeration::FORMAT_REVISION_BRANCH, 'mode' => ProjectVersionModeEnumeration::FILE, 'staticVersion' => '', 'versionFilePath' => 'VERSION' ]; - /** - * @var \KamiYang\ProjectVersion\Facade\SystemEnvironmentBuilderFacade|\Prophecy\Prophecy\ObjectProphecy - */ - private $systemEnvironmentBuilderFacadeProphecy; - /** * @var \KamiYang\ProjectVersion\Facade\CommandUtilityFacade */ @@ -56,15 +56,15 @@ class ProjectVersionServiceTest extends UnitTestCase /** * @test */ - public function getProjectVersionShouldNotSetProjectVersionIfVersionFileIsNotFound() + public function getProjectVersionShouldNotSetProjectVersionIfVersionFileIsNotFound(): void { - $this->extensionConfiguration['versionFilePath'] = '/some/not/existing/path'; - $this->setUpExtensionConfiguration(); + $this->setUpExtensionConfiguration([ + 'versionFilePath' => '/some/not/existing/path' + ]); $projectVersionProphecy = $this->prophesize(ProjectVersion::class); GeneralUtility::setSingletonInstance(ProjectVersion::class, $projectVersionProphecy->reveal()); - - $this->subject->getProjectVersion(); + $_ = $this->getSubject(); $projectVersionProphecy->setVersion(Argument::any()) ->shouldNotHaveBeenCalled(); @@ -75,56 +75,50 @@ public function getProjectVersionShouldNotSetProjectVersionIfVersionFileIsNotFou * @param string $versionFilePath * @dataProvider versionFilePathDataProvider */ - public function getProjectVersionShouldSetVersionFromVersionFileIfFileExists(string $versionFilePath) + public function getProjectVersionShouldSetVersionFromVersionFileIfFileExists(string $versionFilePath): void { - $this->extensionConfiguration['versionFilePath'] = $versionFilePath; - $this->setUpExtensionConfiguration(); - - $projectVersionProphecy = $this->prophesize(ProjectVersion::class); - GeneralUtility::setSingletonInstance(ProjectVersion::class, $projectVersionProphecy->reveal()); + $this->setUpExtensionConfiguration(['versionFilePath' => $versionFilePath]); - $this->subject->getProjectVersion(); + $subject = $this->getSubject(); - $projectVersionProphecy->setVersion(Argument::containingString('1.0.1')) - ->shouldHaveBeenCalledTimes(1); + self::assertEquals( + '1.0.1', + $subject->getProjectVersion()->getVersion() + ); } - /** - * @return array - */ - public function versionFilePathDataProvider(): array + public function versionFilePathDataProvider(): Generator { - return [ - 'version file with EXT shortcut' => [ - 'EXT:project_version/Tests/Fixture/VERSION' - ], - 'directory with EXT shortcut' => [ - 'EXT:project_version/Tests/Fixture/' - ], - 'Version file with EXT shortcut and different filename' => [ - 'EXT:project_version/Tests/Fixture/VersionFileWithDifferentName' - ] + yield 'version file with EXT shortcut' => [ + 'EXT:project_version/Tests/Fixture/VERSION' + ]; + yield 'directory with EXT shortcut' => [ + 'EXT:project_version/Tests/Fixture/' + ]; + yield 'Version file with EXT shortcut and different filename' => [ + 'EXT:project_version/Tests/Fixture/VersionFileWithDifferentName' ]; } /** * @test */ - public function getProjectVersionShouldNotSetVersionFromGitIfCommandExecIsNotAvailable() + public function getProjectVersionShouldNotSetVersionFromGitIfCommandExecIsNotAvailable(): void { - $this->extensionConfiguration['mode'] = ProjectVersionModeEnumeration::GIT; - $this->setUpExtensionConfiguration(); + $this->setUpExtensionConfiguration(['mode' => ProjectVersionModeEnumeration::GIT]); $projectVersionProphecy = $this->prophesize(ProjectVersion::class); GeneralUtility::setSingletonInstance(ProjectVersion::class, $projectVersionProphecy->reveal()); - $this->systemEnvironmentBuilderFacadeProphecy->isFunctionDisabled('exec') - ->willReturn(true); + $originalDisbableFunctions = ini_get('disable_functions'); + ini_set('disable_functions', 'exec'); - $this->subject->getProjectVersion(); + $_ = $this->getSubject(); $projectVersionProphecy->setVersion(Argument::any()) ->shouldNotHaveBeenCalled(); + + ini_set('disable_functions', $originalDisbableFunctions); } /** @@ -144,30 +138,32 @@ public function getProjectVersionShouldReturnSpecifiedVersionBasedOnConfiguredGi string $revision, string $tag, string $expected - ) { - // Arrange - $this->extensionConfiguration['mode'] = ProjectVersionModeEnumeration::GIT; - $this->extensionConfiguration['gitFormat'] = $format; - $this->setUpExtensionConfiguration(); - - $projectVersionProphecy = $this->prophesize(ProjectVersion::class); - GeneralUtility::setSingletonInstance(ProjectVersion::class, $projectVersionProphecy->reveal()); - + ): void { + $this->setUpExtensionConfiguration([ + 'mode' => ProjectVersionModeEnumeration::GIT, + 'gitFormat' => $format + ]); + $returnValue = 0; + $this->commandUtilityFacadeProphecy->exec('git --version', $_, $returnValue) + ->will(function (&$arguments) { + $arguments[2] = 0; + }); $this->commandUtilityFacadeProphecy->exec(GitCommandEnumeration::CMD_BRANCH)->willReturn($branch); $this->commandUtilityFacadeProphecy->exec(GitCommandEnumeration::CMD_REVISION)->willReturn($revision); $this->commandUtilityFacadeProphecy->exec(GitCommandEnumeration::CMD_TAG)->willReturn($tag); - /** @var \KamiYang\ProjectVersion\Service\ProjectVersionService|\PHPUnit\Framework\MockObject\MockObject $subject */ $subject = $this->createPartialMock(ProjectVersionService::class, ['isGitAvailable']); - $subject->method('isGitAvailable')->willReturn(true); - $subject->injectCommandUtilityFacade($this->commandUtilityFacadeProphecy->reveal()); - $subject->injectSystemEnvironmentBuilderFacade($this->systemEnvironmentBuilderFacadeProphecy->reveal()); - - // Act - $actual = $subject->getProjectVersion(); + $this->inject($subject, 'extensionConfiguration', new ExtensionConfiguration()); + $this->inject($subject, 'commandUtilityFacade', $this->commandUtilityFacadeProphecy->reveal()); + $subject + ->expects(self::once()) + ->method('isGitAvailable') + ->willReturn(true); - // Assert - $projectVersionProphecy->setVersion($expected)->shouldHaveBeenCalled(); + static::assertSame( + $expected, + $subject->getProjectVersion()->getVersion() + ); $this->commandUtilityFacadeProphecy->exec(GitCommandEnumeration::CMD_BRANCH)->shouldHaveBeenCalledTimes(1); $this->commandUtilityFacadeProphecy->exec(GitCommandEnumeration::CMD_REVISION)->shouldHaveBeenCalledTimes(1); @@ -177,108 +173,96 @@ public function getProjectVersionShouldReturnSpecifiedVersionBasedOnConfiguredGi /** * @test */ - public function getProjectVersionShouldTryToFetchVersionFromFileIfResolvingUsingGitErrored() + public function getProjectVersionShouldTryToFetchVersionFromFileIfResolvingUsingGitErrored(): void { - //Arrange - $this->extensionConfiguration['versionFilePath'] = 'EXT:project_version/Tests/Fixture/VERSION'; - $this->extensionConfiguration['mode'] = ProjectVersionModeEnumeration::GIT_FILE_FALLBACK; - $this->extensionConfiguration['gitFormat'] = GitCommandEnumeration::FORMAT_REVISION_BRANCH; - $this->setUpExtensionConfiguration(); + $versionFilePath = 'EXT:project_version/Tests/Fixture/VERSION'; + $this->setUpExtensionConfiguration([ + 'versionFilePath' => $versionFilePath, + 'mode' => ProjectVersionModeEnumeration::GIT_FILE_FALLBACK, + 'gitFormat' => GitCommandEnumeration::FORMAT_REVISION_BRANCH + ]); $branch = ''; $revision = ''; $tag = ''; - $absoluteVersionFilename = GeneralUtility::getFileAbsFileName($this->extensionConfiguration['versionFilePath']); - $expected = \file_get_contents($absoluteVersionFilename); - - $projectVersion = new ProjectVersion(); - GeneralUtility::setSingletonInstance(ProjectVersion::class, $projectVersion); + $absoluteVersionFilename = GeneralUtility::getFileAbsFileName($versionFilePath); + $expected = trim(file_get_contents($absoluteVersionFilename)); $this->commandUtilityFacadeProphecy->exec(GitCommandEnumeration::CMD_BRANCH)->willReturn($branch); $this->commandUtilityFacadeProphecy->exec(GitCommandEnumeration::CMD_REVISION)->willReturn($revision); $this->commandUtilityFacadeProphecy->exec(GitCommandEnumeration::CMD_TAG)->willReturn($tag); + $this->commandUtilityFacadeProphecy->exec('git --version', $_, $returnCode)->willReturn(0); - /** @var \KamiYang\ProjectVersion\Service\ProjectVersionService $subject */ - $subject = $this->createPartialMock(ProjectVersionService::class, ['isGitAvailable']); - $subject->method('isGitAvailable')->willReturn(true); - $subject->injectCommandUtilityFacade($this->commandUtilityFacadeProphecy->reveal()); - $subject->injectSystemEnvironmentBuilderFacade($this->systemEnvironmentBuilderFacadeProphecy->reveal()); - - // Act - $subject->getProjectVersion(); + $subject = $this->getSubject(); - // Assert - static::assertSame($expected, $projectVersion->getVersion()); + static::assertSame($expected, $subject->getProjectVersion()->getVersion()); } /** - * @return array + * @return Generator */ - public function gitFormatDataProvider(): array + public function gitFormatDataProvider(): Generator { $branch = 'master'; $revision = 'abcdefg'; $tag = '9.0.42-rc.2'; - return [ - 'default git format' => [ - 'format' => GitCommandEnumeration::FORMAT_REVISION_BRANCH, - 'branch' => $branch, - 'revision' => $revision, - 'tag' => $tag, - 'expected' => "[{$revision}] {$branch}" - ], - 'git format: revision' => [ - 'format' => GitCommandEnumeration::FORMAT_REVISION, - 'branch' => $branch, - 'revision' => $revision, - 'tag' => $tag, - 'expected' => "{$revision}" - ], - 'git format: [revision] branch' => [ - 'format' => GitCommandEnumeration::FORMAT_REVISION_BRANCH, - 'branch' => $branch, - 'revision' => $revision, - 'tag' => $tag, - 'expected' => "[{$revision}] {$branch}" - ], - 'git format: [revision] tag' => [ - 'format' => GitCommandEnumeration::FORMAT_REVISION_TAG, - 'branch' => $branch, - 'revision' => $revision, - 'tag' => $tag, - 'expected' => "[{$revision}] {$tag}" - ], - 'git format: branch' => [ - 'format' => GitCommandEnumeration::FORMAT_BRANCH, - 'branch' => $branch, - 'revision' => $revision, - 'tag' => $tag, - 'expected' => "{$branch}" - ], - 'git format: tag' => [ - 'format' => GitCommandEnumeration::FORMAT_TAG, - 'branch' => $branch, - 'revision' => $revision, - 'tag' => $tag, - 'expected' => "{$tag}" - ], + yield 'default git format' => [ + 'format' => GitCommandEnumeration::FORMAT_REVISION_BRANCH, + 'branch' => $branch, + 'revision' => $revision, + 'tag' => $tag, + 'expected' => "[{$revision}] {$branch}" + ]; + yield 'git format: revision' => [ + 'format' => GitCommandEnumeration::FORMAT_REVISION, + 'branch' => $branch, + 'revision' => $revision, + 'tag' => $tag, + 'expected' => "{$revision}" + ]; + yield 'git format: [revision] branch' => [ + 'format' => GitCommandEnumeration::FORMAT_REVISION_BRANCH, + 'branch' => $branch, + 'revision' => $revision, + 'tag' => $tag, + 'expected' => "[{$revision}] {$branch}" + ]; + yield 'git format: [revision] tag' => [ + 'format' => GitCommandEnumeration::FORMAT_REVISION_TAG, + 'branch' => $branch, + 'revision' => $revision, + 'tag' => $tag, + 'expected' => "[{$revision}] {$tag}" + ]; + yield 'git format: branch' => [ + 'format' => GitCommandEnumeration::FORMAT_BRANCH, + 'branch' => $branch, + 'revision' => $revision, + 'tag' => $tag, + 'expected' => "{$branch}" + ]; + yield 'git format: tag' => [ + 'format' => GitCommandEnumeration::FORMAT_TAG, + 'branch' => $branch, + 'revision' => $revision, + 'tag' => $tag, + 'expected' => "{$tag}" ]; } /** * @test */ - public function getProjectVersionShouldAlwaysSetStaticVersionIfSelected() + public function getProjectVersionShouldAlwaysSetStaticVersionIfSelected(): void { - $this->extensionConfiguration['mode'] = ProjectVersionModeEnumeration::STATIC_VERSION; - $this->setUpExtensionConfiguration(); - - $projectVersionProphecy = $this->prophesize(ProjectVersion::class); - GeneralUtility::setSingletonInstance(ProjectVersion::class, $projectVersionProphecy->reveal()); + $this->setUpExtensionConfiguration(['mode' => ProjectVersionModeEnumeration::STATIC_VERSION]); - $this->subject->getProjectVersion(); + $subject = $this->getSubject(); - $projectVersionProphecy->setVersion('')->shouldHaveBeenCalledTimes(1); + static::assertSame( + '', + $subject->getProjectVersion()->getVersion() + ); } /** @@ -286,59 +270,60 @@ public function getProjectVersionShouldAlwaysSetStaticVersionIfSelected() * @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 getProjectVersionShouldSetStaticVersionFromExtensionConfigurationIfSelected( + string $staticVersion + ): void { + $this->setUpExtensionConfiguration([ + 'mode' => ProjectVersionModeEnumeration::STATIC_VERSION, + 'staticVersion' => $staticVersion + ]); + + $subject = $this->getSubject(); + + self::assertSame( + $staticVersion, + $subject->getProjectVersion()->getVersion() + ); } - public function staticVersionDataProvider(): array + public function staticVersionDataProvider(): Generator { - 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!' - ] + yield 'empty static version (default value)' => [ + 'staticVersion' => '' + ]; + yield 'some value' => [ + 'staticVersion' => 'some value' + ]; + yield '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() + protected function setUp(): void { - $this->systemEnvironmentBuilderFacadeProphecy = $this->prophesize(SystemEnvironmentBuilderFacade::class); - $this->systemEnvironmentBuilderFacadeProphecy->isFunctionDisabled('exec') - ->willReturn(false); - $this->commandUtilityFacadeProphecy = $this->prophesize(CommandUtilityFacade::class); - - $this->subject = new ProjectVersionService(); - $this->subject->injectCommandUtilityFacade($this->commandUtilityFacadeProphecy->reveal()); - $this->subject->injectSystemEnvironmentBuilderFacade($this->systemEnvironmentBuilderFacadeProphecy->reveal()); } - protected function tearDown() + protected function tearDown(): void { GeneralUtility::purgeInstances(); parent::tearDown(); } - protected function setUpExtensionConfiguration() + protected function setUpExtensionConfiguration(array $extConfig): void { - $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['project_version'] = serialize($this->extensionConfiguration); + $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['project_version'] = array_replace( + $this->defaultExtensionConfiguration, + $extConfig + ); + } - GeneralUtility::makeInstance(ExtensionConfiguration::class); + private function getSubject(): ProjectVersionService + { + return new ProjectVersionService( + $this->commandUtilityFacadeProphecy->reveal(), + new ExtensionConfiguration() + ); } } diff --git a/Tests/Unit/Service/ProjectVersionTest.php b/Tests/Unit/Service/ProjectVersionTest.php index 241d78b..1e96e41 100644 --- a/Tests/Unit/Service/ProjectVersionTest.php +++ b/Tests/Unit/Service/ProjectVersionTest.php @@ -1,7 +1,6 @@ subject = new ProjectVersion(); } @@ -36,7 +37,7 @@ protected function setUp() /** * @test */ - public function getTitleShouldReturnInitialValue() + public function getTitleShouldReturnInitialValue(): void { static::assertSame( 'LLL:EXT:project_version/Resources/Private/Language/Backend.xlf:toolbarItems.sysinfo.project-version', @@ -47,43 +48,48 @@ public function getTitleShouldReturnInitialValue() /** * @test */ - public function setTitleShouldSetPropertyTitle() + public function setTitleShouldSetPropertyTitle(): void { $newValue = 'Project Version is awesome!'; $this->subject->setTitle($newValue); - static::assertAttributeSame($newValue, 'title', $this->subject); + static::assertSame( + $newValue, + $this->subject->getTitle() + ); } /** * @test */ - public function initialVersionValueShouldBeLLLString() + public function initialVersionValueShouldBeLLLString(): void { - static::assertAttributeSame( + static::assertSame( 'LLL:EXT:project_version/Resources/Private/Language/Backend.xlf:toolbarItems.sysinfo.project-version.unknown', - 'version', - $this->subject + $this->subject->getVersion() ); } /** * @test */ - public function setVersionShouldSetPropertyVersion() + public function setVersionShouldSetPropertyVersion(): void { $newValue = 'Project Version is awesome!'; $this->subject->setVersion($newValue); - static::assertAttributeSame($newValue, 'version', $this->subject); + static::assertSame( + $newValue, + $this->subject->getVersion() + ); } /** * @test */ - public function getIconIdentifierShouldReturnInitialValue() + public function getIconIdentifierShouldReturnInitialValue(): void { static::assertSame('information-project-version', $this->subject->getIconIdentifier()); } @@ -91,12 +97,15 @@ public function getIconIdentifierShouldReturnInitialValue() /** * @test */ - public function setIconIdentifierShouldSetPropertyIconIdentifier() + public function setIconIdentifierShouldSetPropertyIconIdentifier(): void { $newValue = 'Project Version is awesome!'; $this->subject->setIconIdentifier($newValue); - static::assertAttributeSame($newValue, 'iconIdentifier', $this->subject); + static::assertSame( + $newValue, + $this->subject->getIconIdentifier() + ); } } diff --git a/composer.json b/composer.json index 6a61698..75bb701 100644 --- a/composer.json +++ b/composer.json @@ -22,14 +22,15 @@ "kamiyang/project_version": "self.version" }, "require": { - "typo3/cms-backend": "9.5.*", - "typo3/cms-extbase": "9.5.*", - "typo3/cms-extensionmanager": "9.5.*" + "typo3/cms-backend": "^10.4", + "typo3/cms-extbase": "^10.4", + "typo3/cms-extensionmanager": "^10.4" }, "require-dev": { - "nimut/testing-framework": "~4.1.1", - "phpunit/phpunit": "~6.5", - "satooshi/php-coveralls": "^2.0" + "satooshi/php-coveralls": "^2.0", + "michielroos/typo3scan": "^1.7", + "squizlabs/php_codesniffer": "^3.6", + "nimut/testing-framework": "^6" }, "autoload": { "psr-4": { @@ -42,9 +43,9 @@ } }, "scripts": { - "create-dummy-version-file": "echo \"9.0.42\" > .Build/web/VERSION", - "create-extension-directory": "mkdir -p .Build/web/typo3conf/ext", - "link-package": "ln -snvf ../../../../. .Build/web/typo3conf/ext/project_version", + "create-dummy-version-file": "echo \"9.0.42\" > .Build/public/VERSION", + "create-extension-directory": "mkdir -p .Build/public/typo3conf/ext", + "link-package": "ln -snvf ../../../../. .Build/public/typo3conf/ext/project_version", "post-update-cmd": [ "@create-extension-directory", "@link-package", @@ -63,7 +64,7 @@ "extension-key": "project_version", "cms-package-dir": "{$vendor-dir}/typo3/cms", "app-dir": ".Build", - "web-dir": ".Build/web" + "web-dir": ".Build/public" } } } diff --git a/ext_emconf.php b/ext_emconf.php index a62fee9..5385da8 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -1,8 +1,20 @@ 'Project Version', - 'description' => 'Displays current project version based on \'VERSION\' file or GIT revision.', + 'description' => 'Displays current project version based on a \'VERSION\' file or GIT revision.', 'category' => 'misc', 'state' => 'stable', 'uploadfolder' => 0, @@ -13,8 +25,8 @@ 'version' => '2.0.0-dev', 'constraints' => [ 'depends' => [ - 'php' => '7.0', - 'typo3' => '9.5.0-9.5.99' + 'php' => '7.4', + 'typo3' => '10.4.0-11.5.99' ], 'conflicts' => [ ], diff --git a/ext_localconf.php b/ext_localconf.php index e63f285..12e020b 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,8 +1,21 @@ 'EXT:project_version/Resources/Public/Icons/ToolbarItem.svg' ] ); - - // Add project version to SystemInformation - $signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( - \TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class - ); - $signalSlotDispatcher->connect( - \TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem::class, - 'getSystemInformation', - \KamiYang\ProjectVersion\Backend\ToolbarItems\ProjectVersionSlot::class, - 'getProjectVersion' - ); } -}, 'project_version'); +})(); diff --git a/phpunit.xml b/phpunit.xml index 1a2fc8f..018d1e3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,11 +1,11 @@ @@ -22,6 +22,6 @@ - +