Skip to content

Commit

Permalink
MFAG-1427: Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magicsunday committed Feb 22, 2024
1 parent 51c8511 commit 9983478
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 195 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ jobs:
strategy:
fail-fast: false
matrix:
typo3: [ '^11', '^12' ]
typo3: [ '^12.0', '^13.0' ]
php: [ '8.1', '8.2', '8.3' ]
exclude:
- typo3: '^13.0'
php: '8.1'
include:
- rector: '^1.8'
- rector: '^2.0'
typo3: '^13.0'

steps:
- id: checkout
Expand Down Expand Up @@ -50,7 +57,11 @@ jobs:
- id: install
name: Install dependencies with typo3/cms-core:${{ matrix.typo3 }}
run: |
composer require typo3/cms-core:${{ matrix.typo3 }} --no-progress
composer require typo3/cms-core:${{ matrix.typo3 }} --no-progress --no-update
composer require typo3/cms-backend:${{ matrix.typo3 }} --no-progress --no-update
composer require typo3/cms-extbase:${{ matrix.typo3 }} --no-progress --no-update
composer require typo3/cms-extensionmanager:${{ matrix.typo3 }} --no-progress --no-update
composer require ssch/typo3-rector:${{ matrix.rector }} --no-progress
git checkout composer.json
- id: lint
Expand All @@ -63,15 +74,20 @@ jobs:
name: CGL
if: ${{ always() && steps.install.conclusion == 'success' }}
run: |
php-cs-fixer fix --dry-run --verbose
php-cs-fixer fix --dry-run --verbose --config Build/.php-cs-fixer.dist.php
- id: phpstan
name: PHPStan
continue-on-error: true
if: ${{ always() && steps.install.conclusion == 'success' }}
run: |
composer ci:test:php:phpstan -- --error-format=github
- id: rector
name: Rector
if: ${{ always() && steps.install.conclusion == 'success' }}
run: |
composer ci:test:php:rector
- id: tests_unit
name: Unit Tests
if: ${{ always() && steps.install.conclusion == 'success' }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ composer.lock
# Cache
.php-cs-fixer.cache
.phplint.cache
.phpunit.result.cache
7 changes: 5 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ stages:
.parallel-hidden-job:
parallel:
matrix:
- TYPO3: [ '^11', '^12' ]
PHP: [ '8.1', '8.2' ]
- TYPO3: [ '^12.0' ]
PHP: [ '8.1', '8.2', '8.3' ]

default:
before_script:
Expand Down Expand Up @@ -38,6 +38,9 @@ composer:
- echo "Install dependencies with typo3/cms-core:$TYPO3"
- php composer.phar config -g gitlab-oauth.git.netresearch.de $GITLAB_ACCESS_TOKEN
- php composer.phar require typo3/cms-core:$TYPO3 --no-progress --no-update
- php composer.phar require typo3/cms-backend:$TYPO3 --no-progress --no-update
- php composer.phar require typo3/cms-extbase:$TYPO3 --no-progress --no-update
- php composer.phar require typo3/cms-extensionmanager:$TYPO3 --no-progress --no-update
- php composer.phar install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
- git checkout composer.json
artifacts:
Expand Down
4 changes: 1 addition & 3 deletions Build/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
die('This script supports command line usage only. Please check your command.');
}

$repositoryName = basename(dirname(__DIR__));

$header = <<<EOF
This file is part of the package netresearch/$repositoryName.
This file is part of the package netresearch/nr-textdb.
For the full copyright and license information, please read the
LICENSE file that was distributed with this source code.
Expand Down
6 changes: 6 additions & 0 deletions Build/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: ../Tests/Unit/Controller/TranslationControllerTest.php
6 changes: 3 additions & 3 deletions Build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-strict-rules/rules.neon
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-deprecation-rules/rules.neon
- %currentWorkingDirectory%/.build/vendor/friendsoftypo3/phpstan-typo3/extension.neon
# - %currentWorkingDirectory%/Build/phpstan-baseline.neon
- %currentWorkingDirectory%/Build/phpstan-baseline.neon

parameters:
# You can currently choose from 10 levels (0 is the loosest and 9 is the strictest).
Expand All @@ -19,11 +19,11 @@ parameters:
- %currentWorkingDirectory%/Resources/
- %currentWorkingDirectory%/Tests/
- %currentWorkingDirectory%/ext_localconf.php
- %currentWorkingDirectory%/ext_tables.php
- %currentWorkingDirectory%/ext_emconf.php

