From 9b5b52ea5ff866064500acb5f8124807b78acccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Ara=C3=BAjo=20Paes?= <38794747+ricardoapaes@users.noreply.github.com> Date: Thu, 23 Jun 2022 10:17:37 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=80=20Merge=20pull=20request=20#1=20fr?= =?UTF-8?q?om=20likesistemas/feature/show-error-execution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ Adding codeception tests and showing errors on execution * 💚 Fixing errors in composer dependencies * 💚 Fixing bugs using PHP 5.6 * 💚 Fixing `php-cs-fixer` errors --- .env.example | 5 ++-- .github/workflows/ci.yml | 2 -- .gitignore | 3 ++- .php-cs-fixer.php | 3 ++- codeception.yml | 10 +++++++ composer.json | 11 +++++--- .../20220623110507_my_new_migration.php | 12 +++++++++ docker-compose.phpmyadmin.yml | 18 +++++++++++++ docker-compose.yml | 17 +++++++++--- phinx.php | 23 ++++++++++++++++ phpstan.neon | 7 ++++- src/Phinx.php | 9 +++---- tests/_data/.gitkeep | 0 tests/_output/.gitignore | 2 ++ tests/_support/AcceptanceTester.php | 26 +++++++++++++++++++ tests/_support/FunctionalTester.php | 26 +++++++++++++++++++ tests/_support/Helper/Acceptance.php | 8 ++++++ tests/_support/Helper/Functional.php | 8 ++++++ tests/_support/Helper/Unit.php | 8 ++++++ tests/_support/UnitTester.php | 26 +++++++++++++++++++ tests/_support/_generated/.gitignore | 2 ++ tests/acceptance.suite.yml | 13 ++++++++++ tests/acceptance/.gitkeep | 0 tests/functional.suite.yml | 13 ++++++++++ tests/functional/.gitkeep | 0 tests/unit.suite.yml | 21 +++++++++++++++ tests/unit/FirstCest.php | 7 +++++ tests/{ => unit}/PhinxTest.php | 0 28 files changed, 260 insertions(+), 20 deletions(-) create mode 100644 codeception.yml create mode 100644 db/migrations/20220623110507_my_new_migration.php create mode 100644 docker-compose.phpmyadmin.yml create mode 100644 phinx.php create mode 100644 tests/_data/.gitkeep create mode 100644 tests/_output/.gitignore create mode 100644 tests/_support/AcceptanceTester.php create mode 100644 tests/_support/FunctionalTester.php create mode 100644 tests/_support/Helper/Acceptance.php create mode 100644 tests/_support/Helper/Functional.php create mode 100644 tests/_support/Helper/Unit.php create mode 100644 tests/_support/UnitTester.php create mode 100644 tests/_support/_generated/.gitignore create mode 100644 tests/acceptance.suite.yml create mode 100644 tests/acceptance/.gitkeep create mode 100644 tests/functional.suite.yml create mode 100644 tests/functional/.gitkeep create mode 100644 tests/unit.suite.yml create mode 100644 tests/unit/FirstCest.php rename tests/{ => unit}/PhinxTest.php (100%) diff --git a/.env.example b/.env.example index 1d69973..8d96b93 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ GITHUB_TOKEN= -CODECOMMIT_USER= -CODECOMMIT_PASSWORD= -PHP_VERSION=56|73|74|80 \ No newline at end of file +PHP_VERSION=56|73|74|80 +DB_ENGINE= \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45f76c4..33cae43 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,8 +23,6 @@ jobs: PHP_VERSION: ${{ matrix.PHP }} run: | touch .env - echo "CODECOMMIT_USER=${{ secrets.CODECOMMIT_USER }}" >> .env - echo "CODECOMMIT_PASSWORD=${{ secrets.CODECOMMIT_PASSWORD }}" >> .env echo "GITHUB_TOKEN=${{ secrets.GH_TOKEN }}" >> .env echo "PHP_VERSION=$PHP_VERSION" >> .env diff --git a/.gitignore b/.gitignore index 2230949..461b651 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ composer.lock tests/phpunit.*.xml .phpunit.result.cache .php_cs.cache -.php-cs-fixer.cache \ No newline at end of file +.php-cs-fixer.cache +.mysql-data/ \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index ebd1d19..a04fa3d 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -32,7 +32,8 @@ 'vendor', '.vscode', '.github', - '.devcontainer' + '.devcontainer', + 'tests/_support/_generated/', ]; $finder = PhpCsFixer\Finder::create() diff --git a/codeception.yml b/codeception.yml new file mode 100644 index 0000000..f0446cc --- /dev/null +++ b/codeception.yml @@ -0,0 +1,10 @@ +paths: + tests: tests + output: tests/_output + data: tests/_data + support: tests/_support + envs: tests/_envs +actor_suffix: Tester +extensions: + enabled: + - Codeception\Extension\RunFailed diff --git a/composer.json b/composer.json index 9244109..6dacce9 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,10 @@ }, "require-dev": { "phpunit/phpunit": "^5.0 || ^9.0", - "codeception/codeception": "^4.1" + "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" }, "autoload": { "psr-4": { @@ -31,9 +34,9 @@ } ], "scripts": { - "fix": "php-cs-fixer fix", - "fix:ci": "php-cs-fixer fix --dry-run --stop-on-violation", - "test": "phpunit", + "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", "analyse": "phpstan analyse" } } diff --git a/db/migrations/20220623110507_my_new_migration.php b/db/migrations/20220623110507_my_new_migration.php new file mode 100644 index 0000000..0e93878 --- /dev/null +++ b/db/migrations/20220623110507_my_new_migration.php @@ -0,0 +1,12 @@ +table('user_logins'); + $table->addColumn('user_id', 'integer') + ->addColumn('created', 'datetime') + ->create(); + } +} diff --git a/docker-compose.phpmyadmin.yml b/docker-compose.phpmyadmin.yml new file mode 100644 index 0000000..3abff23 --- /dev/null +++ b/docker-compose.phpmyadmin.yml @@ -0,0 +1,18 @@ +version: '3.7' + +networks: + github: + name: github + driver: bridge + +services: + + phpmyadmin: + image: phpmyadmin/phpmyadmin:latest + environment: + - PMA_HOSTS=mysql + - UPLOAD_LIMIT=300M + ports: + - ${PMA_PORT:-9000}:80 + networks: + - github \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index d4e9842..050df30 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,12 +9,23 @@ services: php: image: likesistemas/php-dev:${PHP_VERSION:-56} environment: - - CODECOMMIT_HOST=git-codecommit.us-east-1.amazonaws.com - GITHUB_TOKEN=$GITHUB_TOKEN - - CODECOMMIT_USER=$CODECOMMIT_USER - - CODECOMMIT_PASSWORD=$CODECOMMIT_PASSWORD - URL_SENTRY=${URL_SENTRY} + - DB_HOST=mysql + - DB_MIGRATE=false volumes: - ./:/var/www/public/ + networks: + - github + + mysql: + image: ${DB_ENGINE:-mysql:5.5} + command: --innodb-use-native-aio=0 --character-set-server=utf8mb4 --collation-server=utf8mb4_bin + volumes: + - ./.mysql-data/:/var/lib/mysql + environment: + - MYSQL_DATABASE=example + - MYSQL_ROOT_PASSWORD=root + - TZ=America/Fortaleza networks: - github \ No newline at end of file diff --git a/phinx.php b/phinx.php new file mode 100644 index 0000000..77945ab --- /dev/null +++ b/phinx.php @@ -0,0 +1,23 @@ + [ + 'migrations' => '%%PHINX_CONFIG_DIR%%/db/migrations', + 'seeds' => '%%PHINX_CONFIG_DIR%%/db/seeds', + ], + 'environments' => [ + 'default_migration_table' => 'phinxlog', + 'default_environment' => 'production', + 'production' => [ + 'adapter' => 'mysql', + 'host' => 'mysql', + 'name' => 'example', + 'user' => 'root', + 'pass' => 'root', + 'port' => '3306', + 'charset' => 'utf8', + ], + ], + 'version_order' => 'creation', +]; diff --git a/phpstan.neon b/phpstan.neon index 13022a6..89943b5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,4 +2,9 @@ parameters: level: 5 paths: - src - - tests \ No newline at end of file + - tests + scanDirectories: + - tests/_support/_generated/ + excludePaths: + analyse: + - tests/_support/_generated/ \ No newline at end of file diff --git a/src/Phinx.php b/src/Phinx.php index e84de32..f70f43e 100644 --- a/src/Phinx.php +++ b/src/Phinx.php @@ -6,8 +6,7 @@ use Codeception\TestInterface; use Phinx\Console\PhinxApplication; use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Output\NullOutput; -use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\BufferedOutput; class Phinx extends Module { public function _before(TestInterface $test) { @@ -24,13 +23,13 @@ private function phinx() { $app = new PhinxApplication(); $app->setAutoExit(false); - $output = new NullOutput(); + $output = new BufferedOutput(); $this->run($app, $output, 'migrate', $config); $this->run($app, $output, 'seed:run', $config); } - private function run(PhinxApplication $phinx, OutputInterface $output, $commandName, $config, $environment='production') { + private function run(PhinxApplication $phinx, BufferedOutput $output, $commandName, $config, $environment='production') { $arguments = [ 'command' => $commandName, '--environment' => $environment, @@ -40,7 +39,7 @@ private function run(PhinxApplication $phinx, OutputInterface $output, $commandN $ok = $phinx->run(new ArrayInput($arguments), $output); if ($ok !== 0) { - trigger_error('Error on phinx execution.', E_USER_ERROR); + trigger_error("Error on phinx execution.\n\n" . $output->fetch(), E_USER_ERROR); } } } diff --git a/tests/_data/.gitkeep b/tests/_data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/_output/.gitignore b/tests/_output/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/tests/_output/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php new file mode 100644 index 0000000..d8c661f --- /dev/null +++ b/tests/_support/AcceptanceTester.php @@ -0,0 +1,26 @@ +seeNumRecords(0, 'user_logins'); + } +} diff --git a/tests/PhinxTest.php b/tests/unit/PhinxTest.php similarity index 100% rename from tests/PhinxTest.php rename to tests/unit/PhinxTest.php