-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from zoilomora/master
Integration with docker, update to PHP 7.4, coding standard.
- Loading branch information
Showing
14 changed files
with
120 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
# phpstorm project files | ||
.idea | ||
|
||
# netbeans project files | ||
nbproject/* | ||
|
||
# zend studio for eclipse project files | ||
.buildpath | ||
.project | ||
.settings | ||
|
||
# windows thumbnail cache | ||
Thumbs.db | ||
|
||
# Mac DS_Store Files | ||
.DS_Store | ||
|
||
/vendor/ | ||
composer.lock | ||
/.idea | ||
.phpunit.result.cache |
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,14 @@ | ||
FROM php:7.4-cli-alpine3.11 | ||
|
||
RUN apk update && \ | ||
apk add --no-cache \ | ||
libzip-dev \ | ||
openssl-dev && \ | ||
docker-php-ext-install -j$(nproc) \ | ||
zip | ||
|
||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer | ||
|
||
ENV PATH /var/app/bin:/var/app/vendor/bin:$PATH | ||
|
||
WORKDIR /var/app |
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,24 @@ | ||
UID=$(shell id -u) | ||
GID=$(shell id -g) | ||
DOCKER_PHP_SERVICE=php | ||
|
||
start: erase cache-folders build composer-install bash | ||
|
||
erase: | ||
docker-compose down -v | ||
|
||
build: | ||
docker-compose build && \ | ||
docker-compose pull | ||
|
||
cache-folders: | ||
mkdir -p ~/.composer && chown ${UID}:${GID} ~/.composer | ||
|
||
composer-install: | ||
docker-compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} composer install | ||
|
||
bash: | ||
docker-compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} sh | ||
|
||
logs: | ||
docker-compose logs -f ${DOCKER_PHP_SERVICE} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: '3.7' | ||
services: | ||
php: | ||
build: . | ||
volumes: | ||
- .:/var/app |
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 |
---|---|---|
@@ -1,17 +1,13 @@ | ||
<?php | ||
/** | ||
* This disaster was designed by | ||
* @author Juan G. Rodríguez Carrión <[email protected]> | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Pccomponentes\Migration\Migration; | ||
use PcComponentes\Migration\Migration; | ||
|
||
class MigrationTested implements Migration | ||
{ | ||
private $constructorArgs; | ||
private $upOperationCalled; | ||
private $downOperationCalled; | ||
private array $constructorArgs; | ||
private bool $upOperationCalled; | ||
private bool $downOperationCalled; | ||
|
||
public function __construct() | ||
{ | ||
|
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 |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?xml version="1.0"?> | ||
<?xml version="1.0" ?> | ||
<ruleset name="Project rules"> | ||
<description>Project rules.</description> | ||
<file>src</file> | ||
<file>tests</file> | ||
<rule ref="PSR2"/> | ||
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"> | ||
<exclude-pattern>tests/*</exclude-pattern> | ||
</rule> | ||
<rule ref="Generic.Files.LineLength.TooLong"> | ||
<exclude-pattern>tests/*</exclude-pattern> | ||
</rule> | ||
<arg name="colors" /> | ||
</ruleset> | ||
<rule ref="vendor/pccomponentes/coding-standard/PccomponentesCodingStandard/ruleset.xml" /> | ||
</ruleset> |
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
<?php | ||
/** | ||
* This disaster was designed by | ||
* @author Juan G. Rodríguez Carrión <[email protected]> | ||
*/ | ||
declare(strict_types=1); | ||
namespace Pccomponentes\Migration; | ||
|
||
namespace PcComponentes\Migration; | ||
|
||
interface Migration | ||
{ | ||
|
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
<?php | ||
/** | ||
* This disaster was designed by | ||
* @author Juan G. Rodríguez Carrión <[email protected]> | ||
*/ | ||
declare(strict_types=1); | ||
namespace Pccomponentes\Migration; | ||
|
||
namespace PcComponentes\Migration; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
@@ -14,14 +11,15 @@ | |
|
||
final class MigrationCommand extends Command | ||
{ | ||
private $loader; | ||
private MigrationLoader $loader; | ||
|
||
private const OPERATION_UP = 'up'; | ||
private const OPERTATION_DOWN = 'down'; | ||
private const OPERATION_DOWN = 'down'; | ||
|
||
public function __construct(string $commandName, string $migrationDir, array $migrationArgs) | ||
{ | ||
parent::__construct("migration:{$commandName}"); | ||
|
||
$this->loader = new MigrationLoader($migrationDir, $migrationArgs); | ||
} | ||
|
||
|
@@ -33,7 +31,7 @@ protected function configure(): void | |
'operation', | ||
'op', | ||
InputOption::VALUE_REQUIRED, | ||
sprintf('Available operations: %s, %s', self::OPERATION_UP, self::OPERTATION_DOWN) | ||
sprintf('Available operations: %s, %s', self::OPERATION_UP, self::OPERATION_DOWN) | ||
) | ||
->addArgument( | ||
'migrations', | ||
|
@@ -53,16 +51,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
case self::OPERATION_UP: | ||
$executor->upOperation(); | ||
return 0; | ||
case self::OPERTATION_DOWN: | ||
case self::OPERATION_DOWN: | ||
$executor->downOperation(); | ||
return 0; | ||
default: | ||
$output->writeln(sprintf('<error>Invalid operation %s</error>', $operation)); | ||
$output->write('<comment>Available operations: </comment>'); | ||
$output->writeln(sprintf('<options=bold>%s, %s</>', self::OPERATION_UP, self::OPERTATION_DOWN)); | ||
$output->writeln(sprintf('<options=bold>%s, %s</>', self::OPERATION_UP, self::OPERATION_DOWN)); | ||
return 1; | ||
} | ||
} catch (\Exception $e) { | ||
} catch (\Throwable $e) { | ||
$output->writeln(sprintf('<error>Exception: %s</error>', $e->getMessage())); | ||
return 1; | ||
} | ||
|
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 |
---|---|---|
@@ -1,14 +1,11 @@ | ||
<?php | ||
/** | ||
* This disaster was designed by | ||
* @author Juan G. Rodríguez Carrión <[email protected]> | ||
*/ | ||
declare(strict_types=1); | ||
namespace Pccomponentes\Migration; | ||
|
||
namespace PcComponentes\Migration; | ||
|
||
final class MigrationExecutor | ||
{ | ||
private $migrations; | ||
private array $migrations; | ||
|
||
public function __construct(array $migrations) | ||
{ | ||
|
@@ -24,7 +21,7 @@ public function upOperation(): void | |
{ | ||
\array_walk( | ||
$this->migrations, | ||
function (Migration $migration) { | ||
static function (Migration $migration) { | ||
$migration->upOperation(); | ||
} | ||
); | ||
|
@@ -34,7 +31,7 @@ public function downOperation(): void | |
{ | ||
\array_walk( | ||
$this->migrations, | ||
function (Migration $migration) { | ||
static function (Migration $migration) { | ||
$migration->downOperation(); | ||
} | ||
); | ||
|
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 |
---|---|---|
@@ -1,15 +1,12 @@ | ||
<?php | ||
/** | ||
* This disaster was designed by | ||
* @author Juan G. Rodríguez Carrión <[email protected]> | ||
*/ | ||
declare(strict_types=1); | ||
namespace Pccomponentes\Migration; | ||
|
||
namespace PcComponentes\Migration; | ||
|
||
final class MigrationLoader | ||
{ | ||
private $dir; | ||
private $migrationArgs; | ||
private string $dir; | ||
private array $migrationArgs; | ||
|
||
public function __construct(string $dir, array $migrationArgs) | ||
{ | ||
|
@@ -19,10 +16,12 @@ public function __construct(string $dir, array $migrationArgs) | |
|
||
public function load(array $migrationClassNames) | ||
{ | ||
return \array_map( | ||
[$this, 'loadOne'], | ||
$migrationClassNames | ||
); | ||
$migrations = []; | ||
foreach ($migrationClassNames as $migrationClassName) { | ||
$migrations[] = $this->loadOne($migrationClassName); | ||
} | ||
|
||
return $migrations; | ||
} | ||
|
||
private function loadOne(string $className): Migration | ||
|
@@ -36,6 +35,7 @@ private function loadOne(string $className): Migration | |
} | ||
|
||
require_once $classFile; | ||
|
||
return (new \ReflectionClass($className))->newInstanceArgs($this->migrationArgs); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,23 +1,20 @@ | ||
<?php | ||
/** | ||
* This disaster was designed by | ||
* @author Juan G. Rodríguez Carrión <[email protected]> | ||
*/ | ||
declare(strict_types=1); | ||
namespace Pccomponentes\Migration\Tests; | ||
|
||
use Pccomponentes\Migration\MigrationCommand; | ||
namespace PcComponentes\Migration\Tests; | ||
|
||
use PcComponentes\Migration\MigrationCommand; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class MigrationCommandTest extends TestCase | ||
{ | ||
private const DIR = __DIR__ . '/../migration'; | ||
|
||
private $command; | ||
private $tester; | ||
private MigrationCommand $command; | ||
private CommandTester $tester; | ||
|
||
public function setUp() | ||
public function setUp(): void | ||
{ | ||
$this->command = new MigrationCommand('test', self::DIR, []); | ||
$this->tester = new CommandTester($this->command); | ||
|
@@ -31,7 +28,7 @@ public function given_a_command_when_execute_it_then_success() | |
$this->tester->execute( | ||
[ | ||
'migrations' => ['MigrationTested'], | ||
'--operation' => 'down' | ||
'--operation' => 'down', | ||
] | ||
); | ||
|
||
|
@@ -46,7 +43,7 @@ public function given_a_invalid_migration_when_execute_the_command_then_fail() | |
$this->tester->execute( | ||
[ | ||
'migrations' => ['Unkonw'], | ||
'--operation' => 'down' | ||
'--operation' => 'down', | ||
] | ||
); | ||
|
||
|
@@ -61,7 +58,7 @@ public function given_a_invalid_operation_when_execute_the_command_then_fail() | |
$this->tester->execute( | ||
[ | ||
'migrations' => ['MigrationTested'], | ||
'--operation' => 'unkonw' | ||
'--operation' => 'unkonw', | ||
] | ||
); | ||
|
||
|
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 |
---|---|---|
@@ -1,19 +1,16 @@ | ||
<?php | ||
/** | ||
* This disaster was designed by | ||
* @author Juan G. Rodríguez Carrión <[email protected]> | ||
*/ | ||
declare(strict_types=1); | ||
namespace Pccomponentes\Migration\Tests; | ||
|
||
use Pccomponentes\Migration\MigrationExecutor; | ||
namespace PcComponentes\Migration\Tests; | ||
|
||
use PcComponentes\Migration\MigrationExecutor; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MigrationExecutorTest extends TestCase | ||
{ | ||
private const DIR = __DIR__ . '/../migration'; | ||
|
||
public function setUp() | ||
public function setUp(): void | ||
{ | ||
include_once self::DIR . '/MigrationTested.php'; | ||
} | ||
|
Oops, something went wrong.