diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8e38afb..c07ebaf 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -13,6 +13,7 @@ "eamodio.gitlens", "mhutchie.git-graph", "junstyle.php-cs-fixer", - "janbn.git-last-commit-message" + "janbn.git-last-commit-message", + "seatonjiang.gitmoji-vscode" ] } \ No newline at end of file diff --git a/.env.example b/.env.example index 3cb636c..d0de590 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ GITHUB_TOKEN= -PHP_VERSION=56|73|74|80|81|82|83 +PHP_VERSION=74|80|81|82|83 DB_ENGINE= \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 883b73f..fc17971 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: test: strategy: matrix: - PHP: [56, 74, 80, 81, 82, 83] + PHP: [74, 80, 81, 82, 83] runs-on: ubuntu-latest steps: @@ -26,10 +26,16 @@ jobs: echo "GITHUB_TOKEN=${{ secrets.GH_TOKEN }}" >> .env echo "PHP_VERSION=$PHP_VERSION" >> .env - - name: Prepare environment + - name: Up environment run: | docker compose up -d - echo $(docker run -t --network github jwilder/dockerize -wait tcp://php:9000 -timeout 120s) + + - name: Wait environment + run: | + echo $(docker compose -f docker-compose.wait.yml run --rm wait) + + - name: Environment logs + run: | docker compose ps docker compose logs php @@ -37,12 +43,20 @@ jobs: run: | docker compose exec -T php composer test + - name: Run Lint + run: | + docker compose exec -T php composer lint + - name: Run PHP Stan - if: matrix.PHP != '56' run: | docker compose exec -T php composer analyse - - name: Run PHP CS Fixer - if: matrix.PHP != '56' + - name: Run ECS + run: | + docker compose exec -T php composer fix:ci + + - name: Desligando ambiente + if: ${{ always() }} run: | - docker compose exec -T php composer fix:ci \ No newline at end of file + docker compose exec -T php rm -Rf vendor/ .env + docker compose down --remove-orphans \ No newline at end of file diff --git a/.gitignore b/.gitignore index 461b651..eea106d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,4 @@ desktop.ini /vendor/ .env composer.lock -tests/phpunit.*.xml -.phpunit.result.cache -.php_cs.cache -.php-cs-fixer.cache .mysql-data/ \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php deleted file mode 100644 index 52918dd..0000000 --- a/.php-cs-fixer.php +++ /dev/null @@ -1,53 +0,0 @@ - true, - 'array_syntax' => ['syntax' => 'short'], - 'multiline_whitespace_before_semicolons' => false, - 'echo_tag_syntax' => false, - 'no_unused_imports' => true, - 'not_operator_with_successor_space' => true, - 'no_useless_else' => true, - 'ordered_imports' => ['sort_algorithm' => 'none', 'imports_order' => ['const', 'class', 'function']], - 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_indent' => true, - 'phpdoc_no_package' => true, - 'phpdoc_order' => true, - 'phpdoc_separation' => true, - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_trim' => true, - 'phpdoc_var_without_name' => true, - 'phpdoc_to_comment' => true, - 'single_quote' => true, - 'ternary_operator_spaces' => true, - 'trailing_comma_in_multiline' => true, - 'trim_array_spaces' => true, - 'curly_braces_position' => [ - 'classes_opening_brace' => 'same_line', - 'functions_opening_brace' => 'same_line', - ], - 'visibility_required' => ['elements' => ['property', 'method']], -]; - -$excludes = [ - 'vendor', - '.vscode', - '.github', - '.devcontainer', - 'tests/Support/_generated/', -]; - -$finder = PhpCsFixer\Finder::create() - ->in(__DIR__) - ->exclude($excludes) - ->notName('README.md') - ->notName('*.xml') - ->notName('*.yml') - ->notName('_ide_helper.php') -; - -return (new PhpCsFixer\Config()) - ->setRules($rules) - ->setFinder($finder) - ->setIndent("\t") -; diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 24303e2..0000000 --- a/.php_cs +++ /dev/null @@ -1,58 +0,0 @@ - true, - 'array_syntax' => ['syntax' => 'short'], - 'no_multiline_whitespace_before_semicolons' => true, - 'no_short_echo_tag' => true, - 'no_unused_imports' => true, - 'not_operator_with_successor_space' => true, - 'no_useless_else' => true, - 'ordered_imports' => ['sort_algorithm' => 'none', 'imports_order' => ['const', 'class', 'function']], - 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_indent' => true, - 'phpdoc_no_package' => true, - 'phpdoc_order' => true, - 'phpdoc_separation' => true, - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_trim' => true, - 'phpdoc_var_without_name' => true, - 'phpdoc_to_comment' => true, - 'single_quote' => true, - 'ternary_operator_spaces' => true, - 'trailing_comma_in_multiline_array' => true, - 'trim_array_spaces' => true, - 'braces' => [ - 'allow_single_line_closure' => true, - 'position_after_functions_and_oop_constructs' => 'same' - ] -]; - -$excludes = [ - 'vendor', - 'storage', - 'node_modules', - '.vscode', - '.github', - '.devcontainer', - 'logs', - 'files', - 'k8s', - 'socket', - 'temp' -]; - -$finder = PhpCsFixer\Finder::create() - ->in(__DIR__) - ->exclude($excludes) - ->notName('README.md') - ->notName('*.xml') - ->notName('*.yml') - ->notName('_ide_helper.php') -; - -return PhpCsFixer\Config::create() - ->setRules($rules) - ->setFinder($finder) - ->setIndent("\t") -; \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json index ba0fe32..1ce7d85 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -6,6 +6,7 @@ "eamodio.gitlens", "mhutchie.git-graph", "junstyle.php-cs-fixer", - "janbn.git-last-commit-message" + "janbn.git-last-commit-message", + "seatonjiang.gitmoji-vscode" ] } \ No newline at end of file diff --git a/composer.json b/composer.json index 0265f68..dfc0ada 100644 --- a/composer.json +++ b/composer.json @@ -2,19 +2,19 @@ "name": "likesistemas/codeception-phinx-module", "type": "library", "description": "Integração com phinx usando codeception.", - "repositories": [ - {"type": "composer", "url": "https://composer.likesistemas.com.br/"} - ], "require": { - "php": ">=5.6", + "php": ">=7.4", "robmorgan/phinx": ">=0.10" }, "require-dev": { - "phpunit/phpunit": "^5.0 || ^9.0", "codeception/codeception": "^4.0 || ^5.0", "codeception/module-phpbrowser": "^1.0 || ^2.0", "codeception/module-asserts": "^1.3 || ^2.0", - "codeception/module-db": "^1.1 || ^2.0 || ^3.0" + "codeception/module-db": "^1.1 || ^2.0 || ^3.0", + "phpstan/phpstan": "^2.0", + "rector/rector": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.4", + "symplify/easy-coding-standard": "^12.6" }, "autoload": { "psr-4": { @@ -34,12 +34,15 @@ } ], "scripts": { - "fix": "php-cs-fixer fix --show-progress=dots", - "fix:ci": "php-cs-fixer fix --dry-run --stop-on-violation --show-progress=dots", + "fix": "ecs --fix", + "fix:ci": "ecs", "test": [ "codecept build", "codecept run" ], - "analyse": "phpstan analyse" + "analyse": "phpstan analyse", + "refactor": "rector process", + "refactor:ci": "rector process --dry-run", + "lint": "parallel-lint --colors --exclude vendor/ ." } } diff --git a/db/migrations/20220623110507_my_new_migration.php b/db/migrations/20220623110507_my_new_migration.php index 0e93878..1f3cb80 100644 --- a/db/migrations/20220623110507_my_new_migration.php +++ b/db/migrations/20220623110507_my_new_migration.php @@ -3,7 +3,7 @@ use Phinx\Migration\AbstractMigration; final class MyNewMigration extends AbstractMigration { - public function change() { + public function change(): void { $table = $this->table('user_logins'); $table->addColumn('user_id', 'integer') ->addColumn('created', 'datetime') diff --git a/docker-compose.wait.yml b/docker-compose.wait.yml new file mode 100644 index 0000000..788d847 --- /dev/null +++ b/docker-compose.wait.yml @@ -0,0 +1,12 @@ +networks: + github: + name: github + driver: bridge + +services: + + wait: + image: jwilder/dockerize:latest + command: -wait tcp://php:9000 -timeout 120s + networks: + - github diff --git a/docker-compose.yml b/docker-compose.yml index 050df30..c76f757 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,6 @@ services: image: likesistemas/php-dev:${PHP_VERSION:-56} environment: - GITHUB_TOKEN=$GITHUB_TOKEN - - URL_SENTRY=${URL_SENTRY} - DB_HOST=mysql - DB_MIGRATE=false volumes: diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..b29836a --- /dev/null +++ b/ecs.php @@ -0,0 +1,36 @@ +withPaths([ + __DIR__ . '/src/', + __DIR__ . '/tests/', + ]) + ->withSkip([ + __DIR__ . '/tests/Support/_generated', + ]) + ->withSets([SetList::PSR_12]) + ->withSpacing(Option::INDENTATION_TAB, PHP_EOL) + ->withRules([RemovePHPStormAnnotationFixer::class]) + ->withConfiguredRule( + ArraySyntaxFixer::class, + ['syntax' => 'short'] + ) + ->withConfiguredRule( + CurlyBracesPositionFixer::class, + [ + 'classes_opening_brace' => 'same_line', + 'functions_opening_brace' => 'same_line', + ] + ) + ->withConfiguredRule( + VisibilityRequiredFixer::class, + ['elements' => ['property', 'method']] + ); diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 8363893..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - ./tests/ - - - - - ./src/ - - - - - - - \ No newline at end of file diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..071ddf8 --- /dev/null +++ b/rector.php @@ -0,0 +1,23 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + __DIR__ . '/db', + ]) + ->withPhpVersion(PhpVersion::PHP_74) + ->withPhp74Sets() + ->withImportNames() + ->withSets([ + SetList::TYPE_DECLARATION, + SetList::DEAD_CODE, + SetList::CODE_QUALITY, + SetList::EARLY_RETURN, + ]); diff --git a/src/Phinx.php b/src/Phinx.php index 4bacbcd..ac0cca8 100644 --- a/src/Phinx.php +++ b/src/Phinx.php @@ -9,8 +9,8 @@ use Symfony\Component\Console\Output\BufferedOutput; class Phinx extends Module { - public function _before(TestInterface $test) { - if(! $this->getConfigPopulate()) { + public function _before(TestInterface $test): void { + if (!$this->getConfigPopulate()) { return; } @@ -31,13 +31,13 @@ private function getConfigPopulate() { return $this->getModule('Db')->_getConfig('populate'); } - private function getSeedConfig() { + private function getSeedConfig(): bool { return $this->getConfigBool('seed'); } - private function getConfigBool($config) { + private function getConfigBool(string $config): bool { $seed = $this->_getConfig($config); - if($seed === null) { + if ($seed === null) { $seed = true; } @@ -46,12 +46,12 @@ private function getConfigBool($config) { /** * @param string $environment - * @param bool $seed - * - * @return void */ - private function phinx($environment, $seed) { + private function phinx($environment, bool $seed): void { $config = $this->findConfigPath(); + if ($config === null) { + return; + } $app = new PhinxApplication(); $app->setAutoExit(false); @@ -60,15 +60,15 @@ private function phinx($environment, $seed) { $this->run($app, $output, 'migrate', $config, $environment); - if($seed) { + if ($seed) { $this->run($app, $output, 'seed:run', $config, $environment); } } - private function run(PhinxApplication $phinx, BufferedOutput $output, $commandName, $config, $environment) { + private function run(PhinxApplication $phinx, BufferedOutput $output, string $commandName, string $config, $environment): void { $arguments = [ - 'command' => $commandName, - '--environment' => $environment, + 'command' => $commandName, + '--environment' => $environment, '--configuration' => $config, '-vvv' => '', ]; @@ -79,25 +79,41 @@ private function run(PhinxApplication $phinx, BufferedOutput $output, $commandNa } } - private function findConfigPath() { - $paths = [ + protected function getPathConfig(string $path): string { + return __DIR__ . '/' . $path; + } + + protected function getPathsConfig(): array { + return [ '../../../../tests/phinx.php', + '../../../tests/phinx.php', + '../../tests/phinx.php', + '../tests/phinx.php', + './tests/phinx.php', '../../../../phinx.php', + '../../../phinx.php', '../../phinx.php', - '../phinx.php', // To use inside library tests + '../phinx.php', + './phinx.php', ]; + } + + protected function findConfigPath(): ?string { + $paths = $this->getPathsConfig(); $notFound = []; foreach ($paths as $path) { - $src = __DIR__ . '/' . $path; - if (file_exists($src)) { - return realpath($src); + $src = $this->getPathConfig($path); + if (file_exists($src) && ($realPath = realpath($src)) !== false) { + return $realPath; } $notFound[] = $src; } - trigger_error('Phinx configuration not found. Paths: `' . join('`, `', $notFound) . '`', E_USER_NOTICE); + trigger_error('Phinx configuration not found. Paths: `' . implode('`, `', $notFound) . '`', E_USER_NOTICE); + + return null; } } diff --git a/tests/Support/AcceptanceTester.php b/tests/Support/AcceptanceTester.php index 89caca0..afb3c74 100644 --- a/tests/Support/AcceptanceTester.php +++ b/tests/Support/AcceptanceTester.php @@ -2,6 +2,7 @@ namespace Tests; +use Codeception\Actor; use Tests\_generated\AcceptanceTesterActions; /** @@ -20,7 +21,7 @@ * * @SuppressWarnings(PHPMD) */ -class AcceptanceTester extends \Codeception\Actor { +class AcceptanceTester extends Actor { use AcceptanceTesterActions; /* diff --git a/tests/Support/FunctionalTester.php b/tests/Support/FunctionalTester.php index 63e23c5..0eb986b 100644 --- a/tests/Support/FunctionalTester.php +++ b/tests/Support/FunctionalTester.php @@ -2,6 +2,7 @@ namespace Tests; +use Codeception\Actor; use Tests\_generated\FunctionalTesterActions; /** @@ -20,7 +21,7 @@ * * @SuppressWarnings(PHPMD) */ -class FunctionalTester extends \Codeception\Actor { +class FunctionalTester extends Actor { use FunctionalTesterActions; /* diff --git a/tests/Support/UnitTester.php b/tests/Support/UnitTester.php index 84f244c..d433efd 100644 --- a/tests/Support/UnitTester.php +++ b/tests/Support/UnitTester.php @@ -2,6 +2,7 @@ namespace Tests; +use Codeception\Actor; use Tests\_generated\UnitTesterActions; /** @@ -20,7 +21,7 @@ * * @SuppressWarnings(PHPMD) */ -class UnitTester extends \Codeception\Actor { +class UnitTester extends Actor { use UnitTesterActions; /* diff --git a/tests/Unit/FirstCest.php b/tests/Unit/FirstCest.php index 4710bb3..cbbe9b6 100644 --- a/tests/Unit/FirstCest.php +++ b/tests/Unit/FirstCest.php @@ -5,7 +5,7 @@ use Tests\UnitTester; class FirstCest { - public function tryToTest(UnitTester $I) { + public function tryToTest(UnitTester $I): void { $I->seeNumRecords(0, 'user_logins'); } } diff --git a/tests/Unit/PhinxTest.php b/tests/Unit/PhinxTest.php index c199df9..54fd7d1 100644 --- a/tests/Unit/PhinxTest.php +++ b/tests/Unit/PhinxTest.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; class PhinxTest extends TestCase { - public function testInstance() { + public function testInstance(): void { $this->assertTrue(class_exists(Phinx::class)); } }