Skip to content

Commit

Permalink
Make command test a little cleaner
Browse files Browse the repository at this point in the history
- clearer ordering of methods
- messages on assertions to help with failures
  • Loading branch information
dank00 committed Jan 5, 2018
1 parent 7fb6798 commit 2083809
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions test/EnvironmentConfigurationCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ class EnvironmentConfigurationCommandTest extends TestCase
/** @var EnvironmentConfigurationCommand */
private $subject;

public function testConfigure()
{
self::assertEquals(
EnvironmentConfigurationCommand::COMMAND_NAME,
$this->subject->getName()
);
}

public function testExecuteFailure()
{
$input = $this->getMockForAbstractClass(InputInterface::class);
Expand All @@ -45,41 +37,65 @@ public function testExecuteSuccess()
->with('environment')
->willReturn(Environment::STAGING);

self::assertEquals(0, $this->subject->execute($input, $output));
self::assertEquals(
0,
$this->subject->execute($input, $output),
'Given a valid environment the command should execute and return 0'
);
}

public function testConfigure()
{
self::assertEquals(
EnvironmentConfigurationCommand::COMMAND_NAME,
$this->subject->getName()
);
}

protected function setUp()
{
$mockConfigWriter = new class implements WriterInterface
$this->subject = new EnvironmentConfigurationCommand(
new ConfigValueRepository($this->getDummyConfigWriter()),
$this->getEmptyConfig()
);
}

private function getDummyConfigWriter(): WriterInterface
{
return new class implements WriterInterface
{
public function delete(
$path,
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
$scopeId = 0
) {
)
{
// do nothing
}

public function save(
$path,
$value,
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
$scopeId = 0
) {
)
{
// do nothing
}
};
}

$emptyConfig = new class implements EnvironmentConfigValuesProvider
/**
* @return EnvironmentConfigValuesProvider
*/
protected function getEmptyConfig()
{
return new class implements EnvironmentConfigValuesProvider
{
public function getValues(): EnvironmentConfigValues
{
return EnvironmentConfigValues::create();
}
};

$this->subject = new EnvironmentConfigurationCommand(
new ConfigValueRepository($mockConfigWriter),
$emptyConfig
);
}
}
}

0 comments on commit 2083809

Please sign in to comment.