Skip to content

Commit

Permalink
[TASK] Use PHPUnit attributes instead of annotations
Browse files Browse the repository at this point in the history
This change modifies the tests to use the php
attributes provided by PHPUnit instead of the
old php doc-block annotations.

Used command(s):

```bash
Build/Scripts/runTests.sh -t 12 -p 8.1 -s phpstanGenerateBaseline
```
  • Loading branch information
sbuerk committed Dec 11, 2024
1 parent 3663ad4 commit 4f6b41a
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 221 deletions.
10 changes: 0 additions & 10 deletions Build/phpstan/Core12/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ parameters:
count: 1
path: ../../../Classes/Event/Listener/GlossarySyncButtonProvider.php

-
message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Form\\\\Item\\\\SiteConfigSupportedLanguageItemsProcFunc\\:\\:getSupportedLanguageForField\\(\\) has no return type specified\\.$#"
count: 1
path: ../../../Classes/Form/Item/SiteConfigSupportedLanguageItemsProcFunc.php

-
message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Form\\\\Item\\\\SiteConfigSupportedLanguageItemsProcFunc\\:\\:getSupportedLanguageForField\\(\\) has parameter \\$configuration with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -95,11 +90,6 @@ parameters:
count: 1
path: ../../../Classes/Hooks/Glossary/UpdatedGlossaryEntryTermHook.php

-
message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Hooks\\\\TCEmainHook\\:\\:checkModifyAccessList\\(\\) has no return type specified\\.$#"
count: 1
path: ../../../Classes/Hooks/TCEmainHook.php

-
message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Override\\\\Core12\\\\DatabaseRecordList\\:\\:makeLocalizationPanel\\(\\) has parameter \\$translations with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
17 changes: 10 additions & 7 deletions Tests/Functional/AbstractDeepLTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace WebVision\Deepltranslate\Core\Tests\Functional;

