Skip to content

Commit 55f34b9

Browse files
authored
Merge pull request #47 from smoench/lazy-commands
use lazy command technique
2 parents 236c238 + 7104381 commit 55f34b9

File tree

10 files changed

+25
-61
lines changed

10 files changed

+25
-61
lines changed

src/AntiMattr/MongoDB/Migrations/Tools/Console/Command/ExecuteCommand.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
*/
2323
class ExecuteCommand extends AbstractCommand
2424
{
25-
const NAME = 'mongodb:migrations:execute';
25+
protected static $defaultName = 'mongodb:migrations:execute';
2626

2727
protected function configure()
2828
{
2929
$this
30-
->setName($this->getName())
3130
->setDescription('Execute a single migration version up or down manually.')
3231
->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null)
3332
->addOption('up', null, InputOption::VALUE_NONE, 'Execute the migration up.')
@@ -85,9 +84,4 @@ public function execute(InputInterface $input, OutputInterface $output)
8584

8685
return 0;
8786
}
88-
89-
public function getName()
90-
{
91-
return self::NAME;
92-
}
9387
}

src/AntiMattr/MongoDB/Migrations/Tools/Console/Command/GenerateCommand.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class GenerateCommand extends AbstractCommand
2323
{
24-
const NAME = 'mongodb:migrations:generate';
24+
protected static $defaultName = 'mongodb:migrations:generate';
2525

2626
private static $_template =
2727
'<?php
@@ -61,7 +61,6 @@ public function down(Database $db)
6161
protected function configure()
6262
{
6363
$this
64-
->setName($this->getName())
6564
->setDescription('Generate a blank migration class.')
6665
->addOption('editor-cmd', null, InputOption::VALUE_OPTIONAL, 'Open file with this command upon creation.')
6766
->setHelp(<<<'EOT'
@@ -103,7 +102,7 @@ public function execute(InputInterface $input, OutputInterface $output)
103102
*
104103
* @return string $path
105104
*
106-
* @throws InvalidArgumentException
105+
* @throws \InvalidArgumentException
107106
*/
108107
protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
109108
{
@@ -178,12 +177,4 @@ protected function getVersionString()
178177
{
179178
return date('YmdHis');
180179
}
181-
182-
/**
183-
* @return string
184-
*/
185-
public function getName()
186-
{
187-
return self::NAME;
188-
}
189180
}

src/AntiMattr/MongoDB/Migrations/Tools/Console/Command/MigrateCommand.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323
*/
2424
class MigrateCommand extends AbstractCommand
2525
{
26-
const NAME = 'mongodb:migrations:migrate';
26+
protected static $defaultName = 'mongodb:migrations:migrate';
2727

2828
protected function configure()
2929
{
3030
$this
31-
->setName($this->getName())
3231
->setDescription('Execute a migration to a specified version or the latest available version.')
3332
->addArgument('version', InputArgument::OPTIONAL, 'The version to migrate to.', null)
3433
->setHelp(<<<'EOT'
@@ -126,9 +125,4 @@ protected function createMigration(Configuration $configuration)
126125
{
127126
return new Migration($configuration);
128127
}
129-
130-
public function getName()
131-
{
132-
return self::NAME;
133-
}
134128
}

src/AntiMattr/MongoDB/Migrations/Tools/Console/Command/StatusCommand.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
*/
2323
class StatusCommand extends AbstractCommand
2424
{
25-
const NAME = 'mongodb:migrations:status';
25+
protected static $defaultName = 'mongodb:migrations:status';
2626

2727
protected function configure()
2828
{
2929
$this
30-
->setName($this->getName())
3130
->setDescription('View the status of a set of migrations.')
3231
->addOption(
3332
'show-versions',
@@ -177,14 +176,4 @@ protected function writeInfoLine(OutputInterface $output, $name, $value)
177176
)
178177
);
179178
}
180-
181-
/**
182-
* getName.
183-
*
184-
* @return string
185-
*/
186-
public function getName()
187-
{
188-
return self::NAME;
189-
}
190179
}

src/AntiMattr/MongoDB/Migrations/Tools/Console/Command/VersionCommand.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
*/
2525
class VersionCommand extends AbstractCommand
2626
{
27-
const NAME = 'mongodb:migrations:version';
27+
protected static $defaultName = 'mongodb:migrations:version';
2828

2929
protected function configure()
3030
{
3131
$this
32-
->setName($this->getName())
3332
->setDescription('Manually add and delete migration versions from the version table.')
3433
->addArgument('version', InputArgument::REQUIRED, 'The version to add or delete.', null)
3534
->addOption('add', null, InputOption::VALUE_NONE, 'Add the specified version.')
@@ -52,8 +51,8 @@ protected function configure()
5251
* @param \Symfony\Component\Console\Input\InputInterface
5352
* @param \Symfony\Component\Console\Output\OutputInterface
5453
*
55-
* @throws AntiMattr\MongoDB\Migrations\Exception\UnknownVersionException Throws exception if migration version does not exist
56-
* @throws InvalidArgumentException
54+
* @throws UnknownVersionException Throws exception if migration version does not exist
55+
* @throws \InvalidArgumentException
5756
*/
5857
public function execute(InputInterface $input, OutputInterface $output)
5958
{
@@ -93,9 +92,4 @@ protected function createMigration(Configuration $configuration)
9392
{
9493
return new Migration($configuration);
9594
}
96-
97-
public function getName()
98-
{
99-
return self::NAME;
100-
}
10195
}

tests/AntiMattr/Tests/MongoDB/Migrations/Tools/Console/Command/ExecuteCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testExecuteDownWithoutInteraction()
3838
$input = new ArgvInput(
3939
[
4040
'application-name',
41-
ExecuteCommand::NAME,
41+
ExecuteCommand::getDefaultName(),
4242
$numVersion,
4343
'--down',
4444
]
@@ -89,7 +89,7 @@ public function testExecuteUpWithInteraction()
8989
$input = new ArgvInput(
9090
[
9191
'application-name',
92-
ExecuteCommand::NAME,
92+
ExecuteCommand::getDefaultName(),
9393
$numVersion,
9494
]
9595
);
@@ -167,7 +167,7 @@ public function testExecuteReplayWithoutInteraction()
167167
$input = new ArgvInput(
168168
[
169169
'application-name',
170-
ExecuteCommand::NAME,
170+
ExecuteCommand::getDefaultName(),
171171
$numVersion,
172172
'--up',
173173
'--replay',

tests/AntiMattr/Tests/MongoDB/Migrations/Tools/Console/Command/GenerateCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testExecute()
4343

4444
$input = new ArgvInput(
4545
[
46-
GenerateCommand::NAME,
46+
GenerateCommand::getDefaultName(),
4747
]
4848
);
4949

@@ -87,7 +87,7 @@ public function testExecuteWithInvalidMigrationDirectory()
8787

8888
$input = new ArgvInput(
8989
[
90-
GenerateCommand::NAME,
90+
GenerateCommand::getDefaultName(),
9191
]
9292
);
9393

tests/AntiMattr/Tests/MongoDB/Migrations/Tools/Console/Command/MigrateCommandTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testExecuteWithExectedUnavailableVersionAndInteraction()
3737
$input = new ArgvInput(
3838
[
3939
'application-name',
40-
MigrateCommand::NAME,
40+
MigrateCommand::getDefaultName(),
4141
$numVersion,
4242
]
4343
);
@@ -103,7 +103,7 @@ public function testExecute()
103103
$numVersion = '000123456789';
104104
$input = new ArgvInput(
105105
[
106-
MigrateCommand::NAME,
106+
MigrateCommand::getDefaultName(),
107107
$numVersion,
108108
]
109109
);
@@ -217,6 +217,8 @@ public function testDefaultSecondInteractionWillCancelMigration()
217217

218218
class MigrateCommandStub extends MigrateCommand
219219
{
220+
protected static $defaultName = 'mongodb:migrations:migrate';
221+
220222
protected $migration;
221223

222224
public function setMigration(Migration $migration)

tests/AntiMattr/Tests/MongoDB/Migrations/Tools/Console/Command/StatusCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testExecuteWithoutShowingVersions()
5353
{
5454
$input = new ArgvInput(
5555
[
56-
StatusCommand::NAME,
56+
StatusCommand::getDefaultName(),
5757
]
5858
);
5959

@@ -213,7 +213,7 @@ public function testExecuteWithShowingVersions()
213213
{
214214
$input = new ArgvInput(
215215
[
216-
StatusCommand::NAME,
216+
StatusCommand::getDefaultName(),
217217
'--show-versions',
218218
]
219219
);

tests/AntiMattr/Tests/MongoDB/Migrations/Tools/Console/Command/VersionCommandTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testInvalidArgumentException()
4040
$numVersion = '123456789012';
4141
$input = new ArgvInput(
4242
[
43-
VersionCommand::NAME,
43+
VersionCommand::getDefaultName(),
4444
$numVersion,
4545
]
4646
);
@@ -61,7 +61,7 @@ public function testUnknownVersionException()
6161
$numVersion = '123456789012';
6262
$input = new ArgvInput(
6363
[
64-
VersionCommand::NAME,
64+
VersionCommand::getDefaultName(),
6565
$numVersion,
6666
'--add',
6767
]
@@ -89,7 +89,7 @@ public function testAddVersion()
8989
$numVersion = '123456789012';
9090
$input = new ArgvInput(
9191
[
92-
VersionCommand::NAME,
92+
VersionCommand::getDefaultName(),
9393
$numVersion,
9494
'--add',
9595
]
@@ -137,7 +137,7 @@ public function testDownVersion()
137137
$numVersion = '123456789012';
138138
$input = new ArgvInput(
139139
[
140-
VersionCommand::NAME,
140+
VersionCommand::getDefaultName(),
141141
$numVersion,
142142
'--delete',
143143
]
@@ -188,7 +188,7 @@ public function testDownOnNonMigratedVersionThrowsInvalidArgumentException()
188188
$numVersion = '123456789012';
189189
$input = new ArgvInput(
190190
[
191-
VersionCommand::NAME,
191+
VersionCommand::getDefaultName(),
192192
$numVersion,
193193
'--delete',
194194
]
@@ -235,7 +235,7 @@ public function testUpOnMigratedVersionThrowsInvalidArgumentException()
235235
$numVersion = '123456789012';
236236
$input = new ArgvInput(
237237
[
238-
VersionCommand::NAME,
238+
VersionCommand::getDefaultName(),
239239
$numVersion,
240240
'--add',
241241
]

0 commit comments

Comments
 (0)