-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
343 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
paths: | ||
code: | ||
"src/": "" | ||
tests: | ||
"tests/": tests\ | ||
phpunit: | ||
base_namespace: tests | ||
base_test_class_name: PHPUnit_Framework_TestCase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\NullDev\Nemesis\Config; | ||
|
||
use NullDev\Nemesis\Config\Config; | ||
use NullDev\Nemesis\Config\ConfigFactory; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class ConfigFactorySpec extends ObjectBehavior | ||
{ | ||
public function let() | ||
{ | ||
$input = [ | ||
'paths' => [ | ||
'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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\NullDev\Nemesis\Config; | ||
|
||
use NullDev\Nemesis\Config\Config; | ||
use NullDev\Skeleton\Path\Psr4Path; | ||
use NullDev\Skeleton\Path\TestPsr4Path; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class ConfigSpec extends ObjectBehavior | ||
{ | ||
public function let(Psr4Path $psr4Path, TestPsr4Path $testPsr4Path) | ||
{ | ||
$this->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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NullDev\Nemesis\Config; | ||
|
||
use NullDev\Skeleton\Path\Psr4Path; | ||
use NullDev\Skeleton\Path\TestPsr4Path; | ||
use Webmozart\Assert\Assert; | ||
|
||
/** | ||
* @see ConfigSpec | ||
* @see ConfigTest | ||
*/ | ||
class Config | ||
{ | ||
/** @var array */ | ||
private $sourceCodePaths = []; | ||
|
||
/** @var array */ | ||
private $testPaths = []; | ||
|
||
/** @var string */ | ||
private $testsNamespace; | ||
|
||
/** @var string */ | ||
private $baseTestClassName; | ||
|
||
public function __construct( | ||
array $sourceCodePaths, | ||
array $testPaths, | ||
string $testsNamespace, | ||
string $baseTestClassName | ||
) { | ||
Assert::allIsInstanceOf($sourceCodePaths, Psr4Path::class); | ||
Assert::allIsInstanceOf($testPaths, TestPsr4Path::class); | ||
|
||
$this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NullDev\Nemesis\Config; | ||
|
||
use NullDev\Skeleton\Path\Psr4Path; | ||
use NullDev\Skeleton\Path\TestPsr4Path; | ||
use Symfony\Component\Yaml\Yaml; | ||
use Webmozart\Assert\Assert; | ||
|
||
/** | ||
* @see ConfigFactorySpec | ||
* @see ConfigFactoryTest | ||
*/ | ||
class ConfigFactory | ||
{ | ||
/** @var array */ | ||
private $sourceCodePaths = []; | ||
/** @var array */ | ||
private $testPaths = []; | ||
/** @var string */ | ||
private $phpunitBaseNamespace; | ||
/** @var string */ | ||
private $phpunitBaseTestClassName; | ||
|
||
public function __construct() | ||
{ | ||
$path = getcwd().'/nemesis.yml'; | ||
$defaultConfig = $this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace tests\NullDev\Nemesis\Config; | ||
|
||
use NullDev\Nemesis\Config\Config; | ||
use NullDev\Nemesis\Config\ConfigFactory; | ||
use tests\NullDev\ContainerSupportedTestCase; | ||
|
||
/** | ||
* @covers \NullDev\Nemesis\Config\ConfigFactory | ||
* @group integration | ||
*/ | ||
class ConfigFactoryTest extends ContainerSupportedTestCase | ||
{ | ||
/** @var ConfigFactory */ | ||
private $configFactory; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->configFactory = $this->getService(ConfigFactory::class); | ||
} | ||
|
||
public function testItReturnsConfigOut(): void | ||
{ | ||
self::assertInstanceOf(Config::class, $this->configFactory->create()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace tests\NullDev\Nemesis\Config; | ||
|
||
use NullDev\Nemesis\Config\Config; | ||
use NullDev\Skeleton\Path\Psr4Path; | ||
use NullDev\Skeleton\Path\TestPsr4Path; | ||
use PHPUnit_Framework_TestCase; | ||
use tests\NullDev\ContainerSupportedTestCase; | ||
|
||
/** | ||
* @covers \NullDev\Nemesis\Config\Config | ||
* @group integration | ||
*/ | ||
class ConfigTest extends ContainerSupportedTestCase | ||
{ | ||
/** @var Config */ | ||
private $config; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->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()); | ||
} | ||
} |