Skip to content

Commit

Permalink
Do not skip tests from within data providers
Browse files Browse the repository at this point in the history
PHPUnit 10 does not allow data providers to throw any exceptions.
  • Loading branch information
morozov committed Jun 14, 2023
1 parent 769b31d commit 5716a6a
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 151 deletions.
19 changes: 0 additions & 19 deletions tests/Driver/AbstractDB2DriverTestCase.php
Expand Up @@ -6,7 +6,6 @@
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
use Doctrine\DBAL\Driver\API\IBMDB2\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2111Platform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\DB2SchemaManager;
Expand All @@ -31,22 +30,4 @@ protected function createExceptionConverter(): ExceptionConverterInterface
{
return new ExceptionConverter();
}

/**
* {@inheritDoc}
*/
public function getDatabasePlatformsForVersions(): array
{
return [
['10.1.0', DB2Platform::class, 'https://github.com/doctrine/dbal/pull/5156', true],
['10.1.0.0', DB2Platform::class, 'https://github.com/doctrine/dbal/pull/5156', true],
['DB2/LINUXX8664 10.1.0.0', DB2Platform::class, 'https://github.com/doctrine/dbal/pull/5156', true],
['11.1.0', DB2111Platform::class],
['11.1.0.0', DB2111Platform::class],
['DB2/LINUXX8664 11.1.0.0', DB2111Platform::class],
['11.5.8', DB2111Platform::class],
['11.5.8.0', DB2111Platform::class],
['DB2/LINUXX8664 11.5.8.0', DB2111Platform::class],
];
}
}
56 changes: 0 additions & 56 deletions tests/Driver/AbstractDriverTestCase.php
Expand Up @@ -14,9 +14,6 @@
use PHPUnit\Framework\TestCase;
use ReflectionProperty;

use function get_class;
use function sprintf;

/** @template P of AbstractPlatform */
abstract class AbstractDriverTestCase extends TestCase
{
Expand All @@ -32,59 +29,6 @@ protected function setUp(): void
$this->driver = $this->createDriver();
}

public function testVersionAwarePlatformCreationIsTested(): void
{
if (! $this->driver instanceof VersionAwarePlatformDriver) {
self::markTestSkipped('This test is only intended for version aware platform drivers.');
}

self::assertNotEmpty(
static::getDatabasePlatformsForVersions(),
sprintf(
'No test data found for test %s. You have to return test data from %s.',
static::class . '::' . __FUNCTION__,
static::class . '::getDatabasePlatformsForVersions',
),
);
}

/**
* @param class-string<AbstractPlatform> $expectedPlatformClass
*
* @dataProvider getDatabasePlatformsForVersions
*/
public function testCreatesDatabasePlatformForVersion(
string $version,
string $expectedPlatformClass,
?string $deprecation = null,
?bool $expectDeprecation = null
): void {
if (! $this->driver instanceof VersionAwarePlatformDriver) {
self::markTestSkipped('This test is only intended for version aware platform drivers.');
}

if ($deprecation !== null) {
if ($expectDeprecation ?? true) {
$this->expectDeprecationWithIdentifier($deprecation);
} else {
$this->expectNoDeprecationWithIdentifier($deprecation);
}
}

$actualPlatform = $this->driver->createDatabasePlatformForVersion($version);

self::assertInstanceOf(
$expectedPlatformClass,
$actualPlatform,
sprintf(
'Expected platform for version "%s" should be "%s", "%s" given',
$version,
$expectedPlatformClass,
get_class($actualPlatform),
),
);
}

