Skip to content

Commit

Permalink
Merge pull request #191 from lchrusciel/fix-backward-compatibility
Browse files Browse the repository at this point in the history
[BC] Bring back support for data providers for PHPUnit 9
  • Loading branch information
lchrusciel authored Oct 13, 2023
2 parents 09ebfd5 + cb63cc8 commit 5cc17d3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class ApiTestCase extends WebTestCase
/** @var string */
protected $dataFixturesPath;

/** @var MatcherFactory */
/** @var MatcherFactory|null */
protected $matcherFactory;

/** @var LoaderInterface|null */
Expand All @@ -50,13 +50,6 @@ abstract class ApiTestCase extends WebTestCase
/** @var EntityManager|null */
private $entityManager;

public function __construct(?string $name = null)
{
parent::__construct($name);

$this->matcherFactory = new MatcherFactory();
}

/**
* @beforeClass
*/
Expand Down Expand Up @@ -88,6 +81,14 @@ public function setUpClient(): void
$this->client = static::createClient(['debug' => false]);
}

/**
* @before
*/
public function createMatcher(): void
{
$this->matcherFactory = new MatcherFactory();
}

/**
* @before
*/
Expand Down
17 changes: 17 additions & 0 deletions test/src/Tests/Controller/SampleControllerJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ public function testGetHelloWorldResponse(): void
$this->assertResponse($response, 'hello_world');
}

/**
* @dataProvider provideTestData
*/
public function testGetHelloWorldResponseWithDataProvider(string $method): void
{
$this->client->request($method, '/');

$response = $this->client->getResponse();

$this->assertResponse($response, 'hello_world');
}

public static function provideTestData(): iterable
{
yield ['method' => 'GET'];
}

public function testGetHelloWorldResponseWithCharsetOnContentType(): void
{
$this->client->request('GET', '/', [], [], ['HTTP_ACCEPT' => 'application/json; charset=utf-8']);
Expand Down

0 comments on commit 5cc17d3

Please sign in to comment.