excludePaths:
- %currentWorkingDirectory%/.build/*
- %currentWorkingDirectory%/ext_tables.php
- %currentWorkingDirectory%/ext_emconf.php

checkGenericClassInNonGenericObjectType: false

Expand Down
2 changes: 1 addition & 1 deletion Build/rector.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* This file is part of the package netresearch/nrc-climate.
* This file is part of the package netresearch/nr-textdb.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/TranslateViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function render(): string
}

if ($this->hasTextDbEntry($placeholder)) {
return (string) $translationRequested;
return (string) $translationRequested;
}

try {
Expand Down
12 changes: 6 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down Expand Up @@ -630,11 +630,11 @@ state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

nr-textdb
Copyright (C) 2020 Netresearch TYPO3 extensions
Copyright (C) 2024 Netresearch DTT GmbH

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
Expand All @@ -643,7 +643,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

Expand All @@ -658,4 +658,4 @@ specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
135 changes: 38 additions & 97 deletions Tests/Unit/Controller/TranslationControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,136 +1,77 @@
<?php

/**
* This file is part of the package netresearch/nr-textdb.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Netresearch\NrTextdb\Tests\Unit\Controller;

use Netresearch\NrTextdb\Controller\TranslationController;
use Netresearch\NrTextdb\Domain\Repository\TranslationRepository;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
use TYPO3Fluid\Fluid\View\ViewInterface;

/**
* Test case.
*
* @author Thomas Schöne <[email protected]>
*/
class TranslationControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
class TranslationControllerTest extends UnitTestCase
{
/**
* @var \Netresearch\NrTextdb\Controller\TranslationController
* @var TranslationController
*/
protected $subject = null;

protected function setUp()
{
parent::setUp();
$this->subject = $this->getMockBuilder(\Netresearch\NrTextdb\Controller\TranslationController::class)
->setMethods(['redirect', 'forward', 'addFlashMessage'])
->disableOriginalConstructor()
->getMock();
}

protected function tearDown()
{
parent::tearDown();
}
protected TranslationController $subject;

/**
* @test
* @return void
*/
public function listActionFetchesAllTranslationsFromRepositoryAndAssignsThemToView()
protected function setUp(): void
{
parent::setUp();

$allTranslations = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class)
->disableOriginalConstructor()
->getMock();

$translationRepository = $this->getMockBuilder(\Netresearch\NrTextdb\Domain\Repository\TranslationRepository::class)
->setMethods(['findAll'])
$this->subject = $this->getMockBuilder(TranslationController::class)
->disableOriginalConstructor()
->getMock();
$translationRepository->expects(self::once())->method('findAll')->will(self::returnValue($allTranslations));
$this->inject($this->subject, 'translationRepository', $translationRepository);

$view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock();
$view->expects(self::once())->method('assign')->with('translations', $allTranslations);
$this->inject($this->subject, 'view', $view);

$this->subject->listAction();
}

/**
* @test
*/
public function showActionAssignsTheGivenTranslationToView()
{
$translation = new \Netresearch\NrTextdb\Domain\Model\Translation();

$view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock();
$this->inject($this->subject, 'view', $view);
$view->expects(self::once())->method('assign')->with('translation', $translation);

$this->subject->showAction($translation);
}

/**
* @test
*/
public function createActionAddsTheGivenTranslationToTranslationRepository()
public function listActionFetchesAllTranslationsFromRepositoryAndAssignsThemToView(): void
{
$translation = new \Netresearch\NrTextdb\Domain\Model\Translation();
self::markTestIncomplete('Rework');

$translationRepository = $this->getMockBuilder(\Netresearch\NrTextdb\Domain\Repository\TranslationRepository::class)
->setMethods(['add'])
$allTranslations = $this->getMockBuilder(QueryResultInterface::class)
->disableOriginalConstructor()
->getMock();

$translationRepository->expects(self::once())->method('add')->with($translation);
$this->inject($this->subject, 'translationRepository', $translationRepository);

$this->subject->createAction($translation);
}

/**
* @test
*/
public function editActionAssignsTheGivenTranslationToView()
{
$translation = new \Netresearch\NrTextdb\Domain\Model\Translation();

$view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock();
$this->inject($this->subject, 'view', $view);
$view->expects(self::once())->method('assign')->with('translation', $translation);

$this->subject->editAction($translation);
}

/**
* @test
*/
public function updateActionUpdatesTheGivenTranslationInTranslationRepository()
{
$translation = new \Netresearch\NrTextdb\Domain\Model\Translation();

$translationRepository = $this->getMockBuilder(\Netresearch\NrTextdb\Domain\Repository\TranslationRepository::class)
->setMethods(['update'])
$translationRepository = $this->getMockBuilder(TranslationRepository::class)
->disableOriginalConstructor()
->getMock();

$translationRepository->expects(self::once())->method('update')->with($translation);
$this->inject($this->subject, 'translationRepository', $translationRepository);
$translationRepository
->expects(self::once())
->method('getAllRecordsByIdentifier')
->willReturn($allTranslations);

$this->subject->updateAction($translation);
}
$this->inject($this->subject, 'translationRepository', $translationRepository);

/**
* @test
*/
public function deleteActionRemovesTheGivenTranslationFromTranslationRepository()
{
$translation = new \Netresearch\NrTextdb\Domain\Model\Translation();
$view = $this->getMockBuilder(ViewInterface::class)->getMock();

$translationRepository = $this->getMockBuilder(\Netresearch\NrTextdb\Domain\Repository\TranslationRepository::class)
->setMethods(['remove'])
->disableOriginalConstructor()
->getMock();
$view
->expects(self::once())
->method('assign')
->with('translations', $allTranslations);

$translationRepository->expects(self::once())->method('remove')->with($translation);
$this->inject($this->subject, 'translationRepository', $translationRepository);
$this->inject($this->subject, 'view', $view);

$this->subject->deleteAction($translation);
$this->subject->listAction();
}
}
Loading

0 comments on commit 9983478

Please sign in to comment.