Add support tests

This commit is contained in:
Anton Medvedev 2017-03-19 01:24:50 +07:00
parent be23ad3c4e
commit 3f52da4a20
5 changed files with 104 additions and 3 deletions

View File

@ -51,7 +51,7 @@ function array_merge_alternate(array $original, array $override)
$original[$key] = array_unique(array_merge($original[$key], $value));
} else {
// Merge all other arrays
$original[$key] = Config::merge($original[$key], $value);
$original[$key] = array_merge_alternate($original[$key], $value);
}
} else {
// Simply add new key/value

View File

@ -0,0 +1,54 @@
<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer\Support;
use PHPUnit\Framework\TestCase;
class HelpersTest extends TestCase
{
public function testArrayFlatten()
{
self::assertEquals(['a', 'b', 'c'], array_flatten(['a', ['b', 'key' => ['c']]]));
}
public function testArrayMergeAlternate()
{
$config = [
'one',
'two' => 2,
'nested' => [],
];
$config = array_merge_alternate($config, [
'two' => 20,
'nested' => [
'first',
],
]);
$config = array_merge_alternate($config, [
'nested' => [
'second',
],
]);
$config = array_merge_alternate($config, [
'extra'
]);
self::assertEquals([
'one',
'two' => 20,
'nested' => [
'first',
'second',
],
'extra',
], $config);
}
}

View File

@ -0,0 +1,27 @@
<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer\Support;
use PHPUnit\Framework\TestCase;
class ProxyTest extends TestCase
{
public function testProxy()
{
$mock = self::getMockBuilder('stdClass')
->setMethods(['foo'])
->getMock();
$mock
->expects(self::once())
->method('foo')
->with('a', 'b');
$proxy = new Proxy([$mock]);
$proxy->foo('a', 'b');
}
}

View File

@ -5,9 +5,8 @@
* file that was distributed with this source code.
*/
namespace Deployer\Utility;
namespace Deployer\Support;
use Deployer\Support\Unix;
use PHPUnit\Framework\TestCase;
class UnixTest extends TestCase

View File

@ -0,0 +1,21 @@
<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer\Utility;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\Output;
class ProcessRunnerTest extends TestCase
{
public function testRun()
{
$output = $this->createMock(Output::class);
$pr = new ProcessRunner();
self::assertEquals('true', $pr->run($output, 'hostname', 'printf "true"'));
}
}