-
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
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
spec/NullDev/Skeleton/Uuid/Handler/CreateUuidClassHandlerSpec.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,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\NullDev\Skeleton\Uuid\Handler; | ||
|
||
use NullDev\Skeleton\CodeGenerator\PhpParserGenerator; | ||
use NullDev\Skeleton\Definition\PHP\Types\ClassType; | ||
use NullDev\Skeleton\Source\ImprovedClassSource; | ||
use NullDev\Skeleton\SourceFactory\UuidIdentitySourceFactory; | ||
use NullDev\Skeleton\Uuid\Command\CreateUuidClass; | ||
use NullDev\Skeleton\Uuid\Handler\CreateUuidClassHandler; | ||
use PhpSpec\ObjectBehavior; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
class CreateUuidClassHandlerSpec extends ObjectBehavior | ||
{ | ||
public function let( | ||
UuidIdentitySourceFactory $sourceFactory, | ||
PhpParserGenerator $codeGenerator, | ||
Filesystem $filesystem | ||
) { | ||
$this->beConstructedWith($sourceFactory, $codeGenerator, $filesystem); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(CreateUuidClassHandler::class); | ||
} | ||
|
||
public function it_will_handle_creating_uuid_class( | ||
CreateUuidClass $command, | ||
ClassType $classType, | ||
UuidIdentitySourceFactory $sourceFactory, | ||
PhpParserGenerator $codeGenerator, | ||
Filesystem $filesystem, | ||
ImprovedClassSource $classSource | ||
) { | ||
$command->getClassType() | ||
->shouldBeCalled() | ||
->willReturn($classType); | ||
|
||
$command->getFileName() | ||
->shouldBeCalled() | ||
->willReturn('/path/filename.php'); | ||
|
||
$sourceFactory->create($classType) | ||
->shouldBeCalled() | ||
->willReturn($classSource); | ||
|
||
$codeGenerator->getOutput($classSource) | ||
->shouldBeCalled() | ||
->willReturn('output'); | ||
|
||
$filesystem->dumpFile('/path/filename.php', 'output') | ||
->shouldBeCalled(); | ||
|
||
$this->handle($command); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/NullDev/Skeleton/Uuid/Handler/CreateUuidClassHandler.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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NullDev\Skeleton\Uuid\Handler; | ||
|
||
use NullDev\Skeleton\CodeGenerator\PhpParserGenerator; | ||
use NullDev\Skeleton\SourceFactory\UuidIdentitySourceFactory; | ||
use NullDev\Skeleton\Uuid\Command\CreateUuidClass; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
/** | ||
* @see CreateUuidClassHandlerSpec | ||
* @see CreateUuidClassHandlerTest | ||
*/ | ||
class CreateUuidClassHandler | ||
{ | ||
/** @var UuidIdentitySourceFactory */ | ||
private $sourceFactory; | ||
/** @var PhpParserGenerator */ | ||
private $codeGenerator; | ||
/** @var Filesystem */ | ||
private $filesystem; | ||
|
||
public function __construct( | ||
UuidIdentitySourceFactory $sourceFactory, | ||
PhpParserGenerator $codeGenerator, | ||
Filesystem $filesystem | ||
) { | ||
$this->sourceFactory = $sourceFactory; | ||
$this->codeGenerator = $codeGenerator; | ||
$this->filesystem = $filesystem; | ||
} | ||
|
||
public function handle(CreateUuidClass $command): void | ||
{ | ||
$classSource = $this->sourceFactory->create($command->getClassType()); | ||
|
||
$output = $this->codeGenerator->getOutput($classSource); | ||
|
||
$this->filesystem->dumpFile($command->getFileName(), $output); | ||
} | ||
} |