-
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
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
spec/NullDev/Skeleton/SourceFactory/UuidIdentitySourceFactorySpec.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 spec\NullDev\Skeleton\SourceFactory; | ||
|
||
use NullDev\Skeleton\Definition\PHP\Methods\ConstructorMethod; | ||
use NullDev\Skeleton\Definition\PHP\Methods\ToStringMethod; | ||
use NullDev\Skeleton\Definition\PHP\Methods\UuidCreateMethod; | ||
use NullDev\Skeleton\Definition\PHP\Types\ClassType; | ||
use NullDev\Skeleton\Source\ClassSourceFactory; | ||
use NullDev\Skeleton\Source\ImprovedClassSource; | ||
use NullDev\Skeleton\SourceFactory\UuidIdentitySourceFactory; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class UuidIdentitySourceFactorySpec extends ObjectBehavior | ||
{ | ||
public function let(ClassSourceFactory $sourceFactory) | ||
{ | ||
$this->beConstructedWith($sourceFactory); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(UuidIdentitySourceFactory::class); | ||
} | ||
|
||
public function it_will_create_source_from_given_class_type( | ||
ClassSourceFactory $sourceFactory, | ||
ClassType $classType, | ||
ImprovedClassSource $classSource | ||
) { | ||
$sourceFactory->create($classType)->willReturn($classSource); | ||
|
||
$classSource->addConstructorMethod(Argument::type(ConstructorMethod::class)); | ||
$classSource->addMethod(Argument::type(ToStringMethod::class)); | ||
$classSource->addMethod(Argument::type(UuidCreateMethod::class)); | ||
$classSource->addImport(Argument::type(ClassType::class)); | ||
|
||
$this->create($classType)->shouldReturn($classSource); | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NullDev\Skeleton\SourceFactory; | ||
|
||
interface SourceFactory | ||
{ | ||
} |
42 changes: 42 additions & 0 deletions
42
src/NullDev/Skeleton/SourceFactory/UuidIdentitySourceFactory.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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NullDev\Skeleton\SourceFactory; | ||
|
||
use NullDev\Skeleton\Definition\PHP\Methods\ConstructorMethod; | ||
use NullDev\Skeleton\Definition\PHP\Methods\ToStringMethod; | ||
use NullDev\Skeleton\Definition\PHP\Methods\UuidCreateMethod; | ||
use NullDev\Skeleton\Definition\PHP\Parameter; | ||
use NullDev\Skeleton\Definition\PHP\Types\ClassType; | ||
use NullDev\Skeleton\Definition\PHP\Types\TypeDeclaration\StringType; | ||
use NullDev\Skeleton\Source\ClassSourceFactory; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
class UuidIdentitySourceFactory implements SourceFactory | ||
{ | ||
/** @var ClassSourceFactory */ | ||
private $sourceFactory; | ||
|
||
public function __construct(ClassSourceFactory $sourceFactory) | ||
{ | ||
$this->sourceFactory = $sourceFactory; | ||
} | ||
|
||
public function create(ClassType $classType) | ||
{ | ||
$source = $this->sourceFactory->create($classType); | ||
$param = new Parameter('id', new StringType()); | ||
|
||
//Add constructor method. | ||
$source->addConstructorMethod(new ConstructorMethod([$param])); | ||
//Add __toString() method. | ||
$source->addMethod(new ToStringMethod($param)); | ||
//Add static create() method. | ||
$source->addMethod(new UuidCreateMethod($classType)); | ||
//Add Ramsey\Uuid\Uuid to imports. | ||
$source->addImport(ClassType::createFromFullyQualified(Uuid::class)); | ||
|
||
return $source; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/NullDev/Skeleton/SourceFactory/UuidIdentitySourceFactoryTest.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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace tests\NullDev\Skeleton\SourceFactory; | ||
|
||
use NullDev\Skeleton\Source\ClassSourceFactory; | ||
use NullDev\Skeleton\SourceFactory\UuidIdentitySourceFactory; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
/** | ||
* @covers \NullDev\Skeleton\SourceFactory\UuidIdentitySourceFactory | ||
* @group nemesis | ||
*/ | ||
class UuidIdentitySourceFactoryTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** @var UuidIdentitySourceFactory */ | ||
private $uuidIdentitySourceFactory; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->uuidIdentitySourceFactory = new UuidIdentitySourceFactory(new ClassSourceFactory()); | ||
} | ||
|
||
public function testNothing(): void | ||
{ | ||
$this->markTestIncomplete('Auto generated using nemesis'); | ||
} | ||
} |