Skip to content

Commit

Permalink
wip: CH for spec/test
Browse files Browse the repository at this point in the history
  • Loading branch information
msvrtan committed Jul 30, 2017
1 parent 9d751ea commit d6f6092
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 0 deletions.
32 changes: 32 additions & 0 deletions spec/NullDev/Skeleton/Uuid/Command/CreateUuidPhpUnitTestSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace spec\NullDev\Skeleton\Uuid\Command;

use NullDev\Skeleton\Definition\PHP\Types\ClassType;
use NullDev\Skeleton\Uuid\Command\CreateUuidPhpUnitTest;
use PhpSpec\ObjectBehavior;

class CreateUuidPhpUnitTestSpec extends ObjectBehavior
{
public function let(ClassType $classType)
{
$this->beConstructedWith('/var/www/somewhere/tests/Namespace/ClassNameTest.php', $classType);
}

public function it_is_initializable()
{
$this->shouldHaveType(CreateUuidPhpUnitTest::class);
}

public function it_will_expose_class_type(ClassType $classType)
{
$this->getClassType()->shouldReturn($classType);
}

public function it_will_expose_fileName()
{
$this->getFileName()->shouldReturn('/var/www/somewhere/tests/Namespace/ClassNameTest.php');
}
}
32 changes: 32 additions & 0 deletions spec/NullDev/Skeleton/Uuid/Command/CreateUuidSpecificationSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace spec\NullDev\Skeleton\Uuid\Command;

use NullDev\Skeleton\Definition\PHP\Types\ClassType;
use NullDev\Skeleton\Uuid\Command\CreateUuidSpecification;
use PhpSpec\ObjectBehavior;

