Skip to content

Commit

Permalink
support for PHPUnit 10
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Ešler committed Mar 23, 2023
1 parent 44d08ed commit 32c684d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
}
],
"require": {
"php": ">=8.0",
"phpunit/phpunit": "^7.0||^8.0||^9.0",
"symfony/yaml": "^4.0||^5.0||^6.0"
"php": ">=8.1",
"phpunit/phpunit": "^10.0",
"symfony/yaml": "^6.0"
},
"suggest": {
"elasticsearch/elasticsearch" : "Needed to support Elasticsearch",
Expand Down
10 changes: 5 additions & 5 deletions src/DbFixturesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PDO;
use stdClass;
use Symfony\Component\Yaml\Yaml;
use PHPUnit\Util\Test;
use PHPUnit\Metadata\Annotation\Parser\Registry;

const AVAILABLE_MODES = ['read-only', 'write'];

Expand Down Expand Up @@ -37,13 +37,13 @@ abstract protected function getConnection(string $connectionName) : mixed;
* @before
*/
public function loadFixturesByAnnotations(): void {
$annotations = Test::parseTestMethodAnnotations(
$annotations = Registry::getInstance()->forMethod(
static::class,
$this->getName(false)
);
$this->name()
)->symbolAnnotations();

$fixtures = [];
foreach ($annotations['method']['fixtures'] ?? [] as $fixture) {
foreach ($annotations['fixtures'] ?? [] as $fixture) {
[$connectionName, $mode, $args] = \explode(' ', $fixture, 3) + [null, null, null];

if (!in_array($mode, AVAILABLE_MODES)) {
Expand Down
22 changes: 15 additions & 7 deletions tests/UsageOfDbFixturesTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ public function provideConnections(): \Generator {
* @fixtures sqlite read-only bds.yml
* @fixtures mysql read-only bds.yml
*
* @dataProvider provideConnections
* @requires @requires PHP >= 8.1
* @testWith ["mysql"]
* ["sqlite"]
*/
public function testBds(\PDO $connection): void {
public function testBds(string $connectionName): void {
$connection = $this->getConnection($connectionName);

$stmt = $connection->query('SELECT * FROM demo');
$demo = $stmt->fetchAll(\PDO::FETCH_ASSOC);

Expand Down Expand Up @@ -123,9 +125,12 @@ public function testBdsMongo(): void {
* @fixtures sqlite read-only bds.yml fixtures.yml fixtures.yaml
* @fixtures mysql read-only bds.yml fixtures.yml fixtures.yaml
*
* @dataProvider provideConnections
* @testWith ["mysql"]
* ["sqlite"]
*/
public function testLoadingFixtures(\PDO $connection): void {
public function testLoadingFixtures(string $connectionName): void {
$connection = $this->getConnection($connectionName);

$stmt = $connection->query('SELECT username FROM demo');
$demo = $stmt->fetchAll(\PDO::FETCH_ASSOC);

Expand Down Expand Up @@ -222,9 +227,12 @@ public function testErrorInFixturesWithMongo() {
}

/**
* @dataProvider provideConnections
* @testWith ["mysql"]
* ["sqlite"]
*/
function testBinaryFixturesSqlite(\PDO $pdo) {
function testBinaryFixturesSqlite(string $connectionName) {
$pdo = $this->getConnection($connectionName);

$connectionName = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);

$this->loadFixtures(
Expand Down

0 comments on commit 32c684d

Please sign in to comment.