Skip to content

Commit

Permalink
Add test for tty/no tty docker-compose exec
Browse files Browse the repository at this point in the history
  • Loading branch information
hranicka committed Sep 12, 2018
1 parent 5892ddb commit 0f9dab8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
29 changes: 14 additions & 15 deletions tests/Tests/Unit/DockerClientTest.php
Expand Up @@ -6,17 +6,9 @@

namespace eZ\Launchpad\Tests\Unit;

use eZ\Launchpad\Core\Client\Docker;
use eZ\Launchpad\Core\ProcessRunner;

class DockerClientTest extends TestCase
{

/**
* @var Docker
*/
protected $client;

/**
* @var array
*/
Expand All @@ -28,13 +20,12 @@ class DockerClientTest extends TestCase
public function setUp()
{
parent::setUp();
$this->client = $this->getDockerClient();
$this->environmentVariables = $this->getDockerClientEnvironmentVariables();
}

public function testEnvVariables()
{
$this->assertEquals($this->environmentVariables, $this->client->getComposeEnvVariables());
$this->assertEquals($this->environmentVariables, $this->getDockerClient()->getComposeEnvVariables());
}

public function testGetCommand()
Expand All @@ -48,7 +39,7 @@ function ($value, $key) {
)->implode(' ');

$expected = "{$prefix} docker-compose -p test -f ".$this->getDockerComposeFilePath();
$this->assertEquals($expected, $this->client->getComposeCommand());
$this->assertEquals($expected, $this->getDockerClient()->getComposeCommand());
}

public function getTestedActions()
Expand All @@ -71,23 +62,31 @@ public function getTestedActions()
['exec', ['/bin/bash', ['-q', '-ez'], 'plop'], 'exec -q -ez plop /bin/bash'],
['exec', ['/bin/bash', [], 'plop'], 'exec plop /bin/bash'],

// no tty
['exec', ['/bin/bash', ['-q', '-ez'], 'plop'], 'exec -T -q -ez plop /bin/bash', false],
['exec', ['/bin/bash', [], 'plop'], 'exec -T plop /bin/bash', false],
];
}

/**
* @dataProvider getTestedActions
*
* @param string $method
* @param array $args
* @param array $args
* @param string $expectedCommandSuffix
* @param bool $hasTty
*/
public function testRun($method, $args, $expectedCommandSuffix)
public function testRun($method, $args, $expectedCommandSuffix, $hasTty = true)
{
$command = "docker-compose -p test -f ".$this->getDockerComposeFilePath();
$mockedResults = call_user_func_array([$this->client, $method], $args);
$client = $this->getDockerClient($hasTty);
$mockedResults = call_user_func_array([$client, $method], $args);

$this->assertCount(2, $mockedResults);
$this->assertEquals($mockedResults[1], $this->environmentVariables);

$command = "docker-compose -p test -f " . $this->getDockerComposeFilePath();
$suffix = trim(str_replace($command, '', $mockedResults[0]));

$this->assertEquals($expectedCommandSuffix, $suffix);
}
}
5 changes: 3 additions & 2 deletions tests/Tests/Unit/TestCase.php
Expand Up @@ -120,9 +120,10 @@ public function getDockerComposeFilePath()
}

/**
* @param bool $hasTty
* @return Docker
*/
public function getDockerClient()
public function getDockerClient($hasTty = true)
{
$options = [
'compose-file' => $this->getDockerComposeFilePath(),
Expand All @@ -146,7 +147,7 @@ function () {

$processRunnerMock
->method('hasTty')
->willReturn(true);
->willReturn($hasTty);

return new Docker($options, $processRunnerMock);
}
Expand Down

0 comments on commit 0f9dab8

Please sign in to comment.