class CreateUuidSpecificationSpec extends ObjectBehavior
{
public function let(ClassType $classType)
{
$this->beConstructedWith('/var/www/somewhere/spec/Namespace/ClassNameSpec.php', $classType);
}

public function it_is_initializable()
{
$this->shouldHaveType(CreateUuidSpecification::class);
}

public function it_will_expose_class_type(ClassType $classType)
{
$this->getClassType()->shouldReturn($classType);
}

public function it_will_expose_fileName()
{
$this->getFileName()->shouldReturn('/var/www/somewhere/spec/Namespace/ClassNameSpec.php');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace spec\NullDev\Skeleton\Uuid\Handler;

use NullDev\PHPUnitSkeleton\PHPUnitTestGenerator;
use NullDev\Skeleton\CodeGenerator\PhpParserGenerator;
use NullDev\Skeleton\Definition\PHP\Types\ClassType;
use NullDev\Skeleton\Source\ImprovedClassSource;
use NullDev\Skeleton\Uuid\Command\CreateUuidPhpUnitTest;
use NullDev\Skeleton\Uuid\Handler\CreateUuidPhpUnitHandler;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Filesystem\Filesystem;

class CreateUuidPhpUnitHandlerSpec extends ObjectBehavior
{
public function let(
PHPUnitTestGenerator $testGenerator,
PhpParserGenerator $codeGenerator,
Filesystem $filesystem
) {
$this->beConstructedWith($testGenerator, $codeGenerator, $filesystem);
}

public function it_is_initializable()
{
$this->shouldHaveType(CreateUuidPhpUnitHandler::class);
}

public function it_will_handle_creating_uuid_test(
CreateUuidPhpUnitTest $command,
ImprovedClassSource $classSource,
ClassType $classType,
PHPUnitTestGenerator $testGenerator,
PhpParserGenerator $codeGenerator,
Filesystem $filesystem,
ImprovedClassSource $phpUnitTestSource
) {
$command->getClassSource()
->shouldBeCalled()
->willReturn($classSource);

$command->getFileName()
->shouldBeCalled()
->willReturn('/path/filename.php');

$testGenerator->generate($classSource)
->shouldBeCalled()
->willReturn($phpUnitTestSource);

$codeGenerator->getOutput($phpUnitTestSource)
->shouldBeCalled()
->willReturn('output');

$filesystem->dumpFile('/path/filename.php', 'output')
->shouldBeCalled();

$this->handle($command);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace spec\NullDev\Skeleton\Uuid\Handler;

use NullDev\PhpSpecSkeleton\SpecGenerator;
use NullDev\Skeleton\CodeGenerator\PhpParserGenerator;
use NullDev\Skeleton\Definition\PHP\Types\ClassType;
use NullDev\Skeleton\Source\ImprovedClassSource;
use NullDev\Skeleton\Uuid\Command\CreateUuidSpecification;
use NullDev\Skeleton\Uuid\Handler\CreateUuidSpecificationHandler;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Filesystem\Filesystem;

class CreateUuidSpecificationHandlerSpec extends ObjectBehavior
{
public function let(
SpecGenerator $specGenerator,
PhpParserGenerator $codeGenerator,
Filesystem $filesystem
) {
$this->beConstructedWith($specGenerator, $codeGenerator, $filesystem);
}

public function it_is_initializable()
{
$this->shouldHaveType(CreateUuidSpecificationHandler::class);
}

public function it_will_handle_creating_uuid_specification(
CreateUuidSpecification $command,
ImprovedClassSource $classSource,
ClassType $classType,
SpecGenerator $specGenerator,
PhpParserGenerator $codeGenerator,
Filesystem $filesystem,
ImprovedClassSource $specificationSource
) {
$command->getClassSource()
->shouldBeCalled()
->willReturn($classSource);

$command->getFileName()
->shouldBeCalled()
->willReturn('/path/filename.php');

$specGenerator->generate($classSource)
->shouldBeCalled()
->willReturn($specificationSource);

$codeGenerator->getOutput($specificationSource)
->shouldBeCalled()
->willReturn('output');

$filesystem->dumpFile('/path/filename.php', 'output')
->shouldBeCalled();

$this->handle($command);
}
}
41 changes: 41 additions & 0 deletions src/NullDev/Skeleton/Uuid/Command/CreateUuidPhpUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace NullDev\Skeleton\Uuid\Command;

use NullDev\Skeleton\Definition\PHP\Types\ClassType;
use NullDev\Skeleton\Source\ImprovedClassSource;

/**
* @see CreateUuidPhpUnitTestSpec
* @see CreateUuidPhpUnitTestTest
*/
class CreateUuidPhpUnitTest
{
/** @var string */
private $fileName;
/** @var ClassType */
private $classType;

public function __construct(string $fileName, ClassType $classType)
{
$this->fileName = $fileName;
$this->classType = $classType;
}

public function getFileName(): string
{
return $this->fileName;
}

public function getClassType(): ClassType
{
return $this->classType;
}

public function getClassSource(): ImprovedClassSource
{
return new ImprovedClassSource($this->classType);
}
}
41 changes: 41 additions & 0 deletions src/NullDev/Skeleton/Uuid/Command/CreateUuidSpecification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace NullDev\Skeleton\Uuid\Command;

use NullDev\Skeleton\Definition\PHP\Types\ClassType;
use NullDev\Skeleton\Source\ImprovedClassSource;

/**
* @see CreateUuidSpecificationSpec
* @see CreateUuidSpecificationTest
*/
class CreateUuidSpecification
{
/** @var string */
private $fileName;
/** @var ClassType */
private $classType;

public function __construct(string $fileName, ClassType $classType)
{
$this->fileName = $fileName;
$this->classType = $classType;
}

public function getFileName(): string
{
return $this->fileName;
}

public function getClassType(): ClassType
{
return $this->classType;
}

public function getClassSource(): ImprovedClassSource
{
return new ImprovedClassSource($this->classType);
}
}
42 changes: 42 additions & 0 deletions src/NullDev/Skeleton/Uuid/Handler/CreateUuidPhpUnitHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace NullDev\Skeleton\Uuid\Handler;

use NullDev\PHPUnitSkeleton\PHPUnitTestGenerator;
use NullDev\Skeleton\CodeGenerator\PhpParserGenerator;
use NullDev\Skeleton\Uuid\Command\CreateUuidPhpUnitTest;
use Symfony\Component\Filesystem\Filesystem;

/**
* @see CreateUuidPhpUnitHandlerSpec
* @see CreateUuidPhpUnitHandlerTest
*/
class CreateUuidPhpUnitHandler
{
/** @var PHPUnitTestGenerator */
private $testGenerator;
/** @var PhpParserGenerator */
private $codeGenerator;
/** @var Filesystem */
private $filesystem;

public function __construct(PHPUnitTestGenerator $testGenerator,
PhpParserGenerator $codeGenerator,
Filesystem $filesystem)
{
$this->testGenerator = $testGenerator;
$this->codeGenerator = $codeGenerator;
$this->filesystem = $filesystem;
}

public function handle(CreateUuidPhpUnitTest $command): void
{
$phpUnitTestSource = $this->testGenerator->generate($command->getClassSource());

$output = $this->codeGenerator->getOutput($phpUnitTestSource);

$this->filesystem->dumpFile($command->getFileName(), $output);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace NullDev\Skeleton\Uuid\Handler;

use NullDev\PhpSpecSkeleton\SpecGenerator;
use NullDev\Skeleton\CodeGenerator\PhpParserGenerator;
use NullDev\Skeleton\Uuid\Command\CreateUuidSpecification;
use Symfony\Component\Filesystem\Filesystem;

/**
* @see CreateUuidSpecificationHandlerSpec
* @see CreateUuidSpecificationHandlerTest
*/
class CreateUuidSpecificationHandler
{
/** @var SpecGenerator */
private $specGenerator;
/** @var PhpParserGenerator */
private $codeGenerator;
/** @var Filesystem */
private $filesystem;

public function __construct(
SpecGenerator $specGenerator,
PhpParserGenerator $codeGenerator,
Filesystem $filesystem
) {
$this->specGenerator = $specGenerator;
$this->codeGenerator = $codeGenerator;
$this->filesystem = $filesystem;
}

public function handle(CreateUuidSpecification $command): void
{
$specificationSource = $this->specGenerator->generate($command->getClassSource());

$output = $this->codeGenerator->getOutput($specificationSource);

$this->filesystem->dumpFile($command->getFileName(), $output);
}
}

0 comments on commit d6f6092

Please sign in to comment.