Skip to content
Merged
131 changes: 131 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: CI


on:
push:
branches:
- master
pull_request:
branches:
- '*'

jobs:
testsuite-linux:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
php-version: ['7.2', '7.4']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
php-version: ['7.2', '7.4']
php-version: ['7.2', '8 0']

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we've done the work to get migrations working on 8.0. I can add that to the matrix once tests are passing again.

#db-type: [mysql, pgsql, sqlite]
db-type: [mysql, sqlite]
prefer-lowest: ['']
include:
- php-version: '7.2'
db-type: 'sqlite'
prefer-lowest: 'prefer-lowest'

services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres


steps:
- uses: actions/checkout@v2

- name: Setup MySQL
if: matrix.db-type == 'mysql'
run: |
sudo service mysql start
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_test DEFAULT COLLATE=utf8mb4_general_ci;'
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_comparisons;'

- name: Setup Postgres
if: matrix.db-type == 'pgsql'
run: |
psql -c 'CREATE DATABASE cakephp_test;' -U postgres
psql -c 'CREATE DATABASE cakephp_comparisons;' -U postgres

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, pdo_${{ matrix.db-type }}
coverage: pcov

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: Composer install
run: |
if [[ ${{ matrix.php-version }} == '8.0' ]]; then
composer install --ignore-platform-reqs
elif ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
else
composer install
fi

