Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates test case to match new implementation #24

Merged
merged 2 commits into from
Jan 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 37 additions & 39 deletions tests/Command/SetupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ final class SetupCommandTest extends TestCase

public function setUp(): void
{
$this->prepareTempDirectory();

/** @var SetupCommand $command */
$command = $this->getMockBuilder(SetupCommand::class)
->setMethods(['getRootDir'])
->getMock();

$command
->method('getRootDir')
->willReturn(sys_get_temp_dir());
->willReturn($this->getTempDirectory());

$application = new Application();
$application->add($command);
Expand All @@ -43,7 +45,7 @@ public function setUp(): void

public function tearDown(): void
{
$this->removeTempFiles();
$this->removeTempDirectory();
}

/**
Expand All @@ -52,12 +54,12 @@ public function tearDown(): void
public function it_creates_config_files(): void
{
$commandTester = new CommandTester($this->command);
$commandTester->setInputs(['gateway', '80', '443', 'y']);
$commandTester->setInputs(['80', '443', 'y']);
$commandTester->execute([]);

$this->assertSame(0, $commandTester->getStatusCode());
$this->assertTrue(file_exists(sys_get_temp_dir() . '/gateway/www.conf'));
$this->assertTrue(file_exists(sys_get_temp_dir() . '/docker-compose.yml'));
$this->assertTrue(file_exists($this->getTempDirectory() . '/gateway/www.conf'));
$this->assertTrue(file_exists($this->getTempDirectory() . '/docker-compose.yml'));
}

/**
Expand All @@ -76,16 +78,13 @@ public function it_answers_with_success_exit_code(array $validInputParameters):
public function getValidInputParameters(): array
{
return [
[['', '', '', 'y']],
[['', '80', '443', 'y']],
[['gateway', '80', '443', 'y']],
[['another/dir', '80', '443', 'y']],
[['gateway', '8080', '443', 'y']],
[['gateway', '', '443', 'y']],
[['gateway', 'random', '443', 'y']],
[['gateway', '80', '', 'y']],
[['gateway', '80', 'random', 'y']],
[['gateway', '', '', 'y']],
[['', '', 'y']],
[['80', '443', 'y']],
[['8080', '443', 'y']],
[['', '443', 'y']],
[['random', '443', 'y']],
[['80', '', 'y']],
[['80', 'random', 'y']],
];
}

Expand Down Expand Up @@ -114,7 +113,7 @@ public function getInvalidInputParameters(): array
*/
public function it_exits_if_docker_compose_file_already_exists(): void
{
touch(sys_get_temp_dir() . '/docker-compose.yml');
touch($this->getTempDirectory() . '/docker-compose.yml');

$commandTester = new CommandTester($this->command);
$commandTester->execute([]);
Expand All @@ -123,30 +122,29 @@ public function it_exits_if_docker_compose_file_already_exists(): void
$this->assertRegExp('/docker-compose.yml exists already/', $commandTester->getDisplay());
}

private function removeTempFiles(): void
private function getTempDirectory(): string
{
return sys_get_temp_dir() . '/prooph_test';
}

private function prepareTempDirectory(): void
{
if (! is_dir($this->getTempDirectory() . '/gateway')) {
mkdir($this->getTempDirectory() . '/gateway', 0777, true);
}
}

private function removeTempDirectory(): void
{
$files = ['gateway', 'docker-compose.yml'];

foreach ($files as $file) {
if (is_file(sys_get_temp_dir() . '/' . $file)) {
unlink(sys_get_temp_dir() . '/' . $file);
}

if (is_dir(sys_get_temp_dir() . '/' . $file)) {
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(
sys_get_temp_dir() . '/' . $file,
\RecursiveDirectoryIterator::SKIP_DOTS
),
\RecursiveIteratorIterator::CHILD_FIRST
);

foreach ($files as $fileInfo) {
$fileInfo->isDir() ? rmdir($fileInfo->getRealPath()) : unlink($fileInfo->getRealPath());
}

rmdir(sys_get_temp_dir() . '/' . $file);
}
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->getTempDirectory(), \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);

foreach ($files as $fileInfo) {
$fileInfo->isDir() ? rmdir($fileInfo->getRealPath()) : unlink($fileInfo->getRealPath());
}

rmdir($this->getTempDirectory());
}
}