From 35be2ce2ad11d0c5813c6979dffaef27020fd2da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Ara=C3=BAjo=20Paes?= <38794747+ricardoapaes@users.noreply.github.com> Date: Tue, 6 Sep 2022 11:46:19 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20Fix=20phinx=20config=20?= =?UTF-8?q?path=20(#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- .php-cs-fixer.php | 2 +- codeception.yml | 6 +++-- composer.json | 9 ++++--- phpstan.neon | 4 ++-- src/Phinx.php | 24 ++++++++++++++++++- ...eptance.suite.yml => Acceptance.suite.yml} | 3 +-- tests/{_data => Acceptance}/.gitkeep | 0 ...ctional.suite.yml => Functional.suite.yml} | 5 ++-- tests/{acceptance => Functional}/.gitkeep | 0 .../AcceptanceTester.php | 7 ++++-- tests/{functional => Support/Data}/.gitkeep | 0 .../FunctionalTester.php | 7 ++++-- tests/{_support => Support}/UnitTester.php | 7 ++++-- tests/Support/_generated/.gitignore | 2 ++ tests/{unit.suite.yml => Unit.suite.yml} | 1 - tests/{unit => Unit}/FirstCest.php | 4 ++++ tests/{unit => Unit}/PhinxTest.php | 0 tests/_output/.gitignore | 2 +- tests/_support/Helper/Acceptance.php | 8 ------- tests/_support/Helper/Functional.php | 8 ------- tests/_support/Helper/Unit.php | 8 ------- tests/_support/_generated/.gitignore | 2 -- 23 files changed, 62 insertions(+), 49 deletions(-) rename tests/{acceptance.suite.yml => Acceptance.suite.yml} (85%) rename tests/{_data => Acceptance}/.gitkeep (100%) rename tests/{functional.suite.yml => Functional.suite.yml} (64%) rename tests/{acceptance => Functional}/.gitkeep (100%) rename tests/{_support => Support}/AcceptanceTester.php (79%) rename tests/{functional => Support/Data}/.gitkeep (100%) rename tests/{_support => Support}/FunctionalTester.php (79%) rename tests/{_support => Support}/UnitTester.php (80%) create mode 100644 tests/Support/_generated/.gitignore rename tests/{unit.suite.yml => Unit.suite.yml} (94%) rename tests/{unit => Unit}/FirstCest.php (71%) rename tests/{unit => Unit}/PhinxTest.php (100%) delete mode 100644 tests/_support/Helper/Acceptance.php delete mode 100644 tests/_support/Helper/Functional.php delete mode 100644 tests/_support/Helper/Unit.php delete mode 100644 tests/_support/_generated/.gitignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33cae43..96f5f90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: test: strategy: matrix: - PHP: [56, 73, 74, 80] + PHP: [56, 73, 74, 80, 81] runs-on: ubuntu-latest steps: diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index a04fa3d..0d7bd20 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -33,7 +33,7 @@ '.vscode', '.github', '.devcontainer', - 'tests/_support/_generated/', + 'tests/Support/_generated/', ]; $finder = PhpCsFixer\Finder::create() diff --git a/codeception.yml b/codeception.yml index f0446cc..1a7adb4 100644 --- a/codeception.yml +++ b/codeception.yml @@ -1,8 +1,10 @@ +namespace: Tests + paths: tests: tests output: tests/_output - data: tests/_data - support: tests/_support + data: tests/Support/Data + support: tests/Support envs: tests/_envs actor_suffix: Tester extensions: diff --git a/composer.json b/composer.json index 6dacce9..0265f68 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "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" + "codeception/module-db": "^1.1 || ^2.0 || ^3.0" }, "autoload": { "psr-4": { @@ -23,7 +23,7 @@ }, "autoload-dev": { "psr-4": { - "Like\\Codeception\\Tests\\": "tests/" + "Tests\\": ["tests/", "tests/Support/"] } }, "authors": [ @@ -36,7 +36,10 @@ "scripts": { "fix": "php-cs-fixer fix --show-progress=dots", "fix:ci": "php-cs-fixer fix --dry-run --stop-on-violation --show-progress=dots", - "test": "codecept run", + "test": [ + "codecept build", + "codecept run" + ], "analyse": "phpstan analyse" } } diff --git a/phpstan.neon b/phpstan.neon index 89943b5..7fe1b3c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,7 +4,7 @@ parameters: - src - tests scanDirectories: - - tests/_support/_generated/ + - tests/Support/_generated/ excludePaths: analyse: - - tests/_support/_generated/ \ No newline at end of file + - tests/Support/_generated/ \ No newline at end of file diff --git a/src/Phinx.php b/src/Phinx.php index f70f43e..52ff469 100644 --- a/src/Phinx.php +++ b/src/Phinx.php @@ -18,7 +18,7 @@ public function _before(TestInterface $test) { } private function phinx() { - $config = realpath(__DIR__ . '/../../phinx.php'); + $config = $this->findConfigPath(); $app = new PhinxApplication(); $app->setAutoExit(false); @@ -42,4 +42,26 @@ private function run(PhinxApplication $phinx, BufferedOutput $output, $commandNa trigger_error("Error on phinx execution.\n\n" . $output->fetch(), E_USER_ERROR); } } + + private function findConfigPath() { + $paths = [ + '../../../../tests/phinx.php', + '../../../../phinx.php', + '../../phinx.php', + '../phinx.php', // To use inside library tests + ]; + + $notFound = []; + + foreach ($paths as $path) { + $src = __DIR__ . '/' . $path; + if (file_exists($src)) { + return realpath($src); + } + + $notFound[] = $src; + } + + trigger_error('Phinx configuration not found. Paths: `' . join('`, `', $notFound) . '`', E_USER_NOTICE); + } } diff --git a/tests/acceptance.suite.yml b/tests/Acceptance.suite.yml similarity index 85% rename from tests/acceptance.suite.yml rename to tests/Acceptance.suite.yml index 6539b99..9229b1f 100644 --- a/tests/acceptance.suite.yml +++ b/tests/Acceptance.suite.yml @@ -9,5 +9,4 @@ modules: enabled: - PhpBrowser: url: http://localhost/myapp - - \Helper\Acceptance -step_decorators: ~ \ No newline at end of file +step_decorators: ~ diff --git a/tests/_data/.gitkeep b/tests/Acceptance/.gitkeep similarity index 100% rename from tests/_data/.gitkeep rename to tests/Acceptance/.gitkeep diff --git a/tests/functional.suite.yml b/tests/Functional.suite.yml similarity index 64% rename from tests/functional.suite.yml rename to tests/Functional.suite.yml index 303c8ac..4ec7b28 100644 --- a/tests/functional.suite.yml +++ b/tests/Functional.suite.yml @@ -2,12 +2,11 @@ # # Suite for functional tests # Emulate web requests and make application process them -# Include one of framework modules (Symfony2, Yii2, Laravel5, Phalcon4) to use it +# Include one of framework modules (Symfony, Yii2, Laravel, Phalcon5) to use it # Remove this suite if you don't use frameworks actor: FunctionalTester modules: enabled: # add a framework module here - - \Helper\Functional - step_decorators: ~ \ No newline at end of file + step_decorators: ~ diff --git a/tests/acceptance/.gitkeep b/tests/Functional/.gitkeep similarity index 100% rename from tests/acceptance/.gitkeep rename to tests/Functional/.gitkeep diff --git a/tests/_support/AcceptanceTester.php b/tests/Support/AcceptanceTester.php similarity index 79% rename from tests/_support/AcceptanceTester.php rename to tests/Support/AcceptanceTester.php index d8c661f..89caca0 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/Support/AcceptanceTester.php @@ -1,5 +1,8 @@ seeNumRecords(0, 'user_logins'); diff --git a/tests/unit/PhinxTest.php b/tests/Unit/PhinxTest.php similarity index 100% rename from tests/unit/PhinxTest.php rename to tests/Unit/PhinxTest.php diff --git a/tests/_output/.gitignore b/tests/_output/.gitignore index c96a04f..d6b7ef3 100644 --- a/tests/_output/.gitignore +++ b/tests/_output/.gitignore @@ -1,2 +1,2 @@ * -!.gitignore \ No newline at end of file +!.gitignore diff --git a/tests/_support/Helper/Acceptance.php b/tests/_support/Helper/Acceptance.php deleted file mode 100644 index 90f4bfb..0000000 --- a/tests/_support/Helper/Acceptance.php +++ /dev/null @@ -1,8 +0,0 @@ -