Skip to content

Commit 05ecab4

Browse files
committed
Merge pull request #2 from valiton-forks/backport_1_0
Backport
2 parents a1444ab + 5be42bd commit 05ecab4

File tree

10 files changed

+41
-70
lines changed

10 files changed

+41
-70
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ php:
66
- 5.6
77

88
env:
9+
- SYMFONY_VERSION=2.3.*
910
- SYMFONY_VERSION=2.4.*
1011
- SYMFONY_VERSION=2.5.*
1112
- SYMFONY_VERSION=2.6.*

Command/InitializeCommand.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,14 @@
1111

1212
namespace DTL\Bundle\PhpcrMigrations\Command;
1313

14-
use PHPCR\Migrations\MigratorFactory;
15-
use Symfony\Component\Console\Command\Command;
14+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1615
use Symfony\Component\Console\Input\InputInterface;
1716
use Symfony\Component\Console\Output\OutputInterface;
1817

19-
class InitializeCommand extends Command
18+
class InitializeCommand extends ContainerAwareCommand
2019
{
2120
private $factory;
2221

23-
public function __construct(
24-
MigratorFactory $factory
25-
) {
26-
parent::__construct();
27-
$this->factory = $factory;
28-
}
29-
3022
public function configure()
3123
{
3224
$this->setName('phpcr:migrations:initialize');
@@ -42,6 +34,7 @@ public function configure()
4234

4335
public function execute(InputInterface $input, OutputInterface $output)
4436
{
37+
$this->factory = $this->getContainer()->get('phpcr_migrations.migrator_factory');
4538
$this->factory->getMigrator()->initialize();
4639
}
4740
}

Command/MigrateCommand.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,20 @@
1111

1212
namespace DTL\Bundle\PhpcrMigrations\Command;
1313

14-
use PHPCR\Migrations\MigratorFactory;
15-
use Symfony\Component\Console\Command\Command;
14+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1615
use Symfony\Component\Console\Input\InputArgument;
1716
use Symfony\Component\Console\Input\InputInterface;
1817
use Symfony\Component\Console\Output\OutputInterface;
1918
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
2019
use Symfony\Component\DependencyInjection\ContainerInterface;
2120

22-
class MigrateCommand extends Command
21+
class MigrateCommand extends ContainerAwareCommand
2322
{
2423
private $factory;
25-
private $container;
2624
private $actions = array(
2725
'up', 'down', 'top', 'bottom',
2826
);
2927

30-
public function __construct(
31-
MigratorFactory $factory,
32-
ContainerInterface $container
33-
) {
34-
parent::__construct();
35-
$this->factory = $factory;
36-
$this->container = $container;
37-
}
38-
3928
public function configure()
4029
{
4130
$this->setName('phpcr:migrations:migrate');
@@ -72,12 +61,14 @@ public function configure()
7261

7362
public function execute(InputInterface $input, OutputInterface $output)
7463
{
64+
$this->factory = $this->getContainer()->get('phpcr_migrations.migrator_factory');
65+
7566
$to = $input->getArgument('to');
7667
$migrator = $this->factory->getMigrator();
7768

7869
foreach ($migrator->getVersions() as $version) {
7970
if ($version instanceof ContainerAwareInterface) {
80-
$version->setContainer($this->container);
71+
$version->setContainer($this->getContainer());
8172
}
8273
}
8374

Command/StatusCommand.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,16 @@
1111

1212
namespace DTL\Bundle\PhpcrMigrations\Command;
1313

14-
use PHPCR\Migrations\VersionFinder;
15-
use PHPCR\Migrations\VersionStorage;
16-
use Symfony\Component\Console\Command\Command;
17-
use Symfony\Component\Console\Helper\Table;
14+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15+
use Symfony\Component\Console\Helper\TableHelper;
1816
use Symfony\Component\Console\Input\InputInterface;
1917
use Symfony\Component\Console\Output\OutputInterface;
2018

21-
class StatusCommand extends Command
19+
class StatusCommand extends ContainerAwareCommand
2220
{
2321
private $versionStorage;
2422
private $finder;
2523

26-
public function __construct(
27-
VersionStorage $versionStorage,
28-
VersionFinder $finder
29-
) {
30-
parent::__construct();
31-
$this->versionStorage = $versionStorage;
32-
$this->finder = $finder;
33-
}
3424

3525
public function configure()
3626
{
@@ -50,11 +40,14 @@ public function configure()
5040

5141
public function execute(InputInterface $input, OutputInterface $output)
5242
{
43+
$this->versionStorage = $this->getContainer()->get('phpcr_migrations.version_storage');
44+
$this->finder = $this->getContainer()->get('phpcr_migrations.version_finder');
45+
5346
$versionCollection = $this->finder->getCollection();
5447
$executedVersions = (array) $this->versionStorage->getPersistedVersions();
5548
$currentVersion = $this->versionStorage->getCurrentVersion();
5649

57-
$table = new Table($output);
50+
$table = new TableHelper();
5851
$table->setHeaders(array(
5952
'', 'Version', 'Date', 'Migrated', 'Path',
6053
));
@@ -70,7 +63,7 @@ public function execute(InputInterface $input, OutputInterface $output)
7063
));
7164
}
7265

73-
$table->render();
66+
$table->render($output);
7467

7568
if ($currentVersion) {
7669
$output->writeln(sprintf('<info>Current:</info> %s (%s)', $currentVersion, $this->getDate($currentVersion)));

Resources/config/services.xml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
55

66
<services>
7-
<service id="phpcr_migrations.version_storage" class="PHPCR\Migrations\VersionStorage" public="false">
7+
<service id="phpcr_migrations.version_storage" class="PHPCR\Migrations\VersionStorage">
88
<argument type="service" id="doctrine_phpcr.default_session" />
99
<argument>%phpcr_migrations.version_node_name%</argument>
1010
</service>
1111

12-
<service id="phpcr_migrations.version_finder" class="PHPCR\Migrations\VersionFinder" public="false">
12+
<service id="phpcr_migrations.version_finder" class="PHPCR\Migrations\VersionFinder">
1313
<argument>%phpcr_migrations.paths%</argument>
1414
</service>
1515

@@ -19,23 +19,6 @@
1919
<argument type="service" id="doctrine_phpcr.default_session" />
2020
</service>
2121

22-
<service id="phpcr_migrations.command.status" class="DTL\Bundle\PhpcrMigrations\Command\StatusCommand">
23-
<argument type="service" id="phpcr_migrations.version_storage" />
24-
<argument type="service" id="phpcr_migrations.version_finder" />
25-
<tag name="console.command" />
26-
</service>
27-
28-
<service id="phpcr_migrations.command.migrate" class="DTL\Bundle\PhpcrMigrations\Command\MigrateCommand">
29-
<argument type="service" id="phpcr_migrations.migrator_factory" />
30-
<argument type="service" id="service_container" />
31-
<tag name="console.command" />
32-
</service>
33-
34-
<service id="phpcr_migrations.command.initialize" class="DTL\Bundle\PhpcrMigrations\Command\InitializeCommand">
35-
<argument type="service" id="phpcr_migrations.migrator_factory" />
36-
<tag name="console.command" />
37-
</service>
38-
3922
<service id="phpcr_migrations.migrator_factory" class="PHPCR\Migrations\MigratorFactory">
4023
<argument type="service" id="phpcr_migrations.version_storage" />
4124
<argument type="service" id="phpcr_migrations.version_finder" />

Tests/Functional/BaseTestCase.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace DTL\Bundle\PhpcrMigrations\Tests\Functional;
1313

14+
use DTL\Bundle\PhpcrMigrations\Command\MigrateCommand;
15+
use DTL\Bundle\PhpcrMigrations\Command\StatusCommand;
1416
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase as CmfBaseTestCase;
1517
use Symfony\Component\Console\Tester\CommandTester;
1618

@@ -27,12 +29,22 @@ public function setUp()
2729
}
2830
}
2931

30-
protected function executeCommand($serviceId, $arguments)
32+
protected function executeCommand($command, $arguments)
3133
{
32-
$command = $this->getContainer()->get($serviceId);
34+
$command->setContainer($this->getContainer());
3335
$tester = new CommandTester($command);
3436
$tester->execute($arguments);
3537

3638
return $tester;
3739
}
40+
41+
protected function getMigrateCommand()
42+
{
43+
return new MigrateCommand();
44+
}
45+
46+
protected function getStatusCommand()
47+
{
48+
return new StatusCommand();
49+
}
3850
}

Tests/Functional/MigrateCommandTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MigrateCommandTest extends BaseTestCase
1818
*/
1919
public function testMigrateToLatest()
2020
{
21-
$this->executeCommand('phpcr_migrations.command.migrate', array());
21+
$this->executeCommand($this->getMigrateCommand(), array());
2222

2323
$versionNodes = $this->session->getNode('/jcr:migrations')->getNodes();
2424
$this->assertCount(5, $versionNodes);
@@ -29,7 +29,7 @@ public function testMigrateToLatest()
2929
*/
3030
public function testUpgradeTo()
3131
{
32-
$tester = $this->executeCommand('phpcr_migrations.command.migrate', array('to' => '201401011300'));
32+
$tester = $this->executeCommand($this->getMigrateCommand(), array('to' => '201401011300'));
3333
$display = $tester->getDisplay();
3434

3535
$this->assertContains('Upgrading 1 version', $display);
@@ -43,8 +43,8 @@ public function testUpgradeTo()
4343
*/
4444
public function testUpgradeRevertTo()
4545
{
46-
$tester = $this->executeCommand('phpcr_migrations.command.migrate', array());
47-
$tester = $this->executeCommand('phpcr_migrations.command.migrate', array('to' => '201501011200'));
46+
$tester = $this->executeCommand($this->getMigrateCommand(), array());
47+
$tester = $this->executeCommand($this->getMigrateCommand(), array('to' => '201501011200'));
4848
$display = $tester->getDisplay();
4949

5050
$this->assertContains('Reverting 3 version', $display);

Tests/Functional/StatusCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class StatusCommandTest extends BaseTestCase
1818
*/
1919
public function testShowAll()
2020
{
21-
$tester = $this->executeCommand('phpcr_migrations.command.status', array());
21+
$tester = $this->executeCommand($this->getStatusCommand(), array());
2222
$display = $tester->getDisplay();
2323

2424
$this->assertContains('No migrations have been executed', $display);
@@ -29,8 +29,8 @@ public function testShowAll()
2929
*/
3030
public function testShowCurrentVersion()
3131
{
32-
$tester = $this->executeCommand('phpcr_migrations.command.migrate', array('to' => '201501011500'));
33-
$tester = $this->executeCommand('phpcr_migrations.command.status', array());
32+
$tester = $this->executeCommand($this->getMigrateCommand(), array('to' => '201501011500'));
33+
$tester = $this->executeCommand($this->getStatusCommand(), array());
3434
$display = $tester->getDisplay();
3535

3636
$this->assertContains('201501011500', $display);
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
phpcr_migrations:
22
version_node_name: "jcr:migrations"
3-
paths:
4-
- "%kernel.root_dir%/migrations"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"require": {
1313
"phpcr/phpcr-migrations": "~0.1",
1414
"phpcr/phpcr-implementation": "~2.1",
15-
"doctrine/phpcr-bundle": "~1.2"
15+
"doctrine/phpcr-bundle": "~1.0"
1616
},
1717
"require-dev": {
1818
"symfony/symfony": "~2.4",

0 commit comments

Comments
 (0)