use RuntimeException;
use Closure;
use Exception;
use DeepL\Translator;
use DeepL\TranslatorOptions;
use phpmock\phpunit\PHPMock;
Expand Down Expand Up @@ -123,14 +126,14 @@ protected function setUp(): void
if ($this->isMockServer) {
$this->authKey = 'mock_server';
if ($this->serverUrl === false) {
throw new \RuntimeException(
throw new RuntimeException(
'DEEPL_SERVER_URL environment variable must be set if using a mock server',
1733938285,
);
}
} else {
if (getenv('DEEPL_AUTH_KEY') === false) {
throw new \RuntimeException(
throw new RuntimeException(
'DEEPL_AUTH_KEY environment variable must be set unless using a mock server',
1733938290,
);
Expand Down Expand Up @@ -207,7 +210,7 @@ protected function instantiateMockServerClient(array $options = []): void

// use closure to set private option for translation
$translator = new Translator(self::getInstanceIdentifier(), $mergedOptions);
\Closure::bind(
Closure::bind(
function (Translator $translator) {
$this->translator = $translator;
},
Expand Down Expand Up @@ -262,11 +265,11 @@ public function tempFiles(): array
return [$tempDir, $exampleDocument, $exampleLargeDocument, $outputDocumentPath];
}

public function assertExceptionContains(string $needle, callable $function): \Exception
public function assertExceptionContains(string $needle, callable $function): Exception
{
try {
$function();
} catch (\Exception $exception) {
} catch (Exception $exception) {
static::assertStringContainsString($needle, $exception->getMessage());
return $exception;
}
Expand All @@ -276,11 +279,11 @@ public function assertExceptionContains(string $needle, callable $function): \Ex
/**
* @param class-string $class
*/
public function assertExceptionClass(string $class, callable $function): \Exception
public function assertExceptionClass(string $class, callable $function): Exception
{
try {
$function();
} catch (\Exception $exception) {
} catch (Exception $exception) {
static::assertEquals($class, get_class($exception));
return $exception;
}
Expand Down
42 changes: 14 additions & 28 deletions Tests/Functional/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace WebVision\Deepltranslate\Core\Tests\Functional;

use PHPUnit\Framework\Attributes\CoversClass;
use WebVision\Deepltranslate\Core\Client;
use PHPUnit\Framework\Attributes\Test;
use DateTime;
use DeepL\GlossaryEntries;
use DeepL\GlossaryInfo;
use DeepL\GlossaryLanguagePair;
Expand All @@ -12,9 +16,7 @@
use Helmich\JsonAssert\JsonAssertions;
use WebVision\Deepltranslate\Core\ClientInterface;

/**
* @covers \WebVision\Deepltranslate\Core\Client
*/
#[CoversClass(Client::class)]
final class ClientTest extends AbstractDeepLTestCase
{
use JsonAssertions;
Expand All @@ -28,9 +30,7 @@ protected function setUp(): void
parent::setUp();
}

/**
* @test
*/
#[Test]
public function checkResponseFromTranslateContent(): void
{
$translateContent = self::EXAMPLE_TEXT['en'];
Expand All @@ -45,9 +45,7 @@ public function checkResponseFromTranslateContent(): void
static::assertSame(self::EXAMPLE_TEXT['de'], $response->text);
}

/**
* @test
*/
#[Test]
public function checkResponseFromSupportedTargetLanguage(): void
{
$client = $this->get(ClientInterface::class);
Expand All @@ -57,9 +55,7 @@ public function checkResponseFromSupportedTargetLanguage(): void
static::assertContainsOnlyInstancesOf(Language::class, $response);
}

/**
* @test
*/
#[Test]
public function checkResponseFromGlossaryLanguagePairs(): void
{
$client = $this->get(ClientInterface::class);
Expand All @@ -69,9 +65,7 @@ public function checkResponseFromGlossaryLanguagePairs(): void
static::assertContainsOnlyInstancesOf(GlossaryLanguagePair::class, $response);
}

/**
* @test
*/
#[Test]
public function checkResponseFromCreateGlossary(): void
{
$client = $this->get(ClientInterface::class);
Expand All @@ -90,12 +84,10 @@ public function checkResponseFromCreateGlossary(): void
static::assertInstanceOf(GlossaryInfo::class, $response);
static::assertSame(1, $response->entryCount);
static::assertIsString($response->glossaryId);
static::assertInstanceOf(\DateTime::class, $response->creationTime);
static::assertInstanceOf(DateTime::class, $response->creationTime);
}

/**
* @test
*/
#[Test]
public function checkResponseGetAllGlossaries(): void
{
$client = $this->get(ClientInterface::class);
Expand All @@ -105,9 +97,7 @@ public function checkResponseGetAllGlossaries(): void
static::assertContainsOnlyInstancesOf(GlossaryInfo::class, $response);
}

/**
* @test
*/
#[Test]
public function checkResponseFromGetGlossary(): void
{
$client = $this->get(ClientInterface::class);
Expand All @@ -130,9 +120,7 @@ public function checkResponseFromGetGlossary(): void
static::assertSame(1, $response->entryCount);
}

/**
* @test
*/
#[Test]
public function checkGlossaryDeletedNotCatchable(): void
{
$client = $this->get(ClientInterface::class);
Expand All @@ -155,9 +143,7 @@ public function checkGlossaryDeletedNotCatchable(): void
static::assertNull($client->getGlossary($glossaryId));
}

/**
* @test
*/
#[Test]
public function checkResponseFromGetGlossaryEntries(): void
{
$client = $this->get(ClientInterface::class);
Expand Down
12 changes: 7 additions & 5 deletions Tests/Functional/Fixtures/Traits/SiteBasedTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WebVision\Deepltranslate\Core\Tests\Functional\Fixtures\Traits;

use Exception;
use LogicException;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Configuration\SiteConfiguration;
use TYPO3\CMS\Core\Information\Typo3Version;
Expand Down Expand Up @@ -58,7 +60,7 @@ protected function writeSiteConfiguration(
// ensure no previous site configuration influences the test
GeneralUtility::rmdir($this->instancePath . '/typo3conf/sites/' . $identifier, true);
$siteConfiguration->write($identifier, $configuration);
} catch (\Exception $exception) {
} catch (Exception $exception) {
$this->markTestSkipped($exception->getMessage());
}
}
Expand All @@ -72,7 +74,7 @@ protected function mergeSiteConfiguration(
$configuration = array_merge($configuration, $overrides);
try {
$siteConfiguration->write($identifier, $configuration);
} catch (\Exception $exception) {
} catch (Exception $exception) {
$this->markTestSkipped($exception->getMessage());
}
}
Expand Down Expand Up @@ -206,7 +208,7 @@ protected function buildErrorHandlingConfiguration(
'errorPhpClassFQCN' => PhpError::class,
];
} else {
throw new \LogicException(
throw new LogicException(
sprintf('Invalid handler "%s"', $handler),
1533894782
);
Expand All @@ -229,7 +231,7 @@ static function (int $code) use ($baseConfiguration) {
protected function resolveLanguagePreset(string $identifier)
{
if (!isset(static::LANGUAGE_PRESETS[$identifier])) {
throw new \LogicException(
throw new LogicException(
sprintf('Undefined preset identifier "%s"', $identifier),
1533893665
);
Expand Down Expand Up @@ -262,7 +264,7 @@ protected function applyInstructions(InternalRequest $request, AbstractInstructi
protected function mergeInstruction(AbstractInstruction $current, AbstractInstruction $other): AbstractInstruction
{
if (get_class($current) !== get_class($other)) {
throw new \LogicException('Cannot merge different instruction types', 1565863174);
throw new LogicException('Cannot merge different instruction types', 1565863174);
}

if ($current instanceof TypoScriptInstruction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace WebVision\Deepltranslate\Core\Tests\Functional\Form\Items;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use WebVision\Deepltranslate\Core\Form\Item\SiteConfigSupportedLanguageItemsProcFunc;
use WebVision\Deepltranslate\Core\Tests\Functional\AbstractDeepLTestCase;

/**
* @covers \WebVision\Deepltranslate\Core\Form\Item\SiteConfigSupportedLanguageItemsProcFunc
*/
#[CoversClass(SiteConfigSupportedLanguageItemsProcFunc::class)]
final class SiteConfigSupportedLanguageItemsProcFuncTest extends AbstractDeepLTestCase
{
protected function setUp(): void
Expand All @@ -23,9 +23,7 @@ protected function setUp(): void
parent::setUp();
}

/**
* @test
*/
#[Test]
public function getSupportedLanguageFormFields(): void
{
$func = GeneralUtility::makeInstance(SiteConfigSupportedLanguageItemsProcFunc::class);
Expand Down
22 changes: 7 additions & 15 deletions Tests/Functional/Form/User/HasFormalitySupportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace WebVision\Deepltranslate\Core\Tests\Functional\Form\User;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Backend\Form\FormDataProvider\EvaluateDisplayConditions;
use WebVision\Deepltranslate\Core\Form\User\HasFormalitySupport;
use WebVision\Deepltranslate\Core\Tests\Functional\AbstractDeepLTestCase;

/**
* @covers \WebVision\Deepltranslate\Core\Form\User\HasFormalitySupport
*/
#[CoversClass(HasFormalitySupport::class)]
class HasFormalitySupportTest extends AbstractDeepLTestCase
{
protected function setUp(): void
Expand All @@ -23,9 +23,7 @@ protected function setUp(): void
parent::setUp();
}

/**
* @test
*/
#[Test]
public function hasFormalitySupportIsSupported(): void
{
/** @var HasFormalitySupport $subject */
Expand All @@ -43,9 +41,7 @@ public function hasFormalitySupportIsSupported(): void
static::assertTrue($isFormalitySupported);
}

/**
* @test
*/
#[Test]
public function hasFormalitySupportIsNotSupported(): void
{
/** @var HasFormalitySupport $subject */
Expand All @@ -63,9 +59,7 @@ public function hasFormalitySupportIsNotSupported(): void
static::assertFalse($isFormalitySupported);
}

/**
* @test
*/
#[Test]
public function formalityIsNotSupportedWhenRecordNotExist(): void
{
/** @var HasFormalitySupport $subject */
Expand All @@ -77,9 +71,7 @@ public function formalityIsNotSupportedWhenRecordNotExist(): void
static::assertFalse($isFormalitySupported);
}

/**
* @test
*/
#[Test]
public function formalityIsNotSupportedWhenDeeplTargetLanguageNotExistOrEmpty(): void
{
/** @var HasFormalitySupport $subject */
Expand Down
13 changes: 4 additions & 9 deletions Tests/Functional/Hooks/ButtonBarHookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WebVision\Deepltranslate\Core\Tests\Functional\Hooks;

use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\Buttons\LinkButton;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
Expand Down Expand Up @@ -33,9 +34,7 @@ public function setUp(): void

}

/**
* @test
*/
#[Test]
public function showGlossarySynchronizationButton(): void
{
// User with Access
Expand All @@ -54,9 +53,7 @@ public function showGlossarySynchronizationButton(): void
static::assertInstanceOf(LinkButton::class, $button);
}

/**
* @test
*/
#[Test]
public function displayGlossarySynchronizationButtonBecauseNotRightModel(): void
{
// Backend-Admin User
Expand All @@ -70,9 +67,7 @@ public function displayGlossarySynchronizationButtonBecauseNotRightModel(): void
static::assertFalse(isset($buttons[ButtonBar::BUTTON_POSITION_LEFT][5]));
}

/**
* @test
*/
#[Test]
public function displayGlossarySynchronizationButtonBecauseNotAllowed(): void
{
// Backend-Admin User
Expand Down
Loading

0 comments on commit 4f6b41a

Please sign in to comment.