mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2025-03-15 08:43:50 +01:00
This commit is contained in:
Oliver Klee 2025-02-03 15:20:21 +00:00 committed by GitHub
commit a9271780b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 93 additions and 264 deletions

View file

@ -18,9 +18,9 @@ updates:
allow: allow:
- dependency-type: "development" - dependency-type: "development"
ignore: ignore:
- dependency-name: "brianium/paratest"
- dependency-name: "doctrine/dbal" - dependency-name: "doctrine/dbal"
- dependency-name: "phpunit/phpunit" - dependency-name: "phpunit/phpunit"
versions: [ "^10.0" ]
- dependency-name: "symfony/console" - dependency-name: "symfony/console"
- dependency-name: "symfony/translation" - dependency-name: "symfony/translation"
- dependency-name: "symfony/yaml" - dependency-name: "symfony/yaml"

View file

@ -5,12 +5,6 @@ use TYPO3\CodingStandards\CsFixerConfig;
$config = CsFixerConfig::create(); $config = CsFixerConfig::create();
$config->addRules([
// This is required as long as we are on PHPUnit 9.x. It can be removed after the switch to PHPUnit 10.x.
// @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/8337
'php_unit_test_case_static_method_calls' => ['call_type' => 'self', 'methods' => ['createStub' => 'this']],
]);
// @TODO 4.0 no need to call this manually // @TODO 4.0 no need to call this manually
$config->setParallelConfig(ParallelConfigFactory::detect()); $config->setParallelConfig(ParallelConfigFactory::detect());

View file

@ -1,38 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit <phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="true" backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="false" beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php" bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
cacheResult="false" cacheResult="false"
colors="true" colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
failOnRisky="true" failOnRisky="true"
failOnWarning="true" failOnWarning="true"
forceCoversAnnotation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
> >
<coverage/>
<testsuites>
<testsuite name="Functional tests">
<!--
This path either needs an adaption in extensions, or an extension's
test location path needs to be given to phpunit.
-->
<directory suffix="Test.php">./</directory>
</testsuite>
</testsuites>
<php> <php>
<!-- @deprecated: will be removed with next major version, constant TYPO3_MODE is deprecated -->
<const name="TYPO3_MODE" value="BE"/>
<!-- <!--
@deprecated: Set this to not suppress warnings, notices and deprecations in functional tests @deprecated: Set this to not suppress warnings, notices and deprecations in functional tests
with TYPO3 core v11 and up. with TYPO3 core v11 and up.

View file

@ -1,37 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit <phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
beStrictAboutTestsThatDoNotTestAnything="false" beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php"
cacheResult="false" cacheResult="false"
colors="true" colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
failOnRisky="true" failOnRisky="true"
failOnWarning="true" failOnWarning="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
> >
<coverage/>
<testsuites>
<testsuite name="Unit tests">
<!--
This path either needs an adaption in extensions, or an extension's
test location path needs to be given to phpunit.
-->
<directory suffix="Test.php">./</directory>
</testsuite>
</testsuites>
<php> <php>
<!-- @deprecated: will be removed with next major version, constant TYPO3_MODE is deprecated -->
<const name="TYPO3_MODE" value="BE"/>
<ini name="display_errors" value="1"/> <ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/> <env name="TYPO3_CONTEXT" value="Testing"/>
</php> </php>

View file

