Skip to content

Commit

Permalink
Refactoring library (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDievart authored Nov 13, 2018
1 parent e48acfd commit b2d3676
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 75 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ElaoCommandMigration
# CommandMigration

PHP library to run commands, for example on deployment.

Expand All @@ -12,7 +12,7 @@ This library allow you to declare in your feature git branch what command(s) nee

## Install

$ composer require elao/elao-command-migration
$ composer require elao/command-migration

Add a `elao_command_migration.yaml` file (in a not public directory of course!):

Expand Down Expand Up @@ -48,11 +48,11 @@ elao_command_migration:

Entries in `migrations` could have whatever identifier, but we recommend to use a date + time format: YYYYMMDDHHMMSS

Run `php bin/elaoCommandMigration path/to/elao_command_migration.yaml` to test it.
Run `php bin/elao-command-migration path/to/elao_command_migration.yaml` to test it.

## Integration

Add `php bin/elaoCommandMigration path/to/elao_command_migration.yaml`
Add `php bin/elao-command-migration path/to/elao_command_migration.yaml`
to your deployment process.

### Capifony
Expand All @@ -65,7 +65,7 @@ Set in deploy.rb:
namespace :app_tasks do
task :elao_command_migration do
capifony_pretty_print "--> Run command migrations"
invoke_command "php bin/elaoCommandMigration path/to/elao_command_migration.yaml", :via => run_method
invoke_command "php bin/elao-command-migration path/to/elao_command_migration.yaml", :via => run_method
capifony_puts_ok
end
end
Expand All @@ -77,19 +77,19 @@ With [Manala/ansible-role-deploy](https://github.com/manala/ansible-role-deploy)

```yaml
manala_deploy_tasks:
- command: php bin/elaoCommandMigration path/to/elao_command_migration.yaml
- command: php bin/elao-command-migration path/to/elao_command_migration.yaml
```

or

```yaml
manala_deploy_post_tasks:
- command: php bin/elaoCommandMigration path/to/elao_command_migration.yaml
- command: php bin/elao-command-migration path/to/elao_command_migration.yaml
```

## How it works

ElaoCommandMigration is very inspired by [Doctrine Migrations](https://github.com/doctrine/migrations) but
CommandMigration is very inspired by [Doctrine Migrations](https://github.com/doctrine/migrations) but
for running commands.

The `elao:command-migration:run` command :
Expand Down
2 changes: 1 addition & 1 deletion bin/elaoCommandMigration → bin/elao-command-migration
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require __DIR__ . '/../vendor/autoload.php';

use Elao\ElaoCommandMigration\Command\RunCommand;
use Elao\CommandMigration\Command\RunCommand;
use Symfony\Component\Console\Application;

$runCommand = new RunCommand();
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "elao/elao-command-migration",
"name": "elao/command-migration",
"description": "PHP lib to run commands, for example on deployment.",
"license": "MIT",
"keywords": [],
Expand Down Expand Up @@ -27,12 +27,12 @@
],
"autoload": {
"psr-4": {
"Elao\\ElaoCommandMigration\\": "src"
"Elao\\CommandMigration\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Elao\\ElaoCommandMigration\\Tests\\": "tests"
"Elao\\CommandMigration\\Tests\\": "tests"
}
},
"require": {
Expand All @@ -47,5 +47,5 @@
"phpunit/phpunit": "^7.0",
"friendsofphp/php-cs-fixer": "^2.13"
},
"bin": ["bin/elaoCommandMigration"]
"bin": ["bin/elao-command-migration"]
}
10 changes: 1 addition & 9 deletions src/Adapter/ProcessAdapter.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<?php

/*
* This file is part of the ElaoCommandMigration project.
*
* Copyright (C) ElaoCommandMigration
*
* @author Elao <[email protected]>
*/

namespace Elao\ElaoCommandMigration\Adapter;
namespace Elao\CommandMigration\Adapter;

use Symfony\Component\Process\Process;

Expand Down
8 changes: 4 additions & 4 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Elao\ElaoCommandMigration\Command;
namespace Elao\CommandMigration\Command;

use Elao\ElaoCommandMigration\Process\Exception\ConnectionException;
use Elao\ElaoCommandMigration\Process\ResultView;
use Elao\ElaoCommandMigration\Process\Run;
use Elao\CommandMigration\Process\Exception\ConnectionException;
use Elao\CommandMigration\Process\ResultView;
use Elao\CommandMigration\Process\Run;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Elao\ElaoCommandMigration\Configuration\Factory\Doctrine;
namespace Elao\CommandMigration\Configuration\Factory\Doctrine;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ConnectionException;
Expand Down
2 changes: 1 addition & 1 deletion src/Event/MigrationExecutedEvent.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Elao\ElaoCommandMigration\Event;
namespace Elao\CommandMigration\Event;

use Symfony\Component\EventDispatcher\Event;

Expand Down
2 changes: 1 addition & 1 deletion src/Events.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Elao\ElaoCommandMigration;
namespace Elao\CommandMigration;

final class Events
{
Expand Down
4 changes: 2 additions & 2 deletions src/Migration/GetNotExecutedMigrations.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Elao\ElaoCommandMigration\Migration;
namespace Elao\CommandMigration\Migration;

use Elao\ElaoCommandMigration\Storage\StorageInterface;
use Elao\CommandMigration\Storage\StorageInterface;

class GetNotExecutedMigrations
{
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Exception/InvalidYamlSchemaException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Elao\ElaoCommandMigration\Parser\Exception;
namespace Elao\CommandMigration\Parser\Exception;

class InvalidYamlSchemaException extends \Exception
{
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ParserInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Elao\ElaoCommandMigration\Parser;
namespace Elao\CommandMigration\Parser;

interface ParserInterface
{
Expand Down
4 changes: 2 additions & 2 deletions src/Parser/YamlParser.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Elao\ElaoCommandMigration\Parser;
namespace Elao\CommandMigration\Parser;

use Elao\ElaoCommandMigration\Parser\Exception\InvalidYamlSchemaException;
use Elao\CommandMigration\Parser\Exception\InvalidYamlSchemaException;
use Symfony\Component\Yaml\Yaml;

class YamlParser implements ParserInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Process/Exception/ConnectionException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Elao\ElaoCommandMigration\Process\Exception;
namespace Elao\CommandMigration\Process\Exception;

class ConnectionException extends \Exception
{
Expand Down
8 changes: 4 additions & 4 deletions src/Process/ExecuteVersion.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Elao\ElaoCommandMigration\Process;
namespace Elao\CommandMigration\Process;

use Elao\ElaoCommandMigration\Adapter\ProcessAdapter;
use Elao\ElaoCommandMigration\Event\MigrationExecutedEvent;
use Elao\ElaoCommandMigration\Events;
use Elao\CommandMigration\Adapter\ProcessAdapter;
use Elao\CommandMigration\Event\MigrationExecutedEvent;
use Elao\CommandMigration\Events;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class ExecuteVersion
Expand Down
2 changes: 1 addition & 1 deletion src/Process/ResultView.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Elao\ElaoCommandMigration\Process;
namespace Elao\CommandMigration\Process;

class ResultView
{
Expand Down
12 changes: 6 additions & 6 deletions src/Process/Run.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace Elao\ElaoCommandMigration\Process;
namespace Elao\CommandMigration\Process;

use Elao\ElaoCommandMigration\Adapter\ProcessAdapter;
use Elao\ElaoCommandMigration\Migration\GetNotExecutedMigrations;
use Elao\ElaoCommandMigration\Parser\YamlParser;
use Elao\ElaoCommandMigration\Storage\StorageFactory;
use Elao\ElaoCommandMigration\Subscriber\MigrationExecutedSubscriber;
use Elao\CommandMigration\Adapter\ProcessAdapter;
use Elao\CommandMigration\Migration\GetNotExecutedMigrations;
use Elao\CommandMigration\Parser\YamlParser;
use Elao\CommandMigration\Storage\StorageFactory;
use Elao\CommandMigration\Subscriber\MigrationExecutedSubscriber;
use Symfony\Component\EventDispatcher\EventDispatcher;

class Run
Expand Down
4 changes: 2 additions & 2 deletions src/Storage/DoctrineStorage.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace Elao\ElaoCommandMigration\Storage;
namespace Elao\CommandMigration\Storage;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Connections\MasterSlaveConnection;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use Elao\ElaoCommandMigration\Configuration\Factory\Doctrine\DBALConnectionFactory;
use Elao\CommandMigration\Configuration\Factory\Doctrine\DBALConnectionFactory;

final class DoctrineStorage implements StorageInterface
{
Expand Down
4 changes: 2 additions & 2 deletions src/Storage/StorageFactory.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Elao\ElaoCommandMigration\Storage;
namespace Elao\CommandMigration\Storage;

use Elao\ElaoCommandMigration\Parser\Exception\InvalidYamlSchemaException;
use Elao\CommandMigration\Parser\Exception\InvalidYamlSchemaException;

final class StorageFactory
{
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/StorageInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Elao\ElaoCommandMigration\Storage;
namespace Elao\CommandMigration\Storage;

interface StorageInterface
{
Expand Down
8 changes: 4 additions & 4 deletions src/Subscriber/MigrationExecutedSubscriber.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Elao\ElaoCommandMigration\Subscriber;
namespace Elao\CommandMigration\Subscriber;

use Elao\ElaoCommandMigration\Event\MigrationExecutedEvent;
use Elao\ElaoCommandMigration\Events;
use Elao\ElaoCommandMigration\Storage\StorageInterface;
use Elao\CommandMigration\Event\MigrationExecutedEvent;
use Elao\CommandMigration\Events;
use Elao\CommandMigration\Storage\StorageInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MigrationExecutedSubscriber implements EventSubscriberInterface
Expand Down
6 changes: 3 additions & 3 deletions tests/Parser/YamlParserTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Elao\ElaoCommandMigration\Tests\Parser;
namespace Elao\CommandMigration\Tests\Parser;

use Elao\ElaoCommandMigration\Parser\Exception\InvalidYamlSchemaException;
use Elao\ElaoCommandMigration\Parser\YamlParser;
use Elao\CommandMigration\Parser\Exception\InvalidYamlSchemaException;
use Elao\CommandMigration\Parser\YamlParser;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Exception\ParseException;

Expand Down
18 changes: 9 additions & 9 deletions tests/Process/ExecuteVersionTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace Elao\ElaoCommandMigration\Tests\Process;
namespace Elao\CommandMigration\Tests\Process;

use Elao\ElaoCommandMigration\Adapter\ProcessAdapter;
use Elao\ElaoCommandMigration\Event\MigrationExecutedEvent;
use Elao\ElaoCommandMigration\Events;
use Elao\ElaoCommandMigration\Process\ExecuteVersion;
use Elao\ElaoCommandMigration\Process\ResultView;
use Elao\CommandMigration\Adapter\ProcessAdapter;
use Elao\CommandMigration\Event\MigrationExecutedEvent;
use Elao\CommandMigration\Events;
use Elao\CommandMigration\Process\ExecuteVersion;
use Elao\CommandMigration\Process\ResultView;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Process\Process;
Expand All @@ -17,7 +17,7 @@ public function testExecuteVersion(): void
{
$migrations = [
'identifier1' => [
'php bin/elaoCommandMigration inception.yml',
'php bin/elao-command-migration inception.yml',
],
'1234567890' => [
'php -r "echo \"toto\";"',
Expand All @@ -29,7 +29,7 @@ public function testExecuteVersion(): void
$processAdapter = $this->prophesize(ProcessAdapter::class);

$firstProcess = $this->prophesize(Process::class);
$processAdapter->getProcess('php bin/elaoCommandMigration inception.yml')->shouldBeCalled()->willReturn($firstProcess);
$processAdapter->getProcess('php bin/elao-command-migration inception.yml')->shouldBeCalled()->willReturn($firstProcess);
$firstProcess->run()->shouldBeCalled();
$firstProcess->isSuccessful()->shouldBeCalled()->willReturn(false);
$firstProcess->getErrorOutput()->shouldBeCalled()->willReturn('Endless spinning');
Expand All @@ -53,7 +53,7 @@ public function testExecuteVersion(): void
$generators = $executeVersion($migrations);

$expected = [
0 => new ResultView(false, 'php bin/elaoCommandMigration inception.yml', 'Endless spinning'),
0 => new ResultView(false, 'php bin/elao-command-migration inception.yml', 'Endless spinning'),
1 => new ResultView(true, 'php -r "echo \"toto\";"', ''),
2 => new ResultView(true, 'php -r "echo \"test\";"', ''),
];
Expand Down
8 changes: 4 additions & 4 deletions tests/Storage/StorageFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Elao\ElaoCommandMigration\Tests\Storage;
namespace Elao\CommandMigration\Tests\Storage;

use Elao\ElaoCommandMigration\Parser\Exception\InvalidYamlSchemaException;
use Elao\ElaoCommandMigration\Storage\DoctrineStorage;
use Elao\ElaoCommandMigration\Storage\StorageFactory;
use Elao\CommandMigration\Parser\Exception\InvalidYamlSchemaException;
use Elao\CommandMigration\Storage\DoctrineStorage;
use Elao\CommandMigration\Storage\StorageFactory;
use PHPUnit\Framework\TestCase;

class StorageFactoryTest extends TestCase
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/E2ETest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Elao\ElaoCommandMigration\Tests\e2e;
namespace Elao\CommandMigration\Tests\e2e;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;
Expand All @@ -10,7 +10,7 @@ class E2ETest extends TestCase
public function testE2E()
{
$pathToFile = sprintf('%s/elao_command_migration.yaml', __DIR__);
$process = new Process(sprintf('php bin/elaoCommandMigration %s', $pathToFile));
$process = new Process(sprintf('php bin/elao-command-migration %s', $pathToFile));
$process->run();

$this->assertFileExists('elao_command_migration_test.txt');
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/elao_command_migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ elao_command_migration:
dsn: mysql://app:password@mysql/elao_command_migration
table_name: 'command_migrations'
migrations:
20181112153014:
20181112153017:
- php -r "echo \"test\";"
- touch elao_command_migration_test.txt

0 comments on commit b2d3676

Please sign in to comment.