Skip to content

Commit

Permalink
PHPUnit 10 support (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
misantron committed Aug 17, 2023
1 parent 2df0707 commit c582963
Show file tree
Hide file tree
Showing 31 changed files with 352 additions and 151 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Expand Up @@ -36,6 +36,7 @@ jobs:
- '8.0'
- '8.1'
- '8.2'
- '8.3'
services:
mysql:
image: "mysql:${{ matrix.db-version }}"
Expand All @@ -60,8 +61,11 @@ jobs:
with:
dependency-versions: locked
composer-options: --no-ansi --no-interaction --no-progress
- name: Override config
run: cp ci/phpunit/phpunit.96.xml phpunit.xml.dist
if: ${{ matrix.php-versions == '7.4' || matrix.php-versions == '8.0' }}
- name: Run PHPUnit
run: vendor/bin/phpunit --colors=always
run: vendor/bin/phpunit --colors=always --config phpunit.xml.dist
coverage:
name: Tests coverage
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
/.idea
/.phpunit.result.cache
/composer.lock
/phpunit.xml
/build
/vendor
/tools
2 changes: 1 addition & 1 deletion phpunit.xml → ci/phpunit/phpunit.96.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="tests/bootstrap.php"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
Expand Down
11 changes: 8 additions & 3 deletions composer.json
Expand Up @@ -18,12 +18,14 @@
"require": {
"php": "^7.4 || ^8.0",
"ext-pdo": "*",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^9.5 || ^10.2",
"symfony/polyfill-php80": "^1.27",
"symfony/yaml": "^5.4 || ^6.0"
},
"require-dev": {
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"symplify/easy-coding-standard": "^11.3"
"symplify/easy-coding-standard": "^12.0"
},
"autoload": {
"psr-4": {
Expand All @@ -39,6 +41,9 @@
]
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Expand Up @@ -2,7 +2,7 @@ version: 3.x

services:
mysql:
image: mysql:5.7
image: biarms/mysql:5.7
environment:
MYSQL_DATABASE: dbunit
MYSQL_ALLOW_EMPTY_PASSWORD: yes
Expand Down
9 changes: 5 additions & 4 deletions ecs.php
Expand Up @@ -2,8 +2,6 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

Expand All @@ -24,12 +22,13 @@
file that was distributed with this source code.
EOF;

$ecsConfig->ruleWithConfiguration(HeaderCommentFixer::class, [
$ecsConfig->ruleWithConfiguration(PhpCsFixer\Fixer\Comment\HeaderCommentFixer::class, [
'header' => $header,
]);

$ecsConfig->skip([
NotOperatorWithSuccessorSpaceFixer::class,
PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer::class,
PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer::class,
]);

$ecsConfig->sets([
Expand All @@ -38,5 +37,7 @@
SetList::CLEAN_CODE,
SetList::ARRAY,
SetList::PHPUNIT,
SetList::CONTROL_STRUCTURES,
SetList::NAMESPACES,
]);
};
1 change: 0 additions & 1 deletion phpstan.neon
Expand Up @@ -3,5 +3,4 @@ parameters:
paths:
- src
- tests
editorUrl: '%%file%%:%%line%%'
checkGenericClassInNonGenericObjectType: false
32 changes: 32 additions & 0 deletions phpunit.xml.dist
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true">

<testsuites>
<testsuite name="all">
<directory>tests/</directory>
<exclude>tests/_files/*</exclude>
</testsuite>
<testsuite name="unit">
<directory>tests/</directory>
<exclude>tests/_files/*</exclude>
<exclude>tests/Operation/OperationsMySQLTest.php</exclude>
</testsuite>
</testsuites>

<php>
<env name="MYSQL_DB_HOST" value="127.0.0.1"/>
<env name="MYSQL_DB_PORT" value="3406"/>
<env name="MYSQL_DB_NAME" value="dbunit"/>
<env name="MYSQL_DB_USER" value="root"/>
<env name="MYSQL_DB_PASSWORD" value=""/>
</php>

<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
6 changes: 3 additions & 3 deletions src/Constraint/DataSetIsEqual.php
Expand Up @@ -23,7 +23,7 @@ class DataSetIsEqual extends Constraint
/**
* @var IDataSet
*/
protected $value;
protected IDataSet $value;

/**
* @param IDataSet $value
Expand All @@ -41,8 +41,8 @@ public function __construct(IDataSet $value)
public function toString(): string
{
return sprintf(
'is equal to expected %s',
(string) $this->value
'is equal to expected dataset %s',
$this->value
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Constraint/TableIsEqual.php
Expand Up @@ -23,7 +23,7 @@ class TableIsEqual extends Constraint
/**
* @var ITable
*/
protected $value;
protected ITable $value;

/**
* @param ITable $value
Expand All @@ -42,7 +42,7 @@ public function toString(): string
{
return sprintf(
'is equal to expected %s',
(string) $this->value
$this->value
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/DataSet/AbstractDataSet.php
Expand Up @@ -20,15 +20,15 @@ abstract class AbstractDataSet implements IDataSet
{
public function __toString()
{
/** @var ITable[] $iterator */
$iterator = $this->getIterator();

$dataSetString = '';

$tables = [];
foreach ($iterator as $table) {
$dataSetString .= $table;
$tables[] = $table->getTableMetadata()->getTableName();
}

return $dataSetString;
return '[' . implode(',', $tables) . ']';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/DataSet/AbstractXmlDataSet.php
Expand Up @@ -102,9 +102,9 @@ protected function createTables(array &$tableColumns, array &$tableValues): void
* @param string $tableName
* @param mixed $tableColumns
*
* @return ITable
* @return DefaultTable
*/
protected function getOrCreateTable($tableName, $tableColumns): ITable
protected function getOrCreateTable(string $tableName, $tableColumns): DefaultTable
{
if (empty($this->tables[$tableName])) {
$tableMetaData = new DefaultTableMetadata($tableName, $tableColumns);
Expand Down
4 changes: 2 additions & 2 deletions src/DataSet/DefaultDataSet.php
Expand Up @@ -19,9 +19,9 @@ class DefaultDataSet extends AbstractDataSet
/**
* An array of ITable objects.
*
* @var array
* @var ITable[]
*/
protected $tables;
protected array $tables;

/**
* @param array $tables
Expand Down
2 changes: 1 addition & 1 deletion src/DataSet/DefaultTableMetadata.php
Expand Up @@ -25,7 +25,7 @@ class DefaultTableMetadata extends AbstractTableMetadata
* @param array $columns
* @param array $primaryKeys
*/
public function __construct($tableName, array $columns, array $primaryKeys = [])
public function __construct(string $tableName, array $columns, array $primaryKeys = [])
{
$this->tableName = $tableName;
$this->columns = $columns;
Expand Down
2 changes: 1 addition & 1 deletion src/DataSet/IDataSet.php
Expand Up @@ -14,7 +14,7 @@
/**
* Provides a basic interface for creating and reading data from data sets.
*/
interface IDataSet extends \IteratorAggregate
interface IDataSet extends \IteratorAggregate, \Stringable
{
/**
* Returns an array of table names contained in the dataset.
Expand Down
2 changes: 1 addition & 1 deletion src/DataSet/ITable.php
Expand Up @@ -14,7 +14,7 @@
/**
* Provides a basic interface for creating and reading data from data sets.
*/
interface ITable
interface ITable extends \Stringable
{
/**
* Returns the table's meta data.
Expand Down
4 changes: 2 additions & 2 deletions src/DataSet/ReplacementDataSet.php
Expand Up @@ -51,9 +51,9 @@ public function __construct(IDataSet $dataSet, array $fullReplacements = [], arr
* Full replacements will only replace values if the FULL value is a match
*
* @param string $value
* @param string $replacement
* @param string|null $replacement
*/
public function addFullReplacement($value, $replacement): void
public function addFullReplacement(string $value, ?string $replacement): void
{
$this->fullReplacements[$value] = $replacement;
}
Expand Down
4 changes: 2 additions & 2 deletions src/DataSet/ReplacementTable.php
Expand Up @@ -82,9 +82,9 @@ public function __toString()
* Full replacements will only replace values if the FULL value is a match
*
* @param string $value
* @param string $replacement
* @param string|null $replacement
*/
public function addFullReplacement($value, $replacement): void
public function addFullReplacement(string $value, ?string $replacement): void
{
$this->fullReplacements[$value] = $replacement;
}
Expand Down
20 changes: 10 additions & 10 deletions src/Database/DataSet.php
Expand Up @@ -38,6 +38,16 @@ class DataSet extends AbstractDataSet
*/
protected $databaseConnection;

/**
* Creates a new dataset using the given database connection.
*
* @param Connection $databaseConnection
*/
public function __construct(Connection $databaseConnection)
{
$this->databaseConnection = $databaseConnection;
}

/**
* Creates the query necessary to pull all of the data from a table.
*
Expand Down Expand Up @@ -83,16 +93,6 @@ public static function buildTableSelect(ITableMetadata $tableMetaData, Connectio
return "SELECT {$columnList} FROM {$tableName} {$orderBy}";
}

/**
* Creates a new dataset using the given database connection.
*
* @param Connection $databaseConnection
*/
public function __construct(Connection $databaseConnection)
{
$this->databaseConnection = $databaseConnection;
}

/**
* Returns a table object for the given table.
*
Expand Down
30 changes: 16 additions & 14 deletions src/Database/Metadata/AbstractMetadata.php
Expand Up @@ -56,6 +56,19 @@ abstract class AbstractMetadata implements Metadata
*/
protected $truncateCommand = 'TRUNCATE';

/**
* Creates a new database meta data object using the given pdo connection
* and schema name.
*
* @param PDO $pdo
* @param string $schema
*/
final public function __construct(PDO $pdo, $schema = '')
{
$this->pdo = $pdo;
$this->schema = $schema;
}

/**
* Creates a meta data object based on the driver of given $pdo object and
* $schema name.
Expand Down Expand Up @@ -110,19 +123,6 @@ public static function registerClassWithDriver($className, $pdoDriver)
throw new RuntimeException("Specified class for {$pdoDriver} driver ({$className}) does not extend PHPUnit_Extensions_Database_DB_MetaData.");
}

/**
* Creates a new database meta data object using the given pdo connection
* and schema name.
*
* @param PDO $pdo
* @param string $schema
*/
final public function __construct(PDO $pdo, $schema = '')
{
$this->pdo = $pdo;
$this->schema = $schema;
}

/**
* Returns the schema for the connection.
*
Expand Down Expand Up @@ -165,7 +165,9 @@ public function quoteSchemaObject($object)
*/
public function splitTableName($fullTableName)
{
if (($dot = strpos($fullTableName, '.')) !== false) {
$dot = strpos($fullTableName, '.');

if ($dot !== false) {
return [
'schema' => substr($fullTableName, 0, $dot),
'table' => substr($fullTableName, $dot + 1),
Expand Down

0 comments on commit c582963

Please sign in to comment.