Skip to content
Open
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
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Continuous Integration"

on:
pull_request:
push:
branches:
- master
jobs:
test:
name: "Test"
runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
dependencies:
- "lowest"
- "highest"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "xdebug"
php-version: "${{ matrix.php-version }}"
ini-values: "zend.assertions=1"

- uses: "ramsey/composer-install@v2"
with:
dependency-versions: "${{ matrix.dependencies }}"

- name: "Run PHPUnit"
run: "./tests/phpunit-mysql8.sh"

- name: Upload coverage results to Coveralls
# skip php-coversalls for lowest deps
# it fails on lowest depedencies
if: "${{ 'highest' == matrix.dependencies }}"
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor/
build/
composer.lock
phpunit.xml
.phpunit.result.cache
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
}
],
"require": {
"doctrine/dbal": "^2.8",
"symfony/yaml": "^4.1 | ^5"
"php": "^7.4 || ^8.0",
"doctrine/dbal": "^3.0",
"symfony/yaml": "^4.1 | ^5 | ^6 | ^7"
},
"require-dev": {
"phpunit/phpunit": "^7",
"satooshi/php-coveralls": "^1.0.1",
"thecodingmachine/dbal-fluid-schema-builder": "^1.3.0"
"phpunit/phpunit": "^9.6.16",
"php-coveralls/php-coveralls": "^2.7.0",
"thecodingmachine/dbal-fluid-schema-builder": "^2.0.1"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 9 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
Expand All @@ -18,24 +17,21 @@
</testsuites>

<php>
<var name="db_host" value="localhost" />
<var name="db_host" value="127.0.0.1" />
<var name="db_username" value="root" />
<var name="db_password" value="password" />
<var name="db_name" value="schema_manager_test_case" />
<var name="db_port" value="3306"/>
<var name="db_driver" value="pdo_mysql"/>
</php>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">src/Test</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
</report>
</coverage>
</phpunit>
5 changes: 3 additions & 2 deletions src/Command/ApplySchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class ApplySchemaCommand extends AbstractSchemaCommand
{
protected function configure()
protected function configure(): void
{
$this
->setName('schema:apply')
Expand All @@ -23,13 +23,14 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
if ($input->getOption('dry-run')) {
$this->getMigrationSql($input, $output);
} else {
$this->updateSchema($input, $output);
}
return 0;
}

protected function updateSchema(InputInterface $input, OutputInterface $output)
Expand Down
5 changes: 3 additions & 2 deletions src/Command/DumpSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
*/
class DumpSchemaCommand extends AbstractSchemaCommand
{
protected function configure()
protected function configure(): void
{
$this
->setName('schema:dump')
->setDescription('Dump current schema into schema description file.')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->schemaVersionControlService->dumpSchema();
return 0;
}
}
7 changes: 4 additions & 3 deletions src/Command/SchemaStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
*/
class SchemaStatusCommand extends AbstractSchemaCommand
{
protected function configure()
protected function configure(): void
{
$this
->setName('schema:status')
->setDescription('Show database schema status.')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$diff = $this->schemaVersionControlService->getSchemaDiff(true);

if (empty($diff->changedTables)
&& empty($diff->newTables)
&& empty($diff->removedTables)){
$output->writeln('Schema up-to-date.');
return;
return 0;
}

foreach ($diff->changedTables as $changedTable) {
Expand All @@ -53,6 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('- Command `schema:dump` to save local changes into schema file.');
$output->writeln('- Command `schema:apply` to migrate database version/discard local changes.');
$output->writeln('- Manual migration (you can start from a SQL script obtained by using command `schema:apply --dry-run`.');
return 0;
}

protected function tableDiffStatus(TableDiff $tableDiff, InputInterface $input, OutputInterface $output)
Expand Down
2 changes: 1 addition & 1 deletion tests/AbstractSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class AbstractSchemaTest extends TestCase
/** @var Connection */
protected static $dbConnection;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
self::resetConnection();
$dbConnection = self::getConnection();
Expand Down
6 changes: 3 additions & 3 deletions tests/SchemaVersionControlServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public function testLoad()
$tables = $schema->getTables();
$this->assertEquals(2, count($tables));
$animalTable = $schema->getTable('animal');
$this->assertEquals(['id'], $animalTable->getPrimaryKeyColumns());
$this->assertEquals(['id'], $animalTable->getPrimaryKey()->getColumns());
}

public function testIndexes()
{
$schemaVersionControlService = new SchemaVersionControlService(self::$dbConnection, __DIR__.'/var/schema2.yml');
$schemaVersionControlService = new SchemaVersionControlService(self::$dbConnection, __DIR__.'/etc/schema2.yml');
$schema = $schemaVersionControlService->loadSchemaFile();

$userTable = $schema->getTable('users');
Expand All @@ -32,7 +32,7 @@ public function testIndexes()

public function testComment()
{
$schemaVersionControlService = new SchemaVersionControlService(self::$dbConnection, __DIR__.'/var/schema2.yml');
$schemaVersionControlService = new SchemaVersionControlService(self::$dbConnection, __DIR__.'/etc/schema2.yml');
$schema = $schemaVersionControlService->loadSchemaFile();

$animalTable = $schema->getTable('animal');
Expand Down
Loading