Skip to content

Commit 48c86bb

Browse files
committed
Add test for InputMerger
1 parent 1c22cfb commit 48c86bb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Test\Console;
4+
5+
use PHPSemVerChecker\Configuration\Configuration;
6+
use PHPSemVerChecker\Console\Command\CompareCommand;
7+
use PHPSemVerChecker\Console\InputMerger;
8+
use Symfony\Component\Console\Input\StringInput;
9+
10+
class InputMergerTest extends \PHPUnit_Framework_TestCase
11+
{
12+
public function testMerge()
13+
{
14+
$config = new Configuration([]);
15+
// Prepare options and arguments
16+
$config->set('include-before', 'in-before config');
17+
$config->set('source-after', 'src-after config');
18+
19+
// Specify options and arguments for input
20+
$input = new StringInput('--include-before "in-before cli" "src-before cli"');
21+
$command = new CompareCommand();
22+
$input->bind($command->getDefinition());
23+
$this->assertEquals('in-before cli', $input->getOption('include-before'), 'Test setup: Could not prepare input arguments');
24+
25+
$im = new InputMerger();
26+
$im->merge($input, $config);
27+
$this->assertEquals('in-before cli', $config->get('include-before'), 'Configuration must be overwritten by CLI option');
28+
$this->assertEquals('src-before cli', $config->get('source-before'), 'Configuration must be overwritten by CLI argument');
29+
$this->assertEquals('src-before cli', $input->getArgument('source-before'), 'Input arguments must not be overwritten by empty configuration');
30+
$this->assertEquals('src-after config', $config->get('source-after'), 'Configuration must not be overwritten by empty CLI argument');
31+
$this->assertEquals('src-after config', $input->getArgument('source-after'), 'Missing input arguments must take on existing configuration');
32+
}
33+
}

0 commit comments

Comments
 (0)