public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion(): void
{
if (! $this->driver instanceof VersionAwarePlatformDriver) {
Expand Down
52 changes: 0 additions & 52 deletions tests/Driver/AbstractMySQLDriverTestCase.php
Expand Up @@ -6,10 +6,6 @@
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\MySQL;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MariaDb1052Platform;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\MySQLSchemaManager;
Expand All @@ -34,52 +30,4 @@ protected function createExceptionConverter(): ExceptionConverter
{
return new MySQL\ExceptionConverter();
}

/**
* {@inheritDoc}
*/
public function getDatabasePlatformsForVersions(): array
{
return [
['5.6.9', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.7', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
['5.7.0', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.7.8', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.7.9', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.7.10', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['8', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
['8.0', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
['8.0.11', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['6', MySQL57Platform::class],
['10.0.15-MariaDB-1~wheezy', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.5.5-10.1.25-MariaDB', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['10.1.2a-MariaDB-a1~lenny-log', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.5.40-MariaDB-1~wheezy', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
[
'5.5.5-MariaDB-10.2.8+maria~xenial-log',
MariaDb1027Platform::class,
'https://github.com/doctrine/dbal/pull/5779',
false,
],
[
'10.2.8-MariaDB-10.2.8+maria~xenial-log',
MariaDb1027Platform::class,
'https://github.com/doctrine/dbal/pull/5779',
false,
],
[
'10.2.8-MariaDB-1~lenny-log',
MariaDb1027Platform::class,
'https://github.com/doctrine/dbal/pull/5779',
false,
],
['mariadb-10.9.3',MariaDb1052Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
[
'10.5.2-MariaDB-1~lenny-log',
MariaDb1052Platform::class,
'https://github.com/doctrine/dbal/pull/5779',
false,
],
];
}
}
14 changes: 0 additions & 14 deletions tests/Driver/AbstractPostgreSQLDriverTestCase.php
Expand Up @@ -6,7 +6,6 @@
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\PostgreSQL;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
Expand All @@ -32,17 +31,4 @@ protected function createExceptionConverter(): ExceptionConverter
{
return new PostgreSQL\ExceptionConverter();
}

/**
* {@inheritDoc}
*/
public function getDatabasePlatformsForVersions(): array
{
return [
['9.4', PostgreSQL94Platform::class],
['9.4.0', PostgreSQL94Platform::class],
['9.4.1', PostgreSQL94Platform::class],
['10', PostgreSQL100Platform::class],
];
}
}
10 changes: 0 additions & 10 deletions tests/Driver/AbstractSQLServerDriverTestCase.php
Expand Up @@ -33,16 +33,6 @@ protected function createExceptionConverter(): ExceptionConverterInterface
return new ExceptionConverter();
}

/**
* {@inheritDoc}
*/
public function getDatabasePlatformsForVersions(): array
{
return [
['12', SQLServer2012Platform::class],
];
}

public function testPortWithoutHost(): void
{
$this->expectException(PortWithoutHost::class);
Expand Down
150 changes: 150 additions & 0 deletions tests/Driver/VersionAwarePlatformDriverTest.php
@@ -0,0 +1,150 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Tests\Driver;

use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2111Platform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MariaDb1052Platform;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use PHPUnit\Framework\TestCase;

use function get_class;

class VersionAwarePlatformDriverTest extends TestCase
{
use VerifyDeprecations;

/** @dataProvider mySQLVersionProvider */
public function testMySQLi(string $version, string $expectedClass): void
{
$this->assertDriverInstantiatesDatabasePlatform(new Driver\Mysqli\Driver(), $version, $expectedClass);
}

/** @dataProvider mySQLVersionProvider */
public function testPDOMySQL(string $version, string $expectedClass): void
{
$this->assertDriverInstantiatesDatabasePlatform(new Driver\PDO\MySQL\Driver(), $version, $expectedClass);
}

/** @return array<array{0: string, 1: class-string<AbstractPlatform>, 2?: string, 3?: bool}> */
public static function mySQLVersionProvider(): array
{
return [
['5.6.9', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.7', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
['5.7.0', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.7.8', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.7.9', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.7.10', MySQL57Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['8', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
['8.0', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
['8.0.11', MySQL80Platform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['6', MySQL57Platform::class],
['10.0.15-MariaDB-1~wheezy', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.5.5-10.1.25-MariaDB', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['10.1.2a-MariaDB-a1~lenny-log', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
['5.5.40-MariaDB-1~wheezy', MySQLPlatform::class, 'https://github.com/doctrine/dbal/pull/5779', false],
[
'5.5.5-MariaDB-10.2.8+maria~xenial-log',
MariaDb1027Platform::class,
'https://github.com/doctrine/dbal/pull/5779',
false,
],
[
'10.2.8-MariaDB-10.2.8+maria~xenial-log',
MariaDb1027Platform::class,
'https://github.com/doctrine/dbal/pull/5779',
false,
],
[
'10.2.8-MariaDB-1~lenny-log',
MariaDb1027Platform::class,
'https://github.com/doctrine/dbal/pull/5779',
false,
],
['mariadb-10.9.3', MariaDB1052Platform::class, 'https://github.com/doctrine/dbal/pull/5779', true],
[
'10.5.2-MariaDB-1~lenny-log',
MariaDB1052Platform::class,
'https://github.com/doctrine/dbal/pull/5779',
false,
],
];
}

/** @dataProvider postgreSQLVersionProvider */
public function testPgSQL(string $version, string $expectedClass): void
{
$this->assertDriverInstantiatesDatabasePlatform(new Driver\PgSQL\Driver(), $version, $expectedClass);
}

/** @dataProvider postgreSQLVersionProvider */
public function testPDOPgSQL(string $version, string $expectedClass): void
{
$this->assertDriverInstantiatesDatabasePlatform(new Driver\PDO\PgSQL\Driver(), $version, $expectedClass);
}

/** @return array<int, array<int, string>> */
public static function postgreSQLVersionProvider(): array
{
return [
['9.4', PostgreSQL94Platform::class],
['9.4.0', PostgreSQL94Platform::class],
['9.4.1', PostgreSQL94Platform::class],
['10', PostgreSQL100Platform::class],
];
}

/** @dataProvider db2VersionProvider */
public function testIBMDB2(string $version, string $expectedClass): void
{
$this->assertDriverInstantiatesDatabasePlatform(new Driver\IBMDB2\Driver(), $version, $expectedClass);
}

/** @return array<int, array<int, string>> */
public static function db2VersionProvider(): array
{
return [
['10.1.0', DB2Platform::class, 'https://github.com/doctrine/dbal/pull/5156', true],
['10.1.0.0', DB2Platform::class, 'https://github.com/doctrine/dbal/pull/5156', true],
['DB2/LINUXX8664 10.1.0.0', DB2Platform::class, 'https://github.com/doctrine/dbal/pull/5156', true],
['11.1.0', DB2111Platform::class],
['11.1.0.0', DB2111Platform::class],
['DB2/LINUXX8664 11.1.0.0', DB2111Platform::class],
['11.5.8', DB2111Platform::class],
['11.5.8.0', DB2111Platform::class],
['DB2/LINUXX8664 11.5.8.0', DB2111Platform::class],
];
}

private function assertDriverInstantiatesDatabasePlatform(
VersionAwarePlatformDriver $driver,
string $version,
string $expectedClass,
?string $deprecation = null,
?bool $expectDeprecation = null
): void {
if ($deprecation !== null) {
if ($expectDeprecation ?? true) {
$this->expectDeprecationWithIdentifier($deprecation);
} else {
$this->expectNoDeprecationWithIdentifier($deprecation);
}
}

$platform = $driver->createDatabasePlatformForVersion($version);

self::assertSame($expectedClass, get_class($platform));
}
}

0 comments on commit 5716a6a

Please sign in to comment.