- name: Run PHPUnit
run: |
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then
export DB='sqlite'
fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then
export DB_URL='mysql://root:root@127.0.0.1/cakephp_test'
export DB_URL_COMPARE='mysql://root:root@127.0.0.1/cakephp_comparisons'
fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then
export DB_URL='postgres://postgres:postgres@127.0.0.1/cakephp_test'
export DB_URL_COMPARE='postgres://postgres:postgres@127.0.0.1/cakephp_comparisons'
fi
if [[ ${{ matrix.php-version }} == '7.4' && ${{ matrix.db-type }} == 'mysql' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi

- name: Code Coverage Report
if: success() && matrix.php-version == '7.4' && matrix.db-type == 'mysql'
uses: codecov/codecov-action@v1

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, intl
coverage: none
tools: psalm:^3.11, phpstan:^0.12, cs2pr

- name: Composer Install
run: composer install

- name: Run phpcs
run: vendor/bin/phpcs --report=checkstyle src/ tests/ | cs2pr

- name: Run psalm
run: psalm --output-format=github

- name: Run phpstan
run: phpstan analyse src/
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"phpunit/phpunit": "~8.5.0",
"cakephp/cakephp": "dev-4.next as 4.3.0",
"cakephp/bake": "^2.1.0",
"cakephp/cakephp-codesniffer": "~4.1.0"
"cakephp/cakephp-codesniffer": "~4.1"
},
"autoload": {
"psr-4": {
Expand All @@ -53,8 +53,8 @@
"@test",
"@stan"
],
"cs-check": "phpcs --colors -p -s --ignore=/tests/comparisons/,/test_app/config/,/TestBlog/config/ src/ tests/",
"cs-fix": "phpcbf --colors -p --ignore=/tests/comparisons/,/test_app/config/,/TestBlog/config/ src/ tests/",
"cs-check": "phpcs --colors -p -s src/ tests/",
"cs-fix": "phpcbf --colors -p src/ tests/",
"stan": "phpstan analyse src/ && psalm.phar --show-info=false",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12 psalm/phar:~3.11.2 && mv composer.backup composer.json",
"test": "phpunit",
Expand Down
6 changes: 6 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Core">
<exclude-pattern>*/tests/comparisons/*</exclude-pattern>
<exclude-pattern>*/test_app/config/*</exclude-pattern>
<exclude-pattern>*/TestBlog/config/*</exclude-pattern>
<exclude-pattern>*/BarPlugin/config/*</exclude-pattern>
<exclude-pattern>*/FooPlugin/config/*</exclude-pattern>

<rule ref="./vendor/cakephp/cakephp-codesniffer/CakePHP/ruleset.xml"/>

<!-- Necessary for class aliases used for backwards compat -->
Expand Down
5 changes: 3 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<psalm
allowStringToStandInForClass="true"
usePhpDocMethodsWithoutMagicCall="true"
ignoreInternalFunctionFalseReturn="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand All @@ -11,11 +10,13 @@
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="tests/test_app" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<RedundantConditionGivenDocblockType errorLevel="suppress"/>
<TypeCoercion errorLevel="suppress"/>
<DocblockTypeContradiction errorLevel="suppress"/>
<MissingClosureParamType errorLevel="suppress"/>
<MissingClosureReturnType errorLevel="suppress"/>
Expand Down
2 changes: 1 addition & 1 deletion src/CakeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CakeAdapter extends AdapterWrapper
public function __construct(AdapterInterface $adapter, ?Connection $connection = null)
{
if ($connection === null) {
throw new \InvalidArgumentException("The cake connection cannot be null");
throw new \InvalidArgumentException('The cake connection cannot be null');
}

parent::__construct($adapter);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/BakeMigrationDiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ protected function getCurrentSchema()
}
$collection = $connection->getSchemaCollection();
foreach ($this->tables as $table) {
if (preg_match("/^.*phinxlog$/", $table) === 1) {
if (preg_match('/^.*phinxlog$/', $table) === 1) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/BakeSeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
* @param string $indentCharacter Desired indent for the code.
* @return string
*/
protected function prettifyArray(array $array, $tabCount = 3, $indentCharacter = " ")
protected function prettifyArray(array $array, $tabCount = 3, $indentCharacter = ' ')
{
$content = var_export($array, true);

Expand Down
10 changes: 5 additions & 5 deletions src/Command/Phinx/MarkMigrated.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($this->invalidOnlyOrExclude()) {
$output->writeln(
"<error>You should use `--exclude` OR `--only` (not both) along with a `--target` !</error>"
'<error>You should use `--exclude` OR `--only` (not both) along with a `--target` !</error>'
);

return BaseCommand::CODE_ERROR;
Expand All @@ -134,7 +134,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
try {
$versions = $this->getManager()->getVersionsToMark($input);
} catch (InvalidArgumentException $e) {
$output->writeln(sprintf("<error>%s</error>", $e->getMessage()));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));

return BaseCommand::CODE_ERROR;
}
Expand Down Expand Up @@ -207,9 +207,9 @@ protected function invalidOnlyOrExclude()
*/
protected function outputDeprecatedAllMessage()
{
$msg = "DEPRECATED: `all` or `*` as version is deprecated. Use `bin/cake migrations mark_migrated` instead";
$msg = 'DEPRECATED: `all` or `*` as version is deprecated. Use `bin/cake migrations mark_migrated` instead';
$output = $this->output();
$output->writeln(sprintf("<comment>%s</comment>", $msg));
$output->writeln(sprintf('<comment>%s</comment>', $msg));
}

/**
Expand All @@ -222,6 +222,6 @@ protected function outputDeprecatedVersionMessage()
$msg = 'DEPRECATED: VERSION as argument is deprecated. Use: ' .
'`bin/cake migrations mark_migrated --target=VERSION --only`';
$output = $this->output();
$output->writeln(sprintf("<comment>%s</comment>", $msg));
$output->writeln(sprintf('<comment>%s</comment>', $msg));
}
}
13 changes: 8 additions & 5 deletions src/TestSuite/ConfigReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ConfigReader
*
* @return $this
*/
public function readMigrationsInDatasources(): self
public function readMigrationsInDatasources()
{
foreach ($this->getActiveConnections() as $connectionName) {
$connection = ConnectionManager::getConfig($connectionName);
Expand All @@ -44,7 +44,6 @@ public function readMigrationsInDatasources(): self
foreach ($config as $k => $v) {
$config[$k]['connection'] = $config[$k]['connection'] ?? $connectionName;
}

}
$this->config = array_merge($this->config, $config);
}
Expand All @@ -59,7 +58,7 @@ public function readMigrationsInDatasources(): self
* @param string[]|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 @@ -71,6 +70,11 @@ public function readConfig(array $config = []): self
return $this;
}

/**
* Helper method to process connection configuration.
*
* @return void
*/
public function processConfig(): void
{
foreach ($this->config as $k => $config) {
Expand Down Expand Up @@ -100,7 +104,6 @@ public function getActiveConnections(): array

/**
* @param string $connectionName Connection name
*
* @return bool
*/
public function skipConnection(string $connectionName): bool
Expand All @@ -121,7 +124,7 @@ public function skipConnection(string $connectionName): bool
/**
* Make array an array of arrays
*
* @param array $array
* @param array $array Input data to normalize (pass by ref)
* @return void
*/
public function normalizeArray(array &$array): void
Expand Down
Loading