-
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
11 changed files
with
643 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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\NullDev\Skeleton\File; | ||
|
||
use NullDev\Nemesis\Config\Config; | ||
use NullDev\Skeleton\File\FileFactory; | ||
use NullDev\Skeleton\File\FileResource; | ||
use NullDev\Skeleton\Path\Psr0Path; | ||
use NullDev\Skeleton\Source\ImprovedClassSource; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class FileFactorySpec extends ObjectBehavior | ||
{ | ||
public function let(Config $config, Psr0Path $path1) | ||
{ | ||
$config->getPaths()->shouldBeCalled()->willReturn([$path1]); | ||
$this->beConstructedWith($config); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(FileFactory::class); | ||
} | ||
|
||
public function it_will_create_file_resource(ImprovedClassSource $classSource, $path1) | ||
{ | ||
$classSource->getFullName()->willReturn('Namespace\\ClassName'); | ||
$path1->belongsTo('Namespace\\ClassName')->willReturn(true); | ||
|
||
$this->create($classSource)->shouldReturnAnInstanceOf(FileResource::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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\NullDev\Skeleton\File; | ||
|
||
use NullDev\Skeleton\CodeGenerator\PhpParserGenerator; | ||
use NullDev\Skeleton\File\FileGenerator; | ||
use NullDev\Skeleton\File\FileResource; | ||
use NullDev\Skeleton\Source\ImprovedClassSource; | ||
use PhpSpec\ObjectBehavior; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
class FileGeneratorSpec extends ObjectBehavior | ||
{ | ||
public function let(Filesystem $filesystem, PhpParserGenerator $codeGenerator) | ||
{ | ||
$this->beConstructedWith($filesystem, $codeGenerator); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(FileGenerator::class); | ||
} | ||
|
||
public function it_will_create_file( | ||
$filesystem, | ||
$codeGenerator, | ||
FileResource $fileResource, | ||
ImprovedClassSource $classSource | ||
) { | ||
$fileResource->getClassSource()->willReturn($classSource); | ||
$fileResource->getFileName()->willReturn('filename.php'); | ||
$codeGenerator->getOutput($classSource)->willReturn('code'); | ||
|
||
$filesystem->dumpFile('filename.php', 'code')->shouldBeCalled(); | ||
|
||
$this->generate($fileResource)->shouldReturn(true); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\NullDev\Skeleton\File; | ||
|
||
use NullDev\Skeleton\File\FileResource; | ||
use NullDev\Skeleton\Path\Path; | ||
use NullDev\Skeleton\Source\ImprovedClassSource; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class FileResourceSpec extends ObjectBehavior | ||
{ | ||
public function let(Path $path, ImprovedClassSource $classSource) | ||
{ | ||
$classSource->getFullName()->willReturn('Namespace\\ClassName'); | ||
|
||
$this->beConstructedWith($path, $classSource); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(FileResource::class); | ||
} | ||
|
||
public function it_know_file_name($path) | ||
{ | ||
$path->getFileNameFor('Namespace\\ClassName')->willReturn('/var/www/somewhere/src/Namespace/ClassName.php'); | ||
$this->getFileName()->shouldReturn('/var/www/somewhere/src/Namespace/ClassName.php'); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/NullDev/Skeleton/Command/ContainerImplementingTrait.php
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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NullDev\Skeleton\Command; | ||
|
||
use NullDev\Nemesis\Application; | ||
use NullDev\Nemesis\Config\Config; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
trait ContainerImplementingTrait | ||
{ | ||
/** | ||
* @var ContainerInterface|null | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* @throws \LogicException | ||
* | ||
* @return ContainerInterface | ||
*/ | ||
protected function getContainer() | ||
{ | ||
if (null === $this->container) { | ||
/** @var Application $application */ | ||
$application = $this->getApplication(); | ||
if (null === $application) { | ||
throw new \LogicException( | ||
'The container cannot be retrieved as the application instance is not yet set.' | ||
); | ||
} | ||
$this->container = $application->getContainer(); | ||
} | ||
|
||
return $this->container; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setContainer(ContainerInterface $container = null) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
public function getService(string $serviceName) | ||
{ | ||
return $this->getContainer()->get($serviceName); | ||
} | ||
|
||
private function getConfig(): Config | ||
{ | ||
return $this->getService(Config::class); | ||
} | ||
} |
Oops, something went wrong.