generated from likesistemas/composer-empty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 Creating the simplest possible module
- Creating Module that executes the migrations and seeds with each test run
- Loading branch information
1 parent
e7dc8cd
commit d209cb1
Showing
6 changed files
with
67 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |