diff --git a/nemesis.yml b/nemesis.yml new file mode 100644 index 00000000..9116d32f --- /dev/null +++ b/nemesis.yml @@ -0,0 +1,8 @@ +paths: + code: + "src/": "" + tests: + "tests/": tests\ +phpunit: + base_namespace: tests + base_test_class_name: PHPUnit_Framework_TestCase diff --git a/spec/NullDev/Nemesis/Config/ConfigFactorySpec.php b/spec/NullDev/Nemesis/Config/ConfigFactorySpec.php new file mode 100644 index 00000000..7a369241 --- /dev/null +++ b/spec/NullDev/Nemesis/Config/ConfigFactorySpec.php @@ -0,0 +1,34 @@ + [ + 'code' => ['src/' => ''], + 'tests' => ['tests/' => 'tests\\'], + ], + ]; + $this->beConstructedWith($input); + } + + public function it_is_initializable() + { + $this->shouldHaveType(ConfigFactory::class); + } + + public function it_will_create_config_file() + { + $this->create() + ->shouldReturnAnInstanceOf(Config::class); + } +} diff --git a/spec/NullDev/Nemesis/Config/ConfigSpec.php b/spec/NullDev/Nemesis/Config/ConfigSpec.php new file mode 100644 index 00000000..39892aa4 --- /dev/null +++ b/spec/NullDev/Nemesis/Config/ConfigSpec.php @@ -0,0 +1,35 @@ +beConstructedWith([$psr4Path], [$testPsr4Path], 'tests', 'PHPUnit_Framework_TestCase'); + } + + public function it_is_initializable() + { + $this->shouldHaveType(Config::class); + } + + public function it_exposes_source_code_paths(Psr4Path $psr4Path) + { + $this->getSourceCodePaths() + ->shouldReturn([$psr4Path]); + } + + public function it_exposes_test_paths(TestPsr4Path $testPsr4Path) + { + $this->getTestPaths() + ->shouldReturn([$testPsr4Path]); + } +} diff --git a/src/NullDev/Nemesis/Config/Config.php b/src/NullDev/Nemesis/Config/Config.php new file mode 100644 index 00000000..63c4646a --- /dev/null +++ b/src/NullDev/Nemesis/Config/Config.php @@ -0,0 +1,68 @@ +sourceCodePaths = $sourceCodePaths; + $this->testPaths = $testPaths; + $this->testsNamespace = $testsNamespace; + $this->baseTestClassName = $baseTestClassName; + } + + public function getSourceCodePaths(): array + { + return $this->sourceCodePaths; + } + + public function getTestPaths(): array + { + return $this->testPaths; + } + + public function getPaths(): array + { + return array_merge($this->testPaths, $this->sourceCodePaths); + } + + public function getTestsNamespace(): string + { + return $this->testsNamespace; + } + + public function getBaseTestClassName(): string + { + return $this->baseTestClassName; + } +} diff --git a/src/NullDev/Nemesis/Config/ConfigFactory.php b/src/NullDev/Nemesis/Config/ConfigFactory.php new file mode 100644 index 00000000..8fd817de --- /dev/null +++ b/src/NullDev/Nemesis/Config/ConfigFactory.php @@ -0,0 +1,98 @@ +getDefaultConfig(); + + if (false === is_file($path)) { + $config = $defaultConfig; + } else { + $config = array_merge($defaultConfig, Yaml::parse(file_get_contents($path))); + } + + Assert::isArray($config['paths']['code']); + Assert::isArray($config['paths']['tests']); + + foreach ($config['paths']['code'] as $path => $namespacePrefix) { + $this->sourceCodePaths[] = new Psr4Path($path, $namespacePrefix); + } + foreach ($config['paths']['tests'] as $path => $namespacePrefix) { + $this->testPaths[] = new TestPsr4Path($path, $namespacePrefix); + } + $this->phpunitBaseNamespace = $config['phpunit']['base_namespace']; + $this->phpunitBaseTestClassName = $config['phpunit']['base_test_class_name']; + } + + public function create(): Config + { + return new Config( + $this->getSourceCodePaths(), + $this->getTestPaths(), + $this->getPhpunitBaseNamespace(), + $this->getPhpunitBaseTestClassName() + ); + } + + private function getDefaultConfig() + { + return [ + 'paths' => [ + 'code' => [ + 'src/' => '', + ], + 'tests' => [ + 'tests/' => 'tests\\', + ], + ], + 'phpunit' => [ + 'base_namespace' => 'tests', + 'base_test_class_name' => 'PHPUnit_Framework_TestCase', + ], + ]; + } + + private function getSourceCodePaths(): array + { + return $this->sourceCodePaths; + } + + private function getTestPaths(): array + { + return $this->testPaths; + } + + private function getPhpunitBaseNamespace(): string + { + return $this->phpunitBaseNamespace; + } + + private function getPhpunitBaseTestClassName(): string + { + return $this->phpunitBaseTestClassName; + } +} diff --git a/src/NullDev/Nemesis/services.yml b/src/NullDev/Nemesis/services.yml index c579836b..21712df9 100644 --- a/src/NullDev/Nemesis/services.yml +++ b/src/NullDev/Nemesis/services.yml @@ -3,3 +3,10 @@ services: autowire: true autoconfigure: true public: true + + NullDev\Nemesis\Config\ConfigFactory: ~ + + NullDev\Nemesis\Config\Config: + class: NullDev\Nemesis\Config\Config + factory: ['@NullDev\Nemesis\Config\ConfigFactory', create] + diff --git a/tests/NullDev/Nemesis/Config/ConfigFactoryTest.php b/tests/NullDev/Nemesis/Config/ConfigFactoryTest.php new file mode 100644 index 00000000..574395e7 --- /dev/null +++ b/tests/NullDev/Nemesis/Config/ConfigFactoryTest.php @@ -0,0 +1,29 @@ +configFactory = $this->getService(ConfigFactory::class); + } + + public function testItReturnsConfigOut(): void + { + self::assertInstanceOf(Config::class, $this->configFactory->create()); + } +} diff --git a/tests/NullDev/Nemesis/Config/ConfigTest.php b/tests/NullDev/Nemesis/Config/ConfigTest.php new file mode 100644 index 00000000..f7181901 --- /dev/null +++ b/tests/NullDev/Nemesis/Config/ConfigTest.php @@ -0,0 +1,64 @@ +config = $this->getService(Config::class); + } + + public function testGetSourceCodePaths(): void + { + $expected = [ + new Psr4Path('src/', ''), + ]; + + self::assertEquals($expected, $this->config->getSourceCodePaths()); + } + + public function testGetTestPaths(): void + { + $expected = [ + new TestPsr4Path('tests/', 'tests\\'), + ]; + + self::assertEquals($expected, $this->config->getTestPaths()); + } + + public function testGetPaths(): void + { + $expected = [ + new TestPsr4Path('tests/', 'tests\\'), + new Psr4Path('src/', ''), + ]; + + self::assertEquals($expected, $this->config->getPaths()); + } + + public function testGetTestsNamespace(): void + { + self::assertEquals('tests', $this->config->getTestsNamespace()); + } + + public function testGetBaseTestClassName(): void + { + self::assertEquals('PHPUnit_Framework_TestCase', $this->config->getBaseTestClassName()); + } +}