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 88bb7ca
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 176 deletions.
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
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
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();
}
}
41 changes: 27 additions & 14 deletions Tests/Unit/Domain/Model/ComponentTest.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
<?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\Domain\Model;

use Netresearch\NrTextdb\Domain\Model\Component;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

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

protected function setUp()
/**
* @return void
*/
/**
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->subject = new \Netresearch\NrTextdb\Domain\Model\Component();
}

protected function tearDown()
{
parent::tearDown();
$this->subject = new Component();
}

/**
* @test
*/
public function getNameReturnsInitialValueForString()
public function getNameReturnsInitialValueForString(): void
{
self::assertSame(
'',
Expand All @@ -39,14 +53,13 @@ public function getNameReturnsInitialValueForString()
/**
* @test
*/
public function setNameForStringSetsName()
public function setNameForStringSetsName(): void
{
$this->subject->setName('Conceived at T3CON10');

self::assertAttributeEquals(
self::assertSame(
'Conceived at T3CON10',
'name',
$this->subject
$this->subject->getName()
);
}
}
38 changes: 24 additions & 14 deletions Tests/Unit/Domain/Model/EnvironmentTest.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
<?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\Domain\Model;

use Netresearch\NrTextdb\Domain\Model\Environment;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

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

protected function setUp()
/**
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->subject = new \Netresearch\NrTextdb\Domain\Model\Environment();
}

protected function tearDown()
{
parent::tearDown();
$this->subject = new Environment();
}

/**
* @test
*/
public function getNameReturnsInitialValueForString()
public function getNameReturnsInitialValueForString(): void
{
self::assertSame(
'',
Expand All @@ -39,14 +50,13 @@ public function getNameReturnsInitialValueForString()
/**
* @test
*/
public function setNameForStringSetsName()
public function setNameForStringSetsName(): void
{
$this->subject->setName('Conceived at T3CON10');

self::assertAttributeEquals(
self::assertSame(
'Conceived at T3CON10',
'name',
$this->subject
$this->subject->getName()
);
}
}
Loading

0 comments on commit 88bb7ca

Please sign in to comment.