Skip to content

Commit

Permalink
CakePHP 5 upgrade + fix CS (#29)
Browse files Browse the repository at this point in the history
* CakePHP 5 upgrade

* fix CS
  • Loading branch information
LordSimal authored Jun 13, 2023
1 parent 61302f8 commit cb1551c
Show file tree
Hide file tree
Showing 22 changed files with 207 additions and 141 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4']
php-version: ['8.1', '8.2']
db-type: [sqlite, mysql, pgsql]
composer-type: [lowest, stable, dev]
exclude:
- php-version: '7.4'
- php-version: '8.1'
db-type: sqlite
composer-type: lowest

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4']
php-version: ['8.1']

name: PHP ${{ matrix.php-version }}

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.idea
/composer.lock
/vendor/
/.phpunit.result.cache
/.phpunit.cache
**/test_migrator
tests/.env
/tmp
17 changes: 11 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"cakephp/cakephp": "^4.0"
"cakephp/cakephp": "5.x-dev"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^4.0",
"cakephp/migrations": "^3.1",
"cakephp/cakephp-codesniffer": "^5.1",
"cakephp/migrations": "4.x-dev as 4.0.0",
"josegonzalez/dotenv": "dev-master",
"phpunit/phpunit": "^8.0"
"phpunit/phpunit": "^10.1"
},
"autoload": {
"psr-4": {
Expand All @@ -36,9 +37,13 @@
"pgsql": "bash run_tests.sh Postgres",
"sqlite": "bash run_tests.sh Sqlite",
"phpstan": "./vendor/bin/phpstan analyse --memory-limit=-1",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.88 && mv composer.backup composer.json"
"phpstan-baseline": "./vendor/bin/phpstan --generate-baseline",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:1.10.18 && mv composer.backup composer.json"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
8 changes: 8 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Core">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP" />

<arg value="s"/>
</ruleset>
31 changes: 31 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\ConnectionInterface\\:\\:execute\\(\\)\\.$#"
count: 1
path: src/Migrator.php

-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\ConnectionInterface\\:\\:disableConstraints\\(\\)\\.$#"
count: 1
path: src/SchemaCleaner.php

-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\ConnectionInterface\\:\\:execute\\(\\)\\.$#"
count: 2
path: src/SchemaCleaner.php

-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\ConnectionInterface\\:\\:getSchemaCollection\\(\\)\\.$#"
count: 2
path: src/SchemaCleaner.php

-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\ConnectionInterface\\:\\:transactional\\(\\)\\.$#"
count: 1
path: src/SchemaCleaner.php

-
message: "#^Call to an undefined method object\\:\\:schemaDialect\\(\\)\\.$#"
count: 1
path: src/SchemaCleaner.php
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
includes:
- phpstan-baseline.neon

parameters:
level: max
checkMissingIterableValueType: false
Expand Down
30 changes: 16 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
cacheDirectory=".phpunit.cache"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="Default">
<directory>./tests/TestCase/</directory>
</testsuite>
<testsuite name="Default">
<directory>./tests/TestCase/</directory>
</testsuite>
</testsuites>

<!-- Ignore vendor tests in code coverage reports -->
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</source>
</phpunit>
42 changes: 24 additions & 18 deletions src/ConfigReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,43 @@
*/
namespace CakephpTestMigrator;


use Cake\Datasource\ConnectionManager;

class ConfigReader
{
/**
* @var array
*/
private $config = [];
private array $config = [];

/**
* Read in the Datasources the 'migrations' key for each
* active connection
*
* @return $this
*/
public function readMigrationsInDatasources(): self
public function readMigrationsInDatasources()
{
foreach ($this->getActiveConnections() as $connectionName) {
$connection = ConnectionManager::getConfig($connectionName);
$config = [];

if (isset($connection['migrations'])) {
if ($connection['migrations'] === true) {
$config = ['connection' => $connectionName ];
$this->normalizeArray($config);
} elseif (is_array($connection['migrations'])) {
$config = $connection['migrations'];
$this->normalizeArray($config);
foreach ($config as $k => $v) {
$config[$k]['connection'] = $config[$k]['connection'] ?? $connectionName;
if (is_array($connection)) {
$migrations = $connection['migrations'] ?? false;

if ($migrations) {
if ($migrations === true) {
$config = ['connection' => $connectionName ];
$this->normalizeArray($config);
} elseif (is_array($migrations)) {
$config = $migrations;
$this->normalizeArray($config);
foreach ($config as $k => $v) {
$config[$k]['connection'] = $v['connection'] ?? $connectionName;
}
}

$this->config = array_merge($this->config, $config);
}
$this->config = array_merge($this->config, $config);
}
}

Expand All @@ -57,10 +59,10 @@ public function readMigrationsInDatasources(): self
}

/**
* @param string[]|array[] $config An array of migration configs
* @param array<string>|array<array> $config An array of migration configs
* @return $this
*/
public function readConfig(array $config = []): self
public function readConfig(array $config = [])
{
if (!empty($config)) {
$this->normalizeArray($config);
Expand All @@ -72,6 +74,11 @@ public function readConfig(array $config = []): self
return $this;
}

/**
* Make sure config is set properly
*
* @return void
*/
public function processConfig(): void
{
foreach ($this->config as $k => $config) {
Expand Down Expand Up @@ -101,7 +108,6 @@ public function getActiveConnections(): array

/**
* @param string $connectionName Connection name
*
* @return bool
*/
public function skipConnection(string $connectionName): bool
Expand All @@ -122,7 +128,7 @@ public function skipConnection(string $connectionName): bool
/**
* Make array an array of arrays
*
* @param array $array
* @param array $array
* @return void
*/
public function normalizeArray(array &$array): void
Expand Down
Loading

0 comments on commit cb1551c

Please sign in to comment.