Migrate from PHPUnit annotations to native attributes

This commit is contained in:
Alejandro Celaya
2023-02-09 20:42:18 +01:00
parent 650a286982
commit 04bbd471ff
188 changed files with 776 additions and 1082 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\EmptyNotFoundRedirectConfig;
@@ -16,7 +17,7 @@ class EmptyNotFoundRedirectConfigTest extends TestCase
$this->redirectsConfig = new EmptyNotFoundRedirectConfig();
}
/** @test */
#[Test]
public function allMethodsReturnHardcodedValues(): void
{
self::assertNull($this->redirectsConfig->invalidShortUrlRedirect());

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\EnvVars;
@@ -23,10 +25,7 @@ class EnvVarsTest extends TestCase
putenv(EnvVars::DB_NAME->value . '=');
}
/**
* @test
* @dataProvider provideExistingEnvVars
*/
#[Test, DataProvider('provideExistingEnvVars')]
public function existsInEnvReturnsExpectedValue(EnvVars $envVar, bool $exists): void
{
self::assertEquals($exists, $envVar->existsInEnv());
@@ -40,10 +39,7 @@ class EnvVarsTest extends TestCase
yield 'DEFAULT_REGULAR_404_REDIRECT' => [EnvVars::DEFAULT_REGULAR_404_REDIRECT, false];
}
/**
* @test
* @dataProvider provideEnvVarsValues
*/
#[Test, DataProvider('provideEnvVarsValues')]
public function expectedValueIsLoadedFromEnv(EnvVars $envVar, mixed $expected, mixed $default): void
{
self::assertEquals($expected, $envVar->loadFromEnv($default));

View File

@@ -9,6 +9,8 @@ use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\Uri;
use Mezzio\Router\Route;
use Mezzio\Router\RouteResult;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
@@ -33,10 +35,7 @@ class NotFoundRedirectResolverTest extends TestCase
$this->resolver = new NotFoundRedirectResolver($this->helper, new NullLogger());
}
/**
* @test
* @dataProvider provideRedirects
*/
#[Test, DataProvider('provideRedirects')]
public function expectedRedirectionIsReturnedDependingOnTheCase(
UriInterface $uri,
NotFoundType $notFoundType,
@@ -113,7 +112,7 @@ class NotFoundRedirectResolverTest extends TestCase
];
}
/** @test */
#[Test]
public function noResponseIsReturnedIfNoConditionsMatch(): void
{
$notFoundType = self::notFoundType(self::requestForRoute('foo'));

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config\PostProcessor;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\PostProcessor\BasePathPrefixer;
@@ -16,10 +18,7 @@ class BasePathPrefixerTest extends TestCase
$this->prefixer = new BasePathPrefixer();
}
/**
* @test
* @dataProvider provideConfig
*/
#[Test, DataProvider('provideConfig')]
public function parsesConfigAsExpected(
array $originalConfig,
array $expectedRoutes,

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config\PostProcessor;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Config\PostProcessor\MultiSegmentSlugProcessor;
@@ -16,10 +18,7 @@ class MultiSegmentSlugProcessorTest extends TestCase
$this->processor = new MultiSegmentSlugProcessor();
}
/**
* @test
* @dataProvider provideConfigs
*/
#[Test, DataProvider('provideConfigs')]
public function parsesRoutesAsExpected(array $config, array $expectedRoutes): void
{
self::assertEquals($expectedRoutes, ($this->processor)($config)['routes'] ?? []);

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Config\PostProcessor;
use Mezzio\Router\Route;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Action\RedirectAction;
use Shlinkio\Shlink\Core\Config\PostProcessor\ShortUrlMethodsProcessor;
@@ -18,10 +20,7 @@ class ShortUrlMethodsProcessorTest extends TestCase
$this->processor = new ShortUrlMethodsProcessor();
}
/**
* @test
* @dataProvider provideConfigs
*/
#[Test, DataProvider('provideConfigs')]
public function onlyFirstRouteIdentifiedAsRedirectIsEditedWithProperAllowedMethods(
array $config,
?array $expectedRoutes,