Skip to content

Commit

Permalink
Merge dc549e1 into ffea11b
Browse files Browse the repository at this point in the history
  • Loading branch information
msvrtan committed Jul 28, 2017
2 parents ffea11b + dc549e1 commit 581f86f
Show file tree
Hide file tree
Showing 11 changed files with 643 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/NullDev/Skeleton/File/FileFactorySpec.php
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);
}
}
40 changes: 40 additions & 0 deletions spec/NullDev/Skeleton/File/FileGeneratorSpec.php
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);
}
}
31 changes: 31 additions & 0 deletions spec/NullDev/Skeleton/File/FileResourceSpec.php
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 src/NullDev/Skeleton/Command/ContainerImplementingTrait.php
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);
}
}
Loading

0 comments on commit 581f86f

Please sign in to comment.