@ -4,15 +4,15 @@ declare(strict_types=1);
namespace TTN\Tea\Tests\Functional\Command; namespace TTN\Tea\Tests\Functional\Command;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use TTN\Tea\Command\CreateTestDataCommand; use TTN\Tea\Command\CreateTestDataCommand;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/** #[CoversClass(CreateTestDataCommand::class)]
* @covers \TTN\Tea\Command\CreateTestDataCommand
*/
final class CreateTestDataCommandTest extends FunctionalTestCase final class CreateTestDataCommandTest extends FunctionalTestCase
{ {
/** /**
@ -38,35 +38,27 @@ final class CreateTestDataCommandTest extends FunctionalTestCase
$this->commandTester = new CommandTester($command); $this->commandTester = new CommandTester($command);
} }
/** #[Test]
* @test
*/
public function isConsoleCommand(): void public function isConsoleCommand(): void
{ {
self::assertInstanceOf(Command::class, $this->subject); self::assertInstanceOf(Command::class, $this->subject);
} }
/** #[Test]
* @test
*/
public function hasDescription(): void public function hasDescription(): void
{ {
$expected = 'Create test data for the tea extension in an already existing page (sysfolder).'; $expected = 'Create test data for the tea extension in an already existing page (sysfolder).';
self::assertSame($expected, $this->subject->getHelp()); self::assertSame($expected, $this->subject->getHelp());
} }
/** #[Test]
* @test
*/
public function hasHelpText(): void public function hasHelpText(): void
{ {
$expected = 'Create test data for the tea extension in an already existing page (sysfolder).'; $expected = 'Create test data for the tea extension in an already existing page (sysfolder).';
self::assertSame($expected, $this->subject->getHelp()); self::assertSame($expected, $this->subject->getHelp());
} }
/** #[Test]
* @test
*/
public function runReturnsSuccessStatus(): void public function runReturnsSuccessStatus(): void
{ {
$result = $this->commandTester->execute( $result = $this->commandTester->execute(
@ -78,9 +70,7 @@ final class CreateTestDataCommandTest extends FunctionalTestCase
self::assertSame(Command::SUCCESS, $result); self::assertSame(Command::SUCCESS, $result);
} }
/** #[Test]
* @test
*/
public function createsTestData(): void public function createsTestData(): void
{ {
$this->commandTester->execute([ $this->commandTester->execute([
@ -90,9 +80,7 @@ final class CreateTestDataCommandTest extends FunctionalTestCase
$this->assertCSVDataSet(__DIR__ . '/Fixtures/Database/Teas.csv'); $this->assertCSVDataSet(__DIR__ . '/Fixtures/Database/Teas.csv');
} }
/** #[Test]
* @test
*/
public function deletesExistingDataOnGivenPidBeforeCreatingNewData(): void public function deletesExistingDataOnGivenPidBeforeCreatingNewData(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/Database/ExistingTeas.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/ExistingTeas.csv');
@ -106,9 +94,7 @@ final class CreateTestDataCommandTest extends FunctionalTestCase
$this->assertCSVDataSet(__DIR__ . '/Fixtures/Database/TeasAfterDelete.csv'); $this->assertCSVDataSet(__DIR__ . '/Fixtures/Database/TeasAfterDelete.csv');
} }
/** #[Test]
* @test
*/
public function doesNotDeleteDataOnOtherPid(): void public function doesNotDeleteDataOnOtherPid(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/Database/OtherExistingTeas.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/OtherExistingTeas.csv');

View file

@ -4,12 +4,13 @@ declare(strict_types=1);
namespace TTN\Tea\Tests\Functional\Controller; namespace TTN\Tea\Tests\Functional\Controller;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use TTN\Tea\Controller\TeaController;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/** #[CoversClass(TeaController::class)]
* @covers \TTN\Tea\Controller\TeaController
*/
final class TeaControllerTest extends FunctionalTestCase final class TeaControllerTest extends FunctionalTestCase
{ {
protected array $testExtensionsToLoad = ['ttn/tea']; protected array $testExtensionsToLoad = ['ttn/tea'];
@ -49,9 +50,7 @@ final class TeaControllerTest extends FunctionalTestCase
$this->importCSVDataSet(__DIR__ . '/Fixtures/Database/Teas.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/Database/Teas.csv');
} }
/** #[Test]
* @test
*/
public function indexActionRendersAllAvailableTeas(): void public function indexActionRendersAllAvailableTeas(): void
{ {
$request = (new InternalRequest())->withPageId(1); $request = (new InternalRequest())->withPageId(1);
@ -62,9 +61,7 @@ final class TeaControllerTest extends FunctionalTestCase
self::assertStringContainsString('Oolong', $html); self::assertStringContainsString('Oolong', $html);
} }
/** #[Test]
* @test
*/
public function showActionRendersTheGivenTeas(): void public function showActionRendersTheGivenTeas(): void
{ {
$request = (new InternalRequest())->withPageId(3)->withQueryParameters(['tx_tea_teashow[tea]' => 1]); $request = (new InternalRequest())->withPageId(3)->withQueryParameters(['tx_tea_teashow[tea]' => 1]);

View file

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace TTN\Tea\Tests\Functional\Domain\Repository; namespace TTN\Tea\Tests\Functional\Domain\Repository;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use TTN\Tea\Domain\Model\Tea; use TTN\Tea\Domain\Model\Tea;
use TTN\Tea\Domain\Repository\TeaRepository; use TTN\Tea\Domain\Repository\TeaRepository;
use TYPO3\CMS\Extbase\Domain\Model\FileReference; use TYPO3\CMS\Extbase\Domain\Model\FileReference;
@ -11,10 +13,8 @@ use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
use TYPO3\CMS\Extbase\Persistence\Repository; use TYPO3\CMS\Extbase\Persistence\Repository;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/** #[CoversClass(TeaRepository::class)]
* @covers \TTN\Tea\Domain\Repository\TeaRepository #[CoversClass(Tea::class)]
* @covers \TTN\Tea\Domain\Model\Tea
*/
final class TeaRepositoryTest extends FunctionalTestCase final class TeaRepositoryTest extends FunctionalTestCase
{ {
protected array $testExtensionsToLoad = ['ttn/tea']; protected array $testExtensionsToLoad = ['ttn/tea'];
@ -32,17 +32,13 @@ final class TeaRepositoryTest extends FunctionalTestCase
$this->subject = $this->get(TeaRepository::class); $this->subject = $this->get(TeaRepository::class);
} }
/** #[Test]
* @test
*/
public function isRepository(): void public function isRepository(): void
{ {
self::assertInstanceOf(Repository::class, $this->subject); self::assertInstanceOf(Repository::class, $this->subject);
} }
/** #[Test]
* @test
*/
public function findAllForNoRecordsReturnsEmptyContainer(): void public function findAllForNoRecordsReturnsEmptyContainer(): void
{ {
$result = $this->subject->findAll(); $result = $this->subject->findAll();
@ -50,9 +46,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertCount(0, $result); self::assertCount(0, $result);
} }
/** #[Test]
* @test
*/
public function findAllSortsByTitleInAscendingOrder(): void public function findAllSortsByTitleInAscendingOrder(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/TwoUnsortedTeas.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/TwoUnsortedTeas.csv');
@ -63,9 +57,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertSame(2, $result->current()->getUid()); self::assertSame(2, $result->current()->getUid());
} }
/** #[Test]
* @test
*/
public function findByUidForInexistentRecordReturnsNull(): void public function findByUidForInexistentRecordReturnsNull(): void
{ {
$model = $this->subject->findByUid(1); $model = $this->subject->findByUid(1);
@ -73,9 +65,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertNull($model); self::assertNull($model);
} }
/** #[Test]
* @test
*/
public function findByUidForExistingRecordReturnsModel(): void public function findByUidForExistingRecordReturnsModel(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithAllScalarData.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithAllScalarData.csv');
@ -85,9 +75,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertInstanceOf(Tea::class, $model); self::assertInstanceOf(Tea::class, $model);
} }
/** #[Test]
* @test
*/
public function findByUidForExistingRecordMapsAllScalarData(): void public function findByUidForExistingRecordMapsAllScalarData(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithAllScalarData.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithAllScalarData.csv');
@ -100,9 +88,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertSame(2, $model->getOwnerUid()); self::assertSame(2, $model->getOwnerUid());
} }
/** #[Test]
* @test
*/
public function fillsImageRelation(): void public function fillsImageRelation(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithImage.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithImage.csv');
@ -115,9 +101,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertSame(1, $image->getUid()); self::assertSame(1, $image->getUid());
} }
/** #[Test]
* @test
*/
public function addAndPersistAllCreatesNewRecord(): void public function addAndPersistAllCreatesNewRecord(): void
{ {
$title = 'Godesberger Burgtee'; $title = 'Godesberger Burgtee';
@ -130,9 +114,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
$this->assertCSVDataSet(__DIR__ . '/Fixtures/PersistedTea.csv'); $this->assertCSVDataSet(__DIR__ . '/Fixtures/PersistedTea.csv');
} }
/** #[Test]
* @test
*/
public function findByOwnerUidFindsTeaWithTheGivenOwnerUid(): void public function findByOwnerUidFindsTeaWithTheGivenOwnerUid(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithOwner.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithOwner.csv');
@ -142,9 +124,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertCount(1, $result); self::assertCount(1, $result);
} }
/** #[Test]
* @test
*/
public function findByOwnerUidFindsTeaWithTheGivenOwnerUidOnPage(): void public function findByOwnerUidFindsTeaWithTheGivenOwnerUidOnPage(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithOwnerOnPage.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithOwnerOnPage.csv');
@ -154,9 +134,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertCount(1, $result); self::assertCount(1, $result);
} }
/** #[Test]
* @test
*/
public function findByOwnerUidFindsIgnoresTeaWithNonMatchingOwnerUid(): void public function findByOwnerUidFindsIgnoresTeaWithNonMatchingOwnerUid(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithOwner.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithOwner.csv');
@ -166,9 +144,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertCount(0, $result); self::assertCount(0, $result);
} }
/** #[Test]
* @test
*/
public function findByOwnerUidFindsIgnoresTeaWithZeroOwnerUid(): void public function findByOwnerUidFindsIgnoresTeaWithZeroOwnerUid(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithoutOwner.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithoutOwner.csv');
@ -178,9 +154,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertCount(0, $result); self::assertCount(0, $result);
} }
/** #[Test]
* @test
*/
public function findByOwnerUidSortsByTitleInAscendingOrder(): void public function findByOwnerUidSortsByTitleInAscendingOrder(): void
{ {
$this->importCSVDataSet(__DIR__ . '/Fixtures/TwoTeasWithOwner.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/TwoTeasWithOwner.csv');

View file

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace TTN\Tea\Tests\Unit\Controller; namespace TTN\Tea\Tests\Unit\Controller;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use TTN\Tea\Controller\FrontEndEditorController; use TTN\Tea\Controller\FrontEndEditorController;
use TTN\Tea\Domain\Model\Tea; use TTN\Tea\Domain\Model\Tea;
@ -22,9 +24,8 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/** /**
* Note: Unit tests for controllers are not considered best practice anymore. Instead, functional tests should be used. * Note: Unit tests for controllers are not considered best practice anymore. Instead, functional tests should be used.
* We're currently in the process of migrating all controller tests to functional tests. * We're currently in the process of migrating all controller tests to functional tests.
*
* @covers \TTN\Tea\Controller\FrontEndEditorController
*/ */
#[CoversClass(FrontEndEditorController::class)]
final class FrontEndEditorControllerTest extends UnitTestCase final class FrontEndEditorControllerTest extends UnitTestCase
{ {
/** /**
@ -62,7 +63,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->viewMock = $this->createMock(TemplateView::class); $this->viewMock = $this->createMock(TemplateView::class);
$this->subject->_set('view', $this->viewMock); $this->subject->_set('view', $this->viewMock);
$responseStub = $this->createStub(HtmlResponse::class); $responseStub = self::createStub(HtmlResponse::class);
$this->subject->method('htmlResponse')->willReturn($responseStub); $this->subject->method('htmlResponse')->willReturn($responseStub);
} }
@ -84,17 +85,13 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->context->setAspect('frontend.user', $userAspectMock); $this->context->setAspect('frontend.user', $userAspectMock);
} }
/** #[Test]
* @test
*/
public function isActionController(): void public function isActionController(): void
{ {
self::assertInstanceOf(ActionController::class, $this->subject); self::assertInstanceOf(ActionController::class, $this->subject);
} }
/** #[Test]
* @test
*/
public function indexActionForNoLoggedInUserAssignsNothingToView(): void public function indexActionForNoLoggedInUserAssignsNothingToView(): void
{ {
$this->setUidOfLoggedInUser(0); $this->setUidOfLoggedInUser(0);
@ -104,24 +101,20 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->indexAction(); $this->subject->indexAction();
} }
/** #[Test]
* @test
*/
public function indexActionForLoggedInUserAssignsTeasOwnedByTheLoggedInUserToView(): void public function indexActionForLoggedInUserAssignsTeasOwnedByTheLoggedInUserToView(): void
{ {
$userUid = 5; $userUid = 5;
$this->setUidOfLoggedInUser($userUid); $this->setUidOfLoggedInUser($userUid);
$teas = $this->createStub(QueryResultInterface::class); $teas = self::createStub(QueryResultInterface::class);
$this->teaRepositoryMock->method('findByOwnerUid')->with($userUid)->willReturn($teas); $this->teaRepositoryMock->method('findByOwnerUid')->with($userUid)->willReturn($teas);
$this->viewMock->expects(self::once())->method('assign')->with('teas', $teas); $this->viewMock->expects(self::once())->method('assign')->with('teas', $teas);
$this->subject->indexAction(); $this->subject->indexAction();
} }
/** #[Test]
* @test
*/
public function indexActionReturnsHtmlResponse(): void public function indexActionReturnsHtmlResponse(): void
{ {
$result = $this->subject->indexAction(); $result = $this->subject->indexAction();
@ -129,9 +122,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
self::assertInstanceOf(HtmlResponse::class, $result); self::assertInstanceOf(HtmlResponse::class, $result);
} }
/** #[Test]
* @test
*/
public function editActionWithOwnTeaAssignsProvidedTeaToView(): void public function editActionWithOwnTeaAssignsProvidedTeaToView(): void
{ {
$userUid = 5; $userUid = 5;
@ -144,9 +135,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->editAction($tea); $this->subject->editAction($tea);
} }
/** #[Test]
* @test
*/
public function editActionWithTeaFromOtherUserThrowsException(): void public function editActionWithTeaFromOtherUserThrowsException(): void
{ {
$this->setUidOfLoggedInUser(1); $this->setUidOfLoggedInUser(1);
@ -160,9 +149,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->editAction($tea); $this->subject->editAction($tea);
} }
/** #[Test]
* @test
*/
public function editActionWithTeaWithoutOwnerThrowsException(): void public function editActionWithTeaWithoutOwnerThrowsException(): void
{ {
$this->setUidOfLoggedInUser(1); $this->setUidOfLoggedInUser(1);
@ -176,9 +163,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->editAction($tea); $this->subject->editAction($tea);
} }
/** #[Test]
* @test
*/
public function editActionForOwnTeaReturnsHtmlResponse(): void public function editActionForOwnTeaReturnsHtmlResponse(): void
{ {
$userUid = 5; $userUid = 5;
@ -191,9 +176,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
self::assertInstanceOf(HtmlResponse::class, $result); self::assertInstanceOf(HtmlResponse::class, $result);
} }
/** #[Test]
* @test
*/
public function updateActionWithOwnTeaPersistsProvidedTea(): void public function updateActionWithOwnTeaPersistsProvidedTea(): void
{ {
$userUid = 5; $userUid = 5;
@ -209,20 +192,18 @@ final class FrontEndEditorControllerTest extends UnitTestCase
private function mockRedirect(string $actionName): void private function mockRedirect(string $actionName): void
{ {
$redirectResponse = $this->createStub(RedirectResponse::class); $redirectResponse = self::createStub(RedirectResponse::class);
$this->subject->expects(self::once())->method('redirect')->with($actionName) $this->subject->expects(self::once())->method('redirect')->with($actionName)
->willReturn($redirectResponse); ->willReturn($redirectResponse);
} }
private function stubRedirect(string $actionName): void private function stubRedirect(string $actionName): void
{ {
$redirectResponse = $this->createStub(RedirectResponse::class); $redirectResponse = self::createStub(RedirectResponse::class);
$this->subject->method('redirect')->willReturn($redirectResponse); $this->subject->method('redirect')->willReturn($redirectResponse);
} }
/** #[Test]
* @test
*/
public function updateActionWithOwnTeaRedirectsToIndexAction(): void public function updateActionWithOwnTeaRedirectsToIndexAction(): void
{ {
$userUid = 5; $userUid = 5;
@ -235,9 +216,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->updateAction($tea); $this->subject->updateAction($tea);
} }
/** #[Test]
* @test
*/
public function updateActionWithTeaFromOtherUserThrowsException(): void public function updateActionWithTeaFromOtherUserThrowsException(): void
{ {
$this->setUidOfLoggedInUser(1); $this->setUidOfLoggedInUser(1);
@ -251,9 +230,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->updateAction($tea); $this->subject->updateAction($tea);
} }
/** #[Test]
* @test
*/
public function updateActionWithTeaWithoutOwnerThrowsException(): void public function updateActionWithTeaWithoutOwnerThrowsException(): void
{ {
$this->setUidOfLoggedInUser(1); $this->setUidOfLoggedInUser(1);
@ -267,9 +244,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->updateAction($tea); $this->subject->updateAction($tea);
} }
/** #[Test]
* @test
*/
public function newActionWithTeaAssignsProvidedTeaToView(): void public function newActionWithTeaAssignsProvidedTeaToView(): void
{ {
$tea = new Tea(); $tea = new Tea();
@ -279,9 +254,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->newAction($tea); $this->subject->newAction($tea);
} }
/** #[Test]
* @test
*/
public function newActionWithNullTeaAssignsProvidedNewTeaToView(): void public function newActionWithNullTeaAssignsProvidedNewTeaToView(): void
{ {
$tea = new Tea(); $tea = new Tea();
@ -292,9 +265,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->newAction(null); $this->subject->newAction(null);
} }
/** #[Test]
* @test
*/
public function newActionWithoutTeaAssignsProvidedNewTeaToView(): void public function newActionWithoutTeaAssignsProvidedNewTeaToView(): void
{ {
$tea = new Tea(); $tea = new Tea();
@ -305,9 +276,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->newAction(); $this->subject->newAction();
} }
/** #[Test]
* @test
*/
public function newActionReturnsHtmlResponse(): void public function newActionReturnsHtmlResponse(): void
{ {
$result = $this->subject->newAction(); $result = $this->subject->newAction();
@ -315,9 +284,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
self::assertInstanceOf(HtmlResponse::class, $result); self::assertInstanceOf(HtmlResponse::class, $result);
} }
/** #[Test]
* @test
*/
public function createActionSetsLoggedInUserAsOwnerOfProvidedTea(): void public function createActionSetsLoggedInUserAsOwnerOfProvidedTea(): void
{ {
$userUid = 5; $userUid = 5;
@ -330,9 +297,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
self::assertSame($userUid, $tea->getOwnerUid()); self::assertSame($userUid, $tea->getOwnerUid());
} }
/** #[Test]
* @test
*/
public function createActionPersistsProvidedTea(): void public function createActionPersistsProvidedTea(): void
{ {
$tea = new Tea(); $tea = new Tea();
@ -343,9 +308,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->createAction($tea); $this->subject->createAction($tea);
} }
/** #[Test]
* @test
*/
public function createActionRedirectsToIndexAction(): void public function createActionRedirectsToIndexAction(): void
{ {
$tea = new Tea(); $tea = new Tea();
@ -355,9 +318,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->updateAction($tea); $this->subject->updateAction($tea);
} }
/** #[Test]
* @test
*/
public function deleteActionWithOwnTeaRemovesProvidedTea(): void public function deleteActionWithOwnTeaRemovesProvidedTea(): void
{ {
$userUid = 5; $userUid = 5;
@ -371,9 +332,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->deleteAction($tea); $this->subject->deleteAction($tea);
} }
/** #[Test]
* @test
*/
public function deleteActionWithOwnTeaRedirectsToIndexAction(): void public function deleteActionWithOwnTeaRedirectsToIndexAction(): void
{ {
$userUid = 5; $userUid = 5;
@ -386,9 +345,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->deleteAction($tea); $this->subject->deleteAction($tea);
} }
/** #[Test]
* @test
*/
public function deleteActionWithTeaFromOtherUserThrowsException(): void public function deleteActionWithTeaFromOtherUserThrowsException(): void
{ {
$this->setUidOfLoggedInUser(1); $this->setUidOfLoggedInUser(1);
@ -402,9 +359,7 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->deleteAction($tea); $this->subject->deleteAction($tea);
} }
/** #[Test]
* @test
*/
public function deleteActionWithTeaWithoutOwnerThrowsException(): void public function deleteActionWithTeaWithoutOwnerThrowsException(): void
{ {
$this->setUidOfLoggedInUser(1); $this->setUidOfLoggedInUser(1);

View file

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace TTN\Tea\Tests\Unit\Controller; namespace TTN\Tea\Tests\Unit\Controller;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use TTN\Tea\Controller\TeaController; use TTN\Tea\Controller\TeaController;
use TTN\Tea\Domain\Model\Tea; use TTN\Tea\Domain\Model\Tea;
@ -18,9 +20,8 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/** /**
* Note: Unit tests for controllers are not considered best practice anymore. Instead, functional tests should be used. * Note: Unit tests for controllers are not considered best practice anymore. Instead, functional tests should be used.
* We're currently in the process of migrating all controller tests to functional tests. * We're currently in the process of migrating all controller tests to functional tests.
*
* @covers \TTN\Tea\Controller\TeaController
*/ */
#[CoversClass(TeaController::class)]
final class TeaControllerTest extends UnitTestCase final class TeaControllerTest extends UnitTestCase
{ {
/** /**
@ -50,33 +51,27 @@ final class TeaControllerTest extends UnitTestCase
$this->viewMock = $this->createMock(TemplateView::class); $this->viewMock = $this->createMock(TemplateView::class);
$this->subject->_set('view', $this->viewMock); $this->subject->_set('view', $this->viewMock);
$responseStub = $this->createStub(HtmlResponse::class); $responseStub = self::createStub(HtmlResponse::class);
$this->subject->method('htmlResponse')->willReturn($responseStub); $this->subject->method('htmlResponse')->willReturn($responseStub);
} }
/** #[Test]
* @test
*/
public function isActionController(): void public function isActionController(): void
{ {
self::assertInstanceOf(ActionController::class, $this->subject); self::assertInstanceOf(ActionController::class, $this->subject);
} }
/** #[Test]
* @test
*/
public function indexActionAssignsAllTeaAsTeasToView(): void public function indexActionAssignsAllTeaAsTeasToView(): void
{ {
$teas = $this->createStub(QueryResultInterface::class); $teas = self::createStub(QueryResultInterface::class);
$this->teaRepositoryMock->method('findAll')->willReturn($teas); $this->teaRepositoryMock->method('findAll')->willReturn($teas);
$this->viewMock->expects(self::once())->method('assign')->with('teas', $teas); $this->viewMock->expects(self::once())->method('assign')->with('teas', $teas);
$this->subject->indexAction(); $this->subject->indexAction();
} }
/** #[Test]
* @test
*/
public function indexActionReturnsHtmlResponse(): void public function indexActionReturnsHtmlResponse(): void
{ {
$result = $this->subject->indexAction(); $result = $this->subject->indexAction();
@ -84,9 +79,7 @@ final class TeaControllerTest extends UnitTestCase
self::assertInstanceOf(HtmlResponse::class, $result); self::assertInstanceOf(HtmlResponse::class, $result);
} }
/** #[Test]
* @test
*/
public function showActionAssignsPassedTeaAsTeaToView(): void public function showActionAssignsPassedTeaAsTeaToView(): void
{ {
$tea = new Tea(); $tea = new Tea();
@ -95,9 +88,7 @@ final class TeaControllerTest extends UnitTestCase
$this->subject->showAction($tea); $this->subject->showAction($tea);
} }
/** #[Test]
* @test
*/
public function showActionAssignsReturnsHtmlResponse(): void public function showActionAssignsReturnsHtmlResponse(): void
{ {
$result = $this->subject->showAction(new Tea()); $result = $this->subject->showAction(new Tea());

View file

@ -4,14 +4,14 @@ declare(strict_types=1);
namespace TTN\Tea\Tests\Unit\Domain\Model; namespace TTN\Tea\Tests\Unit\Domain\Model;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use TTN\Tea\Domain\Model\Tea; use TTN\Tea\Domain\Model\Tea;
use TYPO3\CMS\Extbase\Domain\Model\FileReference; use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/** #[CoversClass(Tea::class)]
* @covers \TTN\Tea\Domain\Model\Tea
*/
final class TeaTest extends UnitTestCase final class TeaTest extends UnitTestCase
{ {
private Tea $subject; private Tea $subject;
@ -23,25 +23,19 @@ final class TeaTest extends UnitTestCase
$this->subject = new Tea(); $this->subject = new Tea();
} }
/** #[Test]
* @test
*/
public function isAbstractEntity(): void public function isAbstractEntity(): void
{ {
self::assertInstanceOf(AbstractEntity::class, $this->subject); self::assertInstanceOf(AbstractEntity::class, $this->subject);
} }
/** #[Test]
* @test
*/
public function getTitleInitiallyReturnsEmptyString(): void public function getTitleInitiallyReturnsEmptyString(): void
{ {
self::assertSame('', $this->subject->getTitle()); self::assertSame('', $this->subject->getTitle());
} }
/** #[Test]
* @test
*/
public function setTitleSetsTitle(): void public function setTitleSetsTitle(): void
{ {
$value = 'Earl Grey'; $value = 'Earl Grey';
@ -50,17 +44,13 @@ final class TeaTest extends UnitTestCase
self::assertSame($value, $this->subject->getTitle()); self::assertSame($value, $this->subject->getTitle());
} }
/** #[Test]
* @test
*/
public function getDescriptionInitiallyReturnsEmptyString(): void public function getDescriptionInitiallyReturnsEmptyString(): void
{ {
self::assertSame('', $this->subject->getDescription()); self::assertSame('', $this->subject->getDescription());
} }
/** #[Test]
* @test
*/
public function setDescriptionSetsDescription(): void public function setDescriptionSetsDescription(): void
{ {
$value = 'Very refreshing and amoratic.'; $value = 'Very refreshing and amoratic.';
@ -69,17 +59,13 @@ final class TeaTest extends UnitTestCase
self::assertSame($value, $this->subject->getDescription()); self::assertSame($value, $this->subject->getDescription());
} }
/** #[Test]
* @test
*/
public function getImageInitiallyReturnsNull(): void public function getImageInitiallyReturnsNull(): void
{ {
self::assertNull($this->subject->getImage()); self::assertNull($this->subject->getImage());
} }
/** #[Test]
* @test
*/
public function setImageSetsImage(): void public function setImageSetsImage(): void
{ {
$model = new FileReference(); $model = new FileReference();
@ -88,17 +74,13 @@ final class TeaTest extends UnitTestCase
self::assertSame($model, $this->subject->getImage()); self::assertSame($model, $this->subject->getImage());
} }
/** #[Test]
* @test
*/
public function getOwnerUidInitiallyReturnsZero(): void public function getOwnerUidInitiallyReturnsZero(): void
{ {
self::assertSame(0, $this->subject->getOwnerUid()); self::assertSame(0, $this->subject->getOwnerUid());
} }
/** #[Test]
* @test
*/
public function setOwnerUidSetsOwnerUid(): void public function setOwnerUidSetsOwnerUid(): void
{ {
$value = 123456; $value = 123456;

View file

@ -47,7 +47,7 @@
"typo3/cms-frontend": "^12.4.26" "typo3/cms-frontend": "^12.4.26"
}, },
"require-dev": { "require-dev": {
"brianium/paratest": "6.11.1", "brianium/paratest": "7.3.1 || 7.4.8",
"ergebnis/composer-normalize": "2.45.0", "ergebnis/composer-normalize": "2.45.0",
"friendsofphp/php-cs-fixer": "3.68.5", "friendsofphp/php-cs-fixer": "3.68.5",
"helmich/typo3-typoscript-lint": "^3.3.0", "helmich/typo3-typoscript-lint": "^3.3.0",
@ -58,7 +58,7 @@
"phpstan/phpstan": "1.12.14", "phpstan/phpstan": "1.12.14",
"phpstan/phpstan-phpunit": "1.4.2", "phpstan/phpstan-phpunit": "1.4.2",
"phpstan/phpstan-strict-rules": "1.6.1", "phpstan/phpstan-strict-rules": "1.6.1",
"phpunit/phpunit": "9.6.22", "phpunit/phpunit": "10.5.31 || 10.5.44",
"saschaegerer/phpstan-typo3": "1.10.2", "saschaegerer/phpstan-typo3": "1.10.2",
"seld/jsonlint": "1.11.0", "seld/jsonlint": "1.11.0",
"spaze/phpstan-disallowed-calls": "4.2.1", "spaze/phpstan-disallowed-calls": "4.2.1",

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive"> <phive xmlns="https://phar.io/phive">
<phar name="phpcov" version="^8.2.1" installed="8.2.1" location="./tools/phpcov" copy="false"/> <phar name="phpcov" version="^9.0.2" installed="9.0.2" location="./tools/phpcov" copy="false"/>
</phive> </phive>

View file

@ -64,13 +64,7 @@ return RectorConfig::configure()
// PHPUnit sets // PHPUnit sets
// PHPUnitSetList::PHPUNIT80_DMS, // PHPUnitSetList::PHPUNIT80_DMS,
// PHPUnitSetList::PHPUNIT_40, PHPUnitSetList::PHPUNIT_100,
// PHPUnitSetList::PHPUNIT_50,
// PHPUnitSetList::PHPUNIT_60,
// PHPUnitSetList::PHPUNIT_70,
// PHPUnitSetList::PHPUNIT_80,
// PHPUnitSetList::PHPUNIT_90,
// PHPUnitSetList::PHPUNIT_100,
// PHPUnitSetList::PHPUNIT_CODE_QUALITY, // PHPUnitSetList::PHPUNIT_CODE_QUALITY,
// TYPO3 Sets // TYPO3 Sets