Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/code-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
strategy:
matrix:
php:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/vendor
/.phpunit.cache/
/vendor/
/composer.lock
/.phpunit.result.cache
2 changes: 1 addition & 1 deletion .runConfigurations/All tests.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<env name="INTEGRATION_ENABLED" value="1" />
</envs>
</CommandLine>
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml.dist" directory="$PROJECT_DIR$/tests" scope="XML" options="--verbose" />
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml.dist" directory="$PROJECT_DIR$/tests" scope="XML" />
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion .runConfigurations/All unit tests.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="All unit tests" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml.dist" scope="XML" options="--verbose" />
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml.dist" scope="XML" />
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion .runConfigurations/Integration tests.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<env name="INTEGRATION_ENABLED" value="1" />
</envs>
</CommandLine>
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml.dist" directory="$PROJECT_DIR$/tests" scope="XML" options="--verbose --group=integration" />
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml.dist" directory="$PROJECT_DIR$/tests" scope="XML" options="--group=integration" />
<method v="2" />
</configuration>
</component>
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Removed
- **BC break**: Removed support for PHP versions <= v8.0 as they are no longer
[actively supported](https://php.net/supported-versions.php) by the PHP project.

## [2.0.2] - 2025-02-08
### Changed
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"ext-pdo": "*",
"ext-pdo_mysql": "*",
"symfony/console": "^3.2|^4|^5 || ^6 || ^7"
"symfony/console": "^6 || ^7"
},
"autoload": {
"psr-4": {
"Phlib\\SchemaDiff\\": "src"
}
},
"require-dev": {
"phpunit/phpunit": "^9",
"phpunit/phpunit": "^10",
"symplify/easy-coding-standard": "^12"
},
"autoload-dev": {
Expand Down
15 changes: 15 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@
[
'closure_fn_spacing' => 'none',
],
)

/*
* Rule from PER Coding Style 2.6:
* "If the list is split across multiple lines, then the last item MUST have a trailing comma."
*/
->withConfiguredRule(
\PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer::class,
[
'elements' => [
\PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer::ELEMENTS_ARGUMENTS,
\PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer::ELEMENTS_ARRAYS,
\PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer::ELEMENTS_PARAMETERS,
],
],
);
8 changes: 4 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
convertDeprecationsToExceptions="true"
cacheDirectory=".phpunit.cache"
colors="true"
>
<php>
Expand All @@ -21,9 +21,9 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</source>
</phpunit>
29 changes: 13 additions & 16 deletions src/SchemaDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
*/
class SchemaDiff
{
private OutputInterface $output;

public function __construct(OutputInterface $output)
{
$this->output = $output;

public function __construct(
private readonly OutputInterface $output,
) {
$this->initStyles();
}

Expand Down Expand Up @@ -51,8 +48,8 @@ public function diff(SchemaInfo $schema1, SchemaInfo $schema2): bool
$tables = array_unique(
array_merge(
$schema1->getTables(),
$schema2->getTables()
)
$schema2->getTables(),
),
);

$msg = '<error>Missing table</error> <table>%s</table> missing on <schema>%s</schema> exists on <schema>%s</schema>';
Expand All @@ -63,7 +60,7 @@ public function diff(SchemaInfo $schema1, SchemaInfo $schema2): bool
$msg,
$tableName,
$schema1->getName() . '@1',
$schema2->getName() . '@2'
$schema2->getName() . '@2',
));

continue;
Expand All @@ -74,7 +71,7 @@ public function diff(SchemaInfo $schema1, SchemaInfo $schema2): bool
$msg,
$tableName,
$schema2->getName() . '@2',
$schema1->getName() . '@1'
$schema1->getName() . '@1',
));

continue;
Expand Down Expand Up @@ -150,8 +147,8 @@ private function compareColumns(SchemaInfo $schema1, SchemaInfo $schema2, string
$tableName,
$columnName,
$schema1->getName() . '@1',
$schema2->getName() . '@2'
)
$schema2->getName() . '@2',
),
);

continue;
Expand All @@ -165,8 +162,8 @@ private function compareColumns(SchemaInfo $schema1, SchemaInfo $schema2, string
$tableName,
$columnName,
$schema2->getName() . '@2',
$schema1->getName() . '@1'
)
$schema1->getName() . '@1',
),
);

continue;
Expand Down Expand Up @@ -216,7 +213,7 @@ private function compareIndexes(SchemaInfo $schema1, SchemaInfo $schema2, string
$tableName,
$indexName,
$schema1->getName() . '@1',
$schema2->getName() . '@2'
$schema2->getName() . '@2',
));

continue;
Expand All @@ -229,7 +226,7 @@ private function compareIndexes(SchemaInfo $schema1, SchemaInfo $schema2, string
$tableName,
$indexName,
$schema2->getName() . '@2',
$schema1->getName() . '@1'
$schema1->getName() . '@1',
));

