Skip to content

Commit

Permalink
πŸ”€ Merge pull request #1 from likesistemas/feature/show-error-execution
Browse files Browse the repository at this point in the history
* ✨ Adding codeception tests and showing errors on execution
* πŸ’š Fixing errors in composer dependencies
* πŸ’š Fixing bugs using PHP 5.6
* πŸ’š Fixing `php-cs-fixer` errors
  • Loading branch information
ricardoapaes authored Jun 23, 2022
1 parent 8836e19 commit 9b5b52e
Show file tree
Hide file tree
Showing 28 changed files with 260 additions and 20 deletions.
5 changes: 2 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
GITHUB_TOKEN=
CODECOMMIT_USER=
CODECOMMIT_PASSWORD=
PHP_VERSION=56|73|74|80
PHP_VERSION=56|73|74|80
DB_ENGINE=
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ composer.lock
tests/phpunit.*.xml
.phpunit.result.cache
.php_cs.cache
.php-cs-fixer.cache
.php-cs-fixer.cache
.mysql-data/
3 changes: 2 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
'vendor',
'.vscode',
'.github',
'.devcontainer'
'.devcontainer',
'tests/_support/_generated/',
];

$finder = PhpCsFixer\Finder::create()
Expand Down
10 changes: 10 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
12 changes: 12 additions & 0 deletions db/migrations/20220623110507_my_new_migration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use Phinx\Migration\AbstractMigration;

final class MyNewMigration extends AbstractMigration {
public function change() {
$table = $this->table('user_logins');
$table->addColumn('user_id', 'integer')
->addColumn('created', 'datetime')
->create();
}
}
18 changes: 18 additions & 0 deletions docker-compose.phpmyadmin.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 14 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions phinx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

return
[
'paths' => [
'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',
];
7 changes: 6 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ parameters:
level: 5
paths:
- src
- tests
- tests
scanDirectories:
- tests/_support/_generated/
excludePaths:
analyse:
- tests/_support/_generated/
9 changes: 4 additions & 5 deletions src/Phinx.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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);
}
}
}
Empty file added tests/_data/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions tests/_output/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
26 changes: 26 additions & 0 deletions tests/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php


/**
* Inherited Methods
*
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor {
use _generated\AcceptanceTesterActions;

/*
* Define custom actions here
*/
}
26 changes: 26 additions & 0 deletions tests/_support/FunctionalTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php


/**
* Inherited Methods
*
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor {
use _generated\FunctionalTesterActions;

/*
* Define custom actions here
*/
}
8 changes: 8 additions & 0 deletions tests/_support/Helper/Acceptance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Acceptance extends \Codeception\Module {
}
8 changes: 8 additions & 0 deletions tests/_support/Helper/Functional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Functional extends \Codeception\Module {
}
8 changes: 8 additions & 0 deletions tests/_support/Helper/Unit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Unit extends \Codeception\Module {
}
26 changes: 26 additions & 0 deletions tests/_support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php


/**
* Inherited Methods
*
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor {
use _generated\UnitTesterActions;

/*
* Define custom actions here
*/
}
2 changes: 2 additions & 0 deletions tests/_support/_generated/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
13 changes: 13 additions & 0 deletions tests/acceptance.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.

actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://localhost/myapp
- \Helper\Acceptance
step_decorators: ~
Empty file added tests/acceptance/.gitkeep
Empty file.
13 changes: 13 additions & 0 deletions tests/functional.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Codeception Test Suite Configuration
#
# Suite for functional tests
# Emulate web requests and make application process them
# Include one of framework modules (Symfony2, Yii2, Laravel5, Phalcon4) 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: ~
Empty file added tests/functional/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions tests/unit.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Codeception Test Suite Configuration
#
# Suite for unit or integration tests.

actor: UnitTester
modules:
enabled:
- Asserts
- Db
- \Helper\Unit
- Like\Codeception\Phinx
step_decorators: ~
config:
Db:
dsn: 'mysql:host=mysql;dbname=example'
user: 'root'
password: 'root'
populate: true
cleanup: true
Phinx:
depends: Db
7 changes: 7 additions & 0 deletions tests/unit/FirstCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class FirstCest {
public function tryToTest(UnitTester $I) {
$I->seeNumRecords(0, 'user_logins');
}
}
File renamed without changes.

0 comments on commit 9b5b52e

Please sign in to comment.