Migrated phpunit annotations to attributes

This commit is contained in:
Jan Böhmer 2025-07-14 00:32:06 +02:00
parent f1d34bbc24
commit dc480f755c
50 changed files with 171 additions and 246 deletions

View file

@ -22,6 +22,8 @@ declare(strict_types=1);
namespace App\Tests\Entity\Attachments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\AttachmentTypeAttachment;
@ -89,9 +91,7 @@ class AttachmentTest extends TestCase
yield [UserAttachment::class, User::class];
}
/**
* @dataProvider subClassesDataProvider
*/
#[DataProvider('subClassesDataProvider')]
public function testSetElement(string $attachment_class, string $allowed_class): void
{
/** @var Attachment $attachment */
@ -106,10 +106,9 @@ class AttachmentTest extends TestCase
/**
* Test that all attachment subclasses like PartAttachment or similar returns an exception, when a not allowed
* element is passed.
*
* @dataProvider subClassesDataProvider
* @depends testSetElement
*/
#[Depends('testSetElement')]
#[DataProvider('subClassesDataProvider')]
public function testSetElementExceptionOnSubClasses(string $attachment_class, string $allowed_class): void
{
$this->expectException(InvalidArgumentException::class);
@ -135,9 +134,7 @@ class AttachmentTest extends TestCase
yield [null, 'test.txt', null, null];
}
/**
* @dataProvider extensionDataProvider
*/
#[DataProvider('extensionDataProvider')]
public function testGetExtension(?string $internal_path, ?string $external_path, ?string $originalFilename, ?string $expected): void
{
$attachment = new PartAttachment();
@ -162,9 +159,7 @@ class AttachmentTest extends TestCase
yield ['%SECURE%/foo.txt/test', 'https://test.de/picture.jpeg', false];
}
/**
* @dataProvider pictureDataProvider
*/
#[DataProvider('pictureDataProvider')]
public function testIsPicture(?string $internal_path, ?string $external_path, bool $expected): void
{
$attachment = new PartAttachment();
@ -184,9 +179,7 @@ class AttachmentTest extends TestCase
yield ['%FOOTPRINTS%/foo/bar.txt', true];
}
/**
* @dataProvider builtinDataProvider
*/
#[DataProvider('builtinDataProvider')]
public function testIsBuiltIn(?string $path, $expected): void
{
$attachment = new PartAttachment();
@ -201,9 +194,7 @@ class AttachmentTest extends TestCase
yield ['https://foo.bar/test?txt=test', 'foo.bar'];
}
/**
* @dataProvider hostDataProvider
*/
#[DataProvider('hostDataProvider')]
public function testGetHost(?string $path, ?string $expected): void
{
$attachment = new PartAttachment();
@ -219,9 +210,7 @@ class AttachmentTest extends TestCase
yield [null, 'https://www.google.de/test.txt', null, null];
}
/**
* @dataProvider filenameProvider
*/
#[DataProvider('filenameProvider')]
public function testGetFilename(?string $internal_path, ?string $external_path, ?string $original_filename, ?string $expected): void
{
$attachment = new PartAttachment();

View file

@ -41,6 +41,7 @@ declare(strict_types=1);
namespace App\Tests\Entity\Parameters;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Parameters\PartParameter;
use PHPUnit\Framework\TestCase;
@ -80,9 +81,7 @@ class PartParameterTest extends TestCase
yield ['10.23 $\mathrm{V}$ (9 $\mathrm{V}$ ... 11 $\mathrm{V}$) [Test]', 9, 10.23, 11, 'V', 'Test'];
}
/**
* @dataProvider valueWithUnitDataProvider
*/
#[DataProvider('valueWithUnitDataProvider')]
public function testGetValueMinWithUnit(string $expected, float $value, string $unit): void
{
$param = new PartParameter();
@ -91,9 +90,7 @@ class PartParameterTest extends TestCase
$this->assertSame($expected, $param->getValueMinWithUnit());
}
/**
* @dataProvider valueWithUnitDataProvider
*/
#[DataProvider('valueWithUnitDataProvider')]
public function testGetValueMaxWithUnit(string $expected, float $value, string $unit): void
{
$param = new PartParameter();
@ -102,9 +99,7 @@ class PartParameterTest extends TestCase
$this->assertSame($expected, $param->getValueMaxWithUnit());
}
/**
* @dataProvider valueWithUnitDataProvider
*/
#[DataProvider('valueWithUnitDataProvider')]
public function testGetValueTypicalWithUnit(string $expected, float $value, string $unit): void
{
$param = new PartParameter();
@ -114,12 +109,12 @@ class PartParameterTest extends TestCase
}
/**
* @dataProvider formattedValueDataProvider
*
* @param float $min
* @param float $typical
* @param float $max
*/
#[DataProvider('formattedValueDataProvider')]
public function testGetFormattedValue(string $expected, ?float $min, ?float $typical, ?float $max, string $unit, string $text): void
{
$param = new PartParameter();
@ -132,12 +127,12 @@ class PartParameterTest extends TestCase
}
/**
* @dataProvider formattedValueWithLatexDataProvider
*
* @param float $min
* @param float $typical
* @param float $max
*/
#[DataProvider('formattedValueWithLatexDataProvider')]
public function testGetFormattedValueWithLatex(string $expected, ?float $min, ?float $typical, ?float $max, string $unit, string $text): void
{
$param = new PartParameter();

View file

@ -22,6 +22,8 @@ declare(strict_types=1);
namespace App\Tests\Entity\UserSystem;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresPhpunit;
use App\Entity\UserSystem\User;
use App\Entity\UserSystem\WebauthnKey;
use Doctrine\Common\Collections\Collection;
@ -52,9 +54,7 @@ class UserTest extends TestCase
yield ['SSSk38498', true];
}
/**
* @dataProvider googleAuthenticatorEnabledDataProvider
*/
#[DataProvider('googleAuthenticatorEnabledDataProvider')]
public function testIsGoogleAuthenticatorEnabled(?string $secret, bool $expected): void
{
$user = new User();
@ -62,9 +62,7 @@ class UserTest extends TestCase
$this->assertSame($expected, $user->isGoogleAuthenticatorEnabled());
}
/**
* @requires PHPUnit 8
*/
#[RequiresPhpunit('8')]
public function testSetBackupCodes(): void
{
$user = new User();