Skip to content

Commit

Permalink
Merge pull request #571 from FriendsOfSymfony/phpunit-data-provider-a…
Browse files Browse the repository at this point in the history
…ttribute

convert annotations to attributes
  • Loading branch information
dbu authored Mar 28, 2024
2 parents e7106a6 + 64275fd commit f116f61
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 27 deletions.
5 changes: 2 additions & 3 deletions tests/Unit/CacheInvalidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Http\Client\Exception\NetworkException;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Mockery\MockInterface;
use PHPUnit\Framework\Attributes as PHPUnit;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -168,9 +169,7 @@ public static function provideOperations(): iterable
];
}

/**
* @dataProvider provideOperations
*/
#[PHPUnit\DataProvider('provideOperations')]
public function testMethodException(string $method, $arg): void
{
/** @var MockInterface&ProxyClient $proxyClient */
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/ProxyClient/HttpDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Http\Mock\Client;
use Http\Promise\Promise;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\Attributes as PHPUnit;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
Expand All @@ -49,12 +50,11 @@ protected function setUp(): void
}

/**
* @dataProvider exceptionProvider
*
* @param \Exception $exception Exception thrown by HTTP client
* @param string $type The returned exception class to be expected
* @param string|null $message Optional exception message to match against
*/
#[PHPUnit\DataProvider('exceptionProvider')]
public function testExceptions(\Exception $exception, string $type, ?string $message = null): void
{
$this->doTestException($exception, $type, $message);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/ProxyClient/MultiplexerClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use FOS\HttpCache\ProxyClient\MultiplexerClient;
use FOS\HttpCache\ProxyClient\ProxyClient;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\Attributes as PHPUnit;
use PHPUnit\Framework\TestCase;

class MultiplexerClientTest extends TestCase
Expand Down Expand Up @@ -173,9 +174,8 @@ public static function provideInvalidClient(): array

/**
* @param ProxyClient[] $clients
*
* @dataProvider provideInvalidClient
*/
#[PHPUnit\DataProvider('provideInvalidClient')]
public function testInvalidClientTest(array $clients): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down
21 changes: 6 additions & 15 deletions tests/Unit/SymfonyCache/UserContextListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use FOS\HttpCache\SymfonyCache\UserContextListener;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Mockery\MockInterface;
use PHPUnit\Framework\Attributes as PHPUnit;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -55,9 +56,7 @@ public static function provideConfigOptions(): array
];
}

/**
* @dataProvider provideConfigOptions
*/
#[PHPUnit\DataProvider('provideConfigOptions')]
public function testGenerateUserHashNotAllowed(array $arg, array $options): void
{
$userContextListener = new UserContextListener($arg);
Expand All @@ -74,9 +73,7 @@ public function testGenerateUserHashNotAllowed(array $arg, array $options): void
$this->assertSame('Bad Request', $response->getContent());
}

/**
* @dataProvider provideConfigOptions
*/
#[PHPUnit\DataProvider('provideConfigOptions')]
public function testPassingUserHashNotAllowed(array $arg, array $options): void
{
$userContextListener = new UserContextListener($arg);
Expand All @@ -93,9 +90,7 @@ public function testPassingUserHashNotAllowed(array $arg, array $options): void
$this->assertSame('Bad Request', $response->getContent());
}

/**
* @dataProvider provideConfigOptions
*/
#[PHPUnit\DataProvider('provideConfigOptions')]
public function testUserHashAnonymous(array $arg, array $options): void
{
$userContextListener = new UserContextListener($arg);
Expand Down Expand Up @@ -160,9 +155,7 @@ static function (Request $request) use ($that, $hashRequest) {
$this->assertNull($response);
}

/**
* @dataProvider provideConfigOptions
*/
#[PHPUnit\DataProvider('provideConfigOptions')]
public function testUserHashUserWithSession(array $arg, array $options): void
{
$userContextListener = new UserContextListener($arg);
Expand Down Expand Up @@ -256,9 +249,7 @@ public function testUserHashUserIgnoreCookies(): void
$this->assertSame('38015b703d82206ebc01d17a39c727e5', $request->headers->get('X-User-Context-Hash'));
}

/**
* @dataProvider provideConfigOptions
*/
#[PHPUnit\DataProvider('provideConfigOptions')]
public function testUserHashUserWithAuthorizationHeader(array $arg, array $options): void
{
$userContextListener = new UserContextListener($arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use FOS\HttpCache\Exception\InvalidTagException;
use FOS\HttpCache\TagHeaderFormatter\CommaSeparatedTagHeaderFormatter;
use FOS\HttpCache\TagHeaderFormatter\MaxHeaderValueLengthFormatter;
use PHPUnit\Framework\Attributes as PHPUnit;
use PHPUnit\Framework\TestCase;

class MaxHeaderValueLengthFormatterTest extends TestCase
Expand All @@ -33,10 +34,9 @@ public function testNotTooLong(): void
}

/**
* @dataProvider tooLongProvider
*
* @param string[] $tags
*/
#[PHPUnit\DataProvider('tooLongProvider')]
public function testTooLong(int $maxLength, array $tags, string|array $expectedHeaderValue): void
{
$formatter = $this->getFormatter($maxLength);
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/Test/Proxy/VarnishProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FOS\HttpCache\Tests\Unit\Test\Proxy;

use FOS\HttpCache\Test\Proxy\VarnishProxy;
use PHPUnit\Framework\Attributes as PHPUnit;
use PHPUnit\Framework\TestCase;

class VarnishProxyTest extends TestCase
Expand All @@ -29,9 +30,7 @@ public static function allowInlineFlagProvider(): array
return [[true], [false]];
}

/**
* @dataProvider allowInlineFlagProvider
*/
#[PHPUnit\DataProvider('allowInlineFlagProvider')]
public function testStart(bool $inlineC): void
{
$proxy = new VarnishProxyMock('config.vcl');
Expand Down

0 comments on commit f116f61

Please sign in to comment.