continue;
Expand Down
33 changes: 13 additions & 20 deletions src/SchemaDiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
*/
class SchemaDiffCommand extends Command
{
private SchemaInfoFactory $schemaInfoFactory;

private \Closure $schemaDiffFactory;

private array $ignoreDatabases;

private ?string $ignoreDatabasesRegex;
Expand All @@ -37,12 +33,9 @@ class SchemaDiffCommand extends Command
private ?string $tablesRegex;

public function __construct(
SchemaInfoFactory $schemaInfoFactory,
\Closure $schemaDiffFactory
private readonly SchemaInfoFactory $schemaInfoFactory,
private readonly \Closure $schemaDiffFactory,
) {
$this->schemaInfoFactory = $schemaInfoFactory;
$this->schemaDiffFactory = $schemaDiffFactory;

parent::__construct();
}

Expand All @@ -65,69 +58,69 @@ protected function configure(): void
$this->addArgument(
'dsn1',
InputArgument::REQUIRED,
'DSN to first schema, needs to contain the main database'
'DSN to first schema, needs to contain the main database',
);

$this->addArgument(
'dsn2',
InputArgument::REQUIRED,
'DSN to second schema, if it contains a database that will be used, otherwise uses the filter options'
'DSN to second schema, if it contains a database that will be used, otherwise uses the filter options',
);

$this->addOption(
'ignore-databases',
null,
InputOption::VALUE_REQUIRED,
'Ignore this comma-separated list of databases'
'Ignore this comma-separated list of databases',
);

$this->addOption(
'ignore-databases-regex',
null,
InputOption::VALUE_REQUIRED,
'Ignore databases whose names match this regex'
'Ignore databases whose names match this regex',
);

$this->addOption(
'databases',
null,
InputOption::VALUE_REQUIRED,
'Only compare this comma-separated list of databases'
'Only compare this comma-separated list of databases',
);

$this->addOption(
'databases-regex',
null,
InputOption::VALUE_REQUIRED,
'Only compare databases whose names match this regex'
'Only compare databases whose names match this regex',
);

$this->addOption(
'ignore-tables',
null,
InputOption::VALUE_REQUIRED,
'Ignore this comma-separated list of tables. Table names may be qualified with the database name'
'Ignore this comma-separated list of tables. Table names may be qualified with the database name',
);

$this->addOption(
'ignore-tables-regex',
null,
InputOption::VALUE_REQUIRED,
'Ignore tables whose names match the regex'
'Ignore tables whose names match the regex',
);

$this->addOption(
'tables',
null,
InputOption::VALUE_REQUIRED,
'Compare only this comma-separated list of tables. Table names may be qualified with the database name'
'Compare only this comma-separated list of tables. Table names may be qualified with the database name',
);

$this->addOption(
'tables-regex',
null,
InputOption::VALUE_REQUIRED,
'Compare only tables whose names match this regex'
'Compare only tables whose names match this regex',
);
}

Expand Down Expand Up @@ -177,7 +170,7 @@ private function createSchemaInfo(\PDO $pdo, string $database, OutputInterface $
$database,
function ($tableName) use ($database, $output): bool {
return $this->isTableAllowed($database, $tableName, $output);
}
},
);
}

Expand Down
16 changes: 5 additions & 11 deletions src/SchemaInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@
*/
class SchemaInfo
{
private string $name;

private array $schemaData;

private array $tableData;

public function __construct(string $name, array $schemaData, array $tableData)
{
$this->name = $name;
$this->schemaData = $schemaData;
$this->tableData = $tableData;
public function __construct(
private readonly string $name,
private readonly array $schemaData,
private readonly array $tableData,
) {
}

public function getName(): string
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function setUp(): void
\PDO::ATTR_TIMEOUT => 2,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
]
],
);
}

Expand All @@ -56,7 +56,7 @@ final protected function createTestTable(
bool $charCol = true,
bool $charIdx = false,
string $colCharset = null,
string $tableCharset = 'ascii'
string $tableCharset = 'ascii',
) {
$schemaTableQuoted = '`' . $schemaName . "`.`{$tableName}`";

Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/SchemaDiffCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
use Phlib\SchemaDiff\SchemaDiff;
use Phlib\SchemaDiff\SchemaDiffCommand;
use Phlib\SchemaDiff\SchemaInfoFactory;
use PHPUnit\Framework\Attributes\Group;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;

/**
* @package phlib/schemadiff
* @group integration
*
* This only runs basic table-centric tests that are handled by `SchemaDiff` as it's relying on a limited test database.
*/
#[Group('integration')]
class SchemaDiffCommandTest extends SchemaDiffTestCase
{
private SchemaDiffCommand $command;
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/SchemaDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

use Phlib\SchemaDiff\SchemaDiff;
use Phlib\SchemaDiff\SchemaInfoFactory;
use PHPUnit\Framework\Attributes\Group;
use Symfony\Component\Console\Output\BufferedOutput;

/**
* @package phlib/schemadiff
* @group integration
*/
#[Group('integration')]
class SchemaDiffTest extends SchemaDiffTestCase
{
protected function runDiff(string $tableName, string &$output = null): bool
Expand Down
Loading