Skip to content

Commit

Permalink
🎉 Creating the simplest possible module
Browse files Browse the repository at this point in the history
- Creating Module that executes the migrations and seeds with each test run
  • Loading branch information
ricardoapaes committed Mar 24, 2022
1 parent e7dc8cd commit d209cb1
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "like/composer-empty",
"name": "codeception-phinx-module",
"dockerComposeFile": [
"../docker-compose.yml"
],
Expand Down
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{
"name": "likesistemas/nomedalib",
"name": "likesistemas/codeception-phinx-module",
"type": "library",
"description": "Descriçãoo da biblioteca.",
"description": "Integração com phinx usando codeception.",
"repositories": [
{"type": "composer", "url": "https://composer.likesistemas.com.br/"}
],
"require": {
"php": ">=5.6"
"php": ">=5.6",
"robmorgan/phinx": "^0.11.7"
},
"require-dev": {
"phpunit/phpunit": "^5.0 || ^9.0"
"phpunit/phpunit": "^5.0 || ^9.0",
"codeception/codeception": "^4.1"
},
"autoload": {
"psr-4": {
"Like\\NomeDaLib\\": "src/"
"Like\\Codeception\\Phinx\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Like\\NomeDaLib\\Tests\\": "tests/"
"Like\\Codeception\\Phinx\\Tests\\": "tests/"
}
},
"authors": [
Expand Down
6 changes: 0 additions & 6 deletions src/NomeDaLib.php

This file was deleted.

46 changes: 46 additions & 0 deletions src/Phinx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Like\Codeception\Phinx;

use Codeception\Module;
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;

class Phinx extends Module {
public function _before(TestInterface $test) {
$populate = $this->getModule('Db')->_getConfig('populate');

if ($populate) {
$this->phinx();
}
}

private function phinx() {
$config = realpath(__DIR__ . '/../../phinx.php');

$app = new PhinxApplication();
$app->setAutoExit(false);

$output = new NullOutput();

$this->run($app, $output, 'migrate', $config);
$this->run($app, $output, 'seed:run', $config);
}

private function run(PhinxApplication $phinx, OutputInterface $output, $commandName, $config, $environment='production') {
$arguments = [
'command' => $commandName,
'--environment' => $environment,
'--configuration' => $config,
'-vvv' => '',
];

$ok = $phinx->run(new ArrayInput($arguments), $output);
if ($ok !== 0) {
trigger_error('Error on phinx execution.', E_USER_ERROR);
}
}
}
12 changes: 0 additions & 12 deletions tests/NomeDaLibTest.php

This file was deleted.

12 changes: 12 additions & 0 deletions tests/PhinxTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Like\NomeDaLib\Tests;

use Like\Codeception\Phinx\Phinx;
use PHPUnit\Framework\TestCase;

class PhinxTest extends TestCase {
public function testInstance() {
$this->assertTrue(class_exists(Phinx::class));
}
}

0 comments on commit d209cb1

Please sign in to comment.