diff --git a/tests/Unit/Core/Configuration/ValueResolver/ArgvValueResolverTest.php b/tests/Unit/Core/Configuration/ValueResolver/ArgvValueResolverTest.php new file mode 100644 index 00000000..574d9e69 --- /dev/null +++ b/tests/Unit/Core/Configuration/ValueResolver/ArgvValueResolverTest.php @@ -0,0 +1,78 @@ + '/home/john/foo', + 9 => '/bin/phpunit' + ]; + $this->argvValueResolver = new ArgvValueResolver(); + $this->configurationParameterBag = $this->createMock(ConfigurationParameterBag::class); + } + + /** + * @dataProvider dataProviderCollection + */ + public function testArgvValueResolver($value, $expected): void + { + $resolvedValue = $this->argvValueResolver->resolveValue( + $this->configurationParameterBag, + $value + ); + + if (is_array($value) && is_array($expected)) { + foreach ($expected as $key => $val) { + $this->assertEquals($val, $resolvedValue[$key]); + } + + return; + } + + $this->assertEquals($expected, $resolvedValue); + } + + public function dataProviderCollection(): array + { + return [ + 'testSingleValue' => [ + '$value' => '%argv:8%/docs', + '$expected' => '/home/john/foo/docs', + ], + 'testArrayWithPlaceholder' => [ + '$value' => [ + 'project_root' => '%argv:8%/test', + 'output_dir' => '%argv:9%/docs', + ], + '$expected' => [ + 'project_root' => '/home/john/foo/test', + 'output_dir' => '/bin/phpunit/docs', + ], + ], + 'testSingleValueWithoutPlaceholder' => [ + '$value' => 'docs', + '$expected' => 'docs', + ], + 'testDefaultValue' => [ + '$value' => false, + '$expected' => false, + ], + ]; + } +} diff --git a/tests/Unit/Core/Configuration/ValueResolver/InternalValueResolverTest.php b/tests/Unit/Core/Configuration/ValueResolver/InternalValueResolverTest.php new file mode 100644 index 00000000..18db307b --- /dev/null +++ b/tests/Unit/Core/Configuration/ValueResolver/InternalValueResolverTest.php @@ -0,0 +1,77 @@ +internalValueResolver = new InternalValueResolver([ + 'WORKING_DIR' => '/home/john/foo', + 'bin' => '/bin/phpunit' + ]); + $this->configurationParameterBag = $this->createMock(ConfigurationParameterBag::class); + } + + /** + * @dataProvider dataProviderCollection + */ + public function testArgvValueResolver($value, $expected): void + { + $resolvedValue = $this->internalValueResolver->resolveValue( + $this->configurationParameterBag, + $value + ); + + if (is_array($value) && is_array($expected)) { + foreach ($expected as $key => $val) { + $this->assertEquals($val, $resolvedValue[$key]); + } + + return; + } + + $this->assertEquals($expected, $resolvedValue); + } + + public function dataProviderCollection(): array + { + return [ + 'testSingleValue' => [ + '$value' => '%WORKING_DIR%/docs', + '$expected' => '/home/john/foo/docs', + ], + 'testSingleValueWithoutPlaceholder' => [ + '$value' => 'docs', + '$expected' => 'docs', + ], + 'testArrayWithPlaceholder' => [ + '$value' => [ + 'project_root' => '%WORKING_DIR%/test', + 'output_dir' => '%bin%/docs', + ], + '$expected' => [ + 'project_root' => '/home/john/foo/test', + 'output_dir' => '/bin/phpunit/docs', + ], + ], + 'testDefaultValue' => [ + '$value' => false, + '$expected' => false, + ], + ]; + } +} diff --git a/tests/Unit/Core/Configuration/ValueResolver/RefValueResolverTest.php b/tests/Unit/Core/Configuration/ValueResolver/RefValueResolverTest.php new file mode 100644 index 00000000..01f01d13 --- /dev/null +++ b/tests/Unit/Core/Configuration/ValueResolver/RefValueResolverTest.php @@ -0,0 +1,76 @@ +refValueResolver = new RefValueResolver(); + $this->configurationParameterBag = $this->createMock(ConfigurationParameterBag::class); + $this->configurationParameterBag->expects($this->any())->method('get')->willReturn('test'); + } + + /** + * @dataProvider dataProviderCollection + */ + public function testRefValueResolver($value, $expected): void + { + $resolvedValue = $this->refValueResolver->resolveValue( + $this->configurationParameterBag, + $value + ); + + if (is_array($value) && is_array($expected)) { + foreach ($expected as $key => $val) { + $this->assertEquals($val, $resolvedValue[$key]); + } + + return; + } + + $this->assertEquals($expected, $resolvedValue); + } + + public function dataProviderCollection(): array + { + return [ + 'testSingleValue' => [ + '$value' => '%project_root%/docs', + '$expected' => 'test/docs', + ], + 'testArrayWithPlaceholder' => [ + '$value' => [ + 'project_root' => 'test', + 'output_dir' => '%project_root%/docs', + ], + '$expected' => [ + 'project_root' => 'test', + 'output_dir' => 'test/docs', + ], + ], + 'testSingleValueWithoutPlaceholder' => [ + '$value' => 'docs', + '$expected' => 'docs', + ], + 'testDefaultValue' => [ + '$value' => false, + '$expected' => false, + ], + ]; + } +}