diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..3aba5ed34 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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'] + #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/ diff --git a/composer.json b/composer.json index 984e09484..9cf82c8ec 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -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", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index f0e24b176..4a821f24d 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,5 +1,11 @@ + */tests/comparisons/* + */test_app/config/* + */TestBlog/config/* + */BarPlugin/config/* + */FooPlugin/config/* + diff --git a/psalm.xml b/psalm.xml index bbcc1b2b4..958f4f1f4 100644 --- a/psalm.xml +++ b/psalm.xml @@ -2,7 +2,6 @@ + + + - diff --git a/src/CakeAdapter.php b/src/CakeAdapter.php index 565b85cda..6622f443e 100644 --- a/src/CakeAdapter.php +++ b/src/CakeAdapter.php @@ -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); diff --git a/src/Command/BakeMigrationDiffCommand.php b/src/Command/BakeMigrationDiffCommand.php index c6cce9d5b..b0e33f9cd 100644 --- a/src/Command/BakeMigrationDiffCommand.php +++ b/src/Command/BakeMigrationDiffCommand.php @@ -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; } diff --git a/src/Command/BakeSeedCommand.php b/src/Command/BakeSeedCommand.php index 498092e21..04d9c2eb1 100644 --- a/src/Command/BakeSeedCommand.php +++ b/src/Command/BakeSeedCommand.php @@ -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); diff --git a/src/Command/Phinx/MarkMigrated.php b/src/Command/Phinx/MarkMigrated.php index f9553d63c..ce579a610 100644 --- a/src/Command/Phinx/MarkMigrated.php +++ b/src/Command/Phinx/MarkMigrated.php @@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($this->invalidOnlyOrExclude()) { $output->writeln( - "You should use `--exclude` OR `--only` (not both) along with a `--target` !" + 'You should use `--exclude` OR `--only` (not both) along with a `--target` !' ); return BaseCommand::CODE_ERROR; @@ -134,7 +134,7 @@ protected function execute(InputInterface $input, OutputInterface $output) try { $versions = $this->getManager()->getVersionsToMark($input); } catch (InvalidArgumentException $e) { - $output->writeln(sprintf("%s", $e->getMessage())); + $output->writeln(sprintf('%s', $e->getMessage())); return BaseCommand::CODE_ERROR; } @@ -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("%s", $msg)); + $output->writeln(sprintf('%s', $msg)); } /** @@ -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("%s", $msg)); + $output->writeln(sprintf('%s', $msg)); } } diff --git a/src/TestSuite/ConfigReader.php b/src/TestSuite/ConfigReader.php index efe9bfdc7..ca2b61250 100644 --- a/src/TestSuite/ConfigReader.php +++ b/src/TestSuite/ConfigReader.php @@ -28,7 +28,7 @@ class ConfigReader * * @return $this */ - public function readMigrationsInDatasources(): self + public function readMigrationsInDatasources() { foreach ($this->getActiveConnections() as $connectionName) { $connection = ConnectionManager::getConfig($connectionName); @@ -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); } @@ -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); @@ -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) { @@ -100,7 +104,6 @@ public function getActiveConnections(): array /** * @param string $connectionName Connection name - * * @return bool */ public function skipConnection(string $connectionName): bool @@ -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 diff --git a/src/TestSuite/Migrator.php b/src/TestSuite/Migrator.php index 83c77aaab..f12dfeaad 100644 --- a/src/TestSuite/Migrator.php +++ b/src/TestSuite/Migrator.php @@ -13,7 +13,6 @@ */ namespace Migrations\TestSuite; -use Cake\Console\ConsoleIo; use Cake\Datasource\ConnectionManager; use Cake\TestSuite\Schema\SchemaCleaner; use Cake\TestSuite\Schema\SchemaManager; @@ -22,18 +21,13 @@ class Migrator extends SchemaManager { - /** - * @var ConsoleIo - */ - protected $io; - /** * General command to run before your tests run * E.g. in tests/bootstrap.php * - * @param array $config + * @param array $config Configuration data * @param bool $verbose Set to true to display messages - * @return Migrator + * @return static */ public static function migrate(array $config = [], $verbose = false): Migrator { @@ -64,11 +58,10 @@ protected function runMigrations(array $config): void $msg = 'Migrations for ' . $this->stringifyConfig($config); - if ($result === true) { $this->io->success($msg . ' successfully run.'); } else { - $this->io->error( $msg . ' failed.'); + $this->io->error($msg . ' failed.'); } } @@ -79,7 +72,7 @@ protected function runMigrations(array $config): void * @return $this * @throws \Exception */ - protected function handleMigrationsStatus(array $configs): self + protected function handleMigrationsStatus(array $configs) { $connectionsToDrop = []; foreach ($configs as &$config) { @@ -94,7 +87,7 @@ protected function handleMigrationsStatus(array $configs): self } if (empty($connectionsToDrop)) { - $this->io->success("No migration changes detected."); + $this->io->success('No migration changes detected.'); return $this; } @@ -122,13 +115,14 @@ protected function handleMigrationsStatus(array $configs): self /** * Unset the phinx migration tables from an array of tables. * - * @param string[] $tables + * @param string[] $tables The list of tables to remove items from. * @return array */ protected function unsetMigrationTables(array $tables): array { $endsWithPhinxlog = function (string $string) { $needle = 'phinxlog'; + return substr($string, -strlen($needle)) === $needle; }; @@ -144,7 +138,7 @@ protected function unsetMigrationTables(array $tables): array /** * Checks if any migrations are up but missing. * - * @param Migrations $migrations + * @param \Migrations\Migrations $migrations The migration collection to check. * @return bool */ protected function isStatusChanged(Migrations $migrations): bool @@ -152,10 +146,12 @@ protected function isStatusChanged(Migrations $migrations): bool foreach ($migrations->status() as $migration) { if ($migration['status'] === 'up' && ($migration['missing'] ?? false)) { $this->io->info('Missing migration(s) detected.'); + return true; } if ($migration['status'] === 'down') { $this->io->info('New migration(s) found.'); + return true; } } @@ -176,7 +172,7 @@ protected function stringifyConfig(array $config): string $options = []; foreach (['connection', 'plugin', 'source', 'target'] as $option) { if (isset($config[$option])) { - $options[] = $option . ' "'.$config[$option].'"'; + $options[] = sprintf('%s "%s"', $option, $config[$option]); } } diff --git a/src/View/Helper/MigrationHelper.php b/src/View/Helper/MigrationHelper.php index b15c67b60..735f03302 100644 --- a/src/View/Helper/MigrationHelper.php +++ b/src/View/Helper/MigrationHelper.php @@ -530,9 +530,9 @@ public function stringifyList(array $list, array $options = [], array $wantedOpt $join = ', '; if ($options['indent']) { $join = ','; - $start = "\n" . str_repeat(" ", $options['indent']); + $start = "\n" . str_repeat(' ', $options['indent']); $join .= $start; - $end = "\n" . str_repeat(" ", $options['indent'] - 1); + $end = "\n" . str_repeat(' ', $options['indent'] - 1); } return $start . implode($join, $list) . ',' . $end; diff --git a/tests/MigratorTestTrait.php b/tests/MigratorTestTrait.php index a8f858031..e5911f3d8 100644 --- a/tests/MigratorTestTrait.php +++ b/tests/MigratorTestTrait.php @@ -20,7 +20,7 @@ trait MigratorTestTrait { public function setDummyConnections(): void { - $testConfig = ['url' => getenv('db_dsn')]; + $testConfig = ['url' => getenv('DB_URL')]; $testConfig['migrations'] = [ ['source' => 'FooSource'], ['plugin' => 'FooPlugin'], diff --git a/tests/TestCase/Command/BakeMigrationDiffCommandTest.php b/tests/TestCase/Command/BakeMigrationDiffCommandTest.php index cb4d393ee..8e55c6868 100644 --- a/tests/TestCase/Command/BakeMigrationDiffCommandTest.php +++ b/tests/TestCase/Command/BakeMigrationDiffCommandTest.php @@ -328,7 +328,7 @@ public function testBakingDiffAddRemove() */ public function getBakeName($name) { - $name .= ucfirst(getenv("DB")); + $name .= ucfirst(getenv('DB')); return $name; } @@ -360,7 +360,7 @@ protected function getMigrations($source = 'MigrationsDiff') */ public function assertCorrectSnapshot($bakeName, $result) { - $dbenv = getenv("DB"); + $dbenv = getenv('DB'); $bakeName = Inflector::underscore($bakeName); if (file_exists($this->_compareBasePath . $dbenv . DS . $bakeName . '.php')) { $this->assertSameAsFile($dbenv . DS . $bakeName . '.php', $result); diff --git a/tests/TestCase/Command/BakeMigrationSnapshotCommandTest.php b/tests/TestCase/Command/BakeMigrationSnapshotCommandTest.php index 3a8e6a273..d91d01395 100644 --- a/tests/TestCase/Command/BakeMigrationSnapshotCommandTest.php +++ b/tests/TestCase/Command/BakeMigrationSnapshotCommandTest.php @@ -116,7 +116,7 @@ public function testNotEmptySnapshot() $generatedMigration = glob($this->migrationPath . '*_TestNotEmptySnapshot*.php'); $this->generatedFiles = $generatedMigration; - $this->generatedFiles[] = $this->migrationPath . "schema-dump-test.lock"; + $this->generatedFiles[] = $this->migrationPath . 'schema-dump-test.lock'; $generatedMigration = basename($generatedMigration[0]); $fileName = pathinfo($generatedMigration, PATHINFO_FILENAME); $this->assertOutputContains('Marking the migration ' . $fileName . ' as migrated...'); @@ -137,7 +137,7 @@ public function testNotEmptySnapshotNoLock() $generatedMigration = glob($this->migrationPath . '*_TestNotEmptySnapshotNoLock*.php'); $this->generatedFiles = $generatedMigration; - $this->generatedFiles[] = $this->migrationPath . "schema-dump-test.lock"; + $this->generatedFiles[] = $this->migrationPath . 'schema-dump-test.lock'; $generatedMigration = basename($generatedMigration[0]); $fileName = pathinfo($generatedMigration, PATHINFO_FILENAME); $this->assertOutputContains('Marking the migration ' . $fileName . ' as migrated...'); @@ -157,7 +157,7 @@ public function testAutoIdDisabledSnapshot() $generatedMigration = glob($this->migrationPath . '*_TestAutoIdDisabledSnapshot*.php'); $this->generatedFiles = $generatedMigration; - $this->generatedFiles[] = $this->migrationPath . "schema-dump-test.lock"; + $this->generatedFiles[] = $this->migrationPath . 'schema-dump-test.lock'; $generatedMigration = basename($generatedMigration[0]); $fileName = pathinfo($generatedMigration, PATHINFO_FILENAME); $this->assertOutputContains('Marking the migration ' . $fileName . ' as migrated...'); @@ -180,7 +180,7 @@ public function testPluginBlog() $generatedMigration = glob($path . '*_TestPluginBlog*.php'); $this->generatedFiles = $generatedMigration; - $this->generatedFiles[] = $path . "schema-dump-test.lock"; + $this->generatedFiles[] = $path . 'schema-dump-test.lock'; $generatedMigration = basename($generatedMigration[0]); $fileName = pathinfo($generatedMigration, PATHINFO_FILENAME); $this->assertOutputContains('Marking the migration ' . $fileName . ' as migrated...'); @@ -231,7 +231,7 @@ public function testFetchTableNames() */ public function getBakeName($name) { - $dbenv = getenv("DB"); + $dbenv = getenv('DB'); if ($dbenv !== 'mysql') { $name .= ucfirst($dbenv); } else { @@ -253,7 +253,7 @@ public function getBakeName($name) */ public function assertCorrectSnapshot($bakeName, $result) { - $dbenv = getenv("DB"); + $dbenv = getenv('DB'); $bakeName = Inflector::underscore($bakeName); if (file_exists($this->_compareBasePath . $dbenv . DS . $bakeName . '.php')) { $this->assertSameAsFile($dbenv . DS . $bakeName . '.php', $result); diff --git a/tests/TestCase/Command/CompletionTest.php b/tests/TestCase/Command/CompletionTest.php index 6e830ffcb..8803735c8 100644 --- a/tests/TestCase/Command/CompletionTest.php +++ b/tests/TestCase/Command/CompletionTest.php @@ -72,8 +72,8 @@ public function testMigrationsOptionsCreate() $this->exec('completion options migrations.migrations create'); $this->assertCount(1, $this->_out->messages()); $output = $this->_out->messages()[0]; - $expected = "--class -l --connection -c --help -h --path --plugin -p --quiet"; - $expected .= " -q --source -s --template -t --verbose -v"; + $expected = '--class -l --connection -c --help -h --path --plugin -p --quiet'; + $expected .= ' -q --source -s --template -t --verbose -v'; $outputExplode = explode(' ', trim($output)); sort($outputExplode); $expectedExplode = explode(' ', $expected); @@ -93,8 +93,8 @@ public function testMigrationsOptionsMarkMigrated() $this->exec('completion options migrations.migrations mark_migrated'); $this->assertCount(1, $this->_out->messages()); $output = $this->_out->messages()[0]; - $expected = "--connection -c --exclude -x --help -h --only -o --plugin -p --quiet -q"; - $expected .= " --source -s --target -t --verbose -v"; + $expected = '--connection -c --exclude -x --help -h --only -o --plugin -p --quiet -q'; + $expected .= ' --source -s --target -t --verbose -v'; $outputExplode = explode(' ', trim($output)); sort($outputExplode); $expectedExplode = explode(' ', $expected); @@ -114,8 +114,8 @@ public function testMigrationsOptionsMigrate() $this->exec('completion options migrations.migrations migrate'); $this->assertCount(1, $this->_out->messages()); $output = $this->_out->messages()[0]; - $expected = "--connection -c --date -d --dry-run -x --fake --help -h --no-lock --plugin -p"; - $expected .= " --quiet -q --source -s --target -t --verbose -v"; + $expected = '--connection -c --date -d --dry-run -x --fake --help -h --no-lock --plugin -p'; + $expected .= ' --quiet -q --source -s --target -t --verbose -v'; $outputExplode = explode(' ', trim($output)); sort($outputExplode); $expectedExplode = explode(' ', $expected); @@ -135,8 +135,8 @@ public function testMigrationsOptionsRollback() $this->exec('completion options migrations.migrations rollback'); $this->assertCount(1, $this->_out->messages()); $output = $this->_out->messages()[0]; - $expected = "--connection -c --date -d --dry-run -x --fake --force -f --help -h --no-lock --plugin -p"; - $expected .= " --quiet -q --source -s --target -t --verbose -v"; + $expected = '--connection -c --date -d --dry-run -x --fake --force -f --help -h --no-lock --plugin -p'; + $expected .= ' --quiet -q --source -s --target -t --verbose -v'; $outputExplode = explode(' ', trim($output)); sort($outputExplode); $expectedExplode = explode(' ', $expected); @@ -156,7 +156,7 @@ public function testMigrationsOptionsStatus() $this->exec('completion options migrations.migrations status'); $this->assertCount(1, $this->_out->messages()); $output = $this->_out->messages()[0]; - $expected = "--connection -c --format -f --help -h --plugin -p --quiet -q --source -s --verbose -v"; + $expected = '--connection -c --format -f --help -h --plugin -p --quiet -q --source -s --verbose -v'; $outputExplode = explode(' ', trim($output)); sort($outputExplode); $expectedExplode = explode(' ', $expected); diff --git a/tests/TestCase/Command/Phinx/CacheBuildTest.php b/tests/TestCase/Command/Phinx/CacheBuildTest.php index e7299c118..1f8295f6f 100644 --- a/tests/TestCase/Command/Phinx/CacheBuildTest.php +++ b/tests/TestCase/Command/Phinx/CacheBuildTest.php @@ -48,7 +48,7 @@ public function setUp(): void $this->connection = ConnectionManager::get('test'); $this->connection->cacheMetadata(true); $this->connection->execute('DROP TABLE IF EXISTS blog'); - $this->connection->execute("CREATE TABLE blog (id int NOT NULL, title varchar(200) NOT NULL)"); + $this->connection->execute('CREATE TABLE blog (id int NOT NULL, title varchar(200) NOT NULL)'); $application = new MigrationsDispatcher('testing'); $this->command = $application->find('orm-cache-build'); $this->streamOutput = new StreamOutput(fopen('php://memory', 'w', false)); diff --git a/tests/TestCase/Command/Phinx/CacheClearTest.php b/tests/TestCase/Command/Phinx/CacheClearTest.php index 2a20ffc0a..b41de841e 100644 --- a/tests/TestCase/Command/Phinx/CacheClearTest.php +++ b/tests/TestCase/Command/Phinx/CacheClearTest.php @@ -49,7 +49,7 @@ public function setUp(): void $this->connection = ConnectionManager::get('test'); $this->connection->cacheMetadata(true); $this->connection->execute('DROP TABLE IF EXISTS blog'); - $this->connection->execute("CREATE TABLE blog (id int NOT NULL, title varchar(200) NOT NULL)"); + $this->connection->execute('CREATE TABLE blog (id int NOT NULL, title varchar(200) NOT NULL)'); $application = new MigrationsDispatcher('testing'); $this->command = $application->find('orm-cache-clear'); $this->streamOutput = new StreamOutput(fopen('php://memory', 'w', false)); diff --git a/tests/TestCase/TestSuite/ConfigReaderTest.php b/tests/TestCase/TestSuite/ConfigReaderTest.php index b31395e96..ed85b7a31 100644 --- a/tests/TestCase/TestSuite/ConfigReaderTest.php +++ b/tests/TestCase/TestSuite/ConfigReaderTest.php @@ -40,12 +40,12 @@ public function testSetConfigFromInjection(): void { $config = [ ['connection' => 'Foo', 'plugin' => 'Bar',], - ['plugin' => 'Bar',] + ['plugin' => 'Bar',], ]; $expect = [ ['connection' => 'Foo', 'plugin' => 'Bar',], - ['plugin' => 'Bar', 'connection' => 'test',] + ['plugin' => 'Bar', 'connection' => 'test',], ]; $this->ConfigReader->readConfig($config); @@ -56,7 +56,7 @@ public function testSetConfigFromInjection(): void public function testSetConfigFromEmptyInjection(): void { $expect = [ - ['connection' => 'test'] + ['connection' => 'test'], ]; $this->ConfigReader->readConfig(); @@ -68,7 +68,7 @@ public function testSetConfigWithConfigureAndInjection(): void { $config1 = [ 'connection' => 'Foo1_testSetConfigWithConfigureAndInjection', - 'plugin' => 'Bar1_testSetConfigWithConfigureAndInjection' + 'plugin' => 'Bar1_testSetConfigWithConfigureAndInjection', ]; $this->ConfigReader->readConfig($config1); diff --git a/tests/TestCase/TestSuite/MigratorTest.php b/tests/TestCase/TestSuite/MigratorTest.php index 5ab7a38f2..70548adb3 100644 --- a/tests/TestCase/TestSuite/MigratorTest.php +++ b/tests/TestCase/TestSuite/MigratorTest.php @@ -56,8 +56,8 @@ public function testMigrate(): void $this->assertSame(['FooMigration'], $fooPluginMigrations); $this->assertSame(['BarMigration'], $barPluginMigrations); - $Letters = TableRegistry::getTableLocator()->get('Letters'); - $this->assertSame('test', $Letters->getConnection()->configName()); + $letters = TableRegistry::getTableLocator()->get('Letters'); + $this->assertSame('test', $letters->getConnection()->configName()); } public function testDropTablesForMissingMigrations(): void diff --git a/tests/TestCase/View/Helper/MigrationHelperTest.php b/tests/TestCase/View/Helper/MigrationHelperTest.php index 65ef4c12e..1fd77d555 100644 --- a/tests/TestCase/View/Helper/MigrationHelperTest.php +++ b/tests/TestCase/View/Helper/MigrationHelperTest.php @@ -79,16 +79,14 @@ public function setUp(): void ]); Cache::clear('_cake_model_'); Cache::enable(); - $this->loadFixtures('Users'); - $this->loadFixtures('SpecialTags'); $this->types = [ 'timestamp' => 'timestamp', ]; $this->values = [ 'null' => null, + 'integerLimit' => null, 'integerNull' => null, - 'integerLimit' => 11, 'precision' => null, 'comment' => null, ]; @@ -96,8 +94,8 @@ public function setUp(): void if (getenv('DB') === 'mysql') { $this->values = [ 'null' => null, - 'integerNull' => null, 'integerLimit' => null, + 'integerNull' => null, 'precision' => null, 'comment' => '', ]; @@ -109,8 +107,8 @@ public function setUp(): void ]; $this->values = [ 'null' => null, + 'integerLimit' => null, 'integerNull' => null, - 'integerLimit' => 10, 'comment' => null, 'precision' => 6, ]; @@ -214,14 +212,11 @@ public function testColumn() { $tableSchema = $this->collection->describe('users'); - $primaryKeyLimit = $this->values['integerLimit']; - if (getenv('PREFER_LOWEST')) { - $primaryKeyLimit = null; - } + $result = $this->helper->column($tableSchema, 'id'); + unset($result['options']['limit']); $this->assertEquals([ 'columnType' => 'integer', 'options' => [ - 'limit' => $primaryKeyLimit, 'null' => false, 'default' => $this->values['integerNull'], 'precision' => null, @@ -229,7 +224,7 @@ public function testColumn() 'signed' => true, 'autoIncrement' => true, ], - ], $this->helper->column($tableSchema, 'id')); + ], $result); $this->assertEquals([ 'columnType' => 'string', @@ -304,20 +299,17 @@ public function testValue() */ public function testAttributes() { - $primaryKeyLimit = $this->values['integerLimit']; - if (getenv('PREFER_LOWEST')) { - $primaryKeyLimit = null; - } + $result = $this->helper->attributes('users', 'id'); + unset($result['limit']); $this->assertEquals([ - 'limit' => $primaryKeyLimit, 'null' => false, 'default' => $this->values['integerNull'], 'precision' => null, 'comment' => $this->values['comment'], 'signed' => true, 'autoIncrement' => true, - ], $this->helper->attributes('users', 'id')); + ], $result); $this->assertEquals([ 'limit' => 256, @@ -351,15 +343,18 @@ public function testAttributes() 'comment' => null, ], $this->helper->attributes('users', 'updated')); + $result = $this->helper->attributes('special_tags', 'article_id'); + // Remove as it is inconsistent between dbs and CI/local. + unset($result['limit']); + $this->assertEquals([ - 'limit' => $this->values['integerLimit'], 'null' => false, 'default' => $this->values['integerNull'], 'precision' => null, 'comment' => $this->values['comment'], 'signed' => true, 'autoIncrement' => null, - ], $this->helper->attributes('special_tags', 'article_id')); + ], $result); } /** @@ -367,7 +362,7 @@ public function testAttributes() */ public function testStringifyList() { - $this->assertSame("", $this->helper->stringifyList([])); + $this->assertSame('', $this->helper->stringifyList([])); $this->assertSame(" 'key' => 'value', ", $this->helper->stringifyList([ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 841a27f9a..678a6f6d0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -41,8 +41,8 @@ define('ROOT', $root . DS . 'tests' . DS . 'test_app'); define('APP_DIR', 'App'); define('APP', ROOT . DS . 'App' . DS); -define('TMP', sys_get_temp_dir() . DS); -define('CACHE', sys_get_temp_dir() . DS . 'cache' . DS); +define('TMP', sys_get_temp_dir() . DS . 'cake-migrations'); +define('CACHE', TMP . DS . 'cache' . DS); if (!defined('CONFIG')) { define('CONFIG', ROOT . DS . 'config' . DS); } diff --git a/tests/test_app/Plugin/BarPlugin/config/Migrations/20200208100000_bar_migration.php b/tests/test_app/Plugin/BarPlugin/config/Migrations/20200208100000_bar_migration.php index a50dd1541..de45c7924 100644 --- a/tests/test_app/Plugin/BarPlugin/config/Migrations/20200208100000_bar_migration.php +++ b/tests/test_app/Plugin/BarPlugin/config/Migrations/20200208100000_bar_migration.php @@ -7,6 +7,7 @@ * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) 2020 Juan Pablo Ramirez and Nicolas Masson + * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link https://webrider.de/ * @since 1.0.0 * @license http://www.opensource.org/licenses/mit-license.php MIT License diff --git a/tests/test_app/Plugin/FooPlugin/config/Migrations/20200208100000_foo_migration.php b/tests/test_app/Plugin/FooPlugin/config/Migrations/20200208100000_foo_migration.php index 4d2e0b28c..41d4a2d04 100644 --- a/tests/test_app/Plugin/FooPlugin/config/Migrations/20200208100000_foo_migration.php +++ b/tests/test_app/Plugin/FooPlugin/config/Migrations/20200208100000_foo_migration.php @@ -7,6 +7,7 @@ * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) 2020 Juan Pablo Ramirez and Nicolas Masson + * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link https://webrider.de/ * @since 1.0.0 * @license http://www.opensource.org/licenses/mit-license.php MIT License