Skip to content

Commit

Permalink
sf
Browse files Browse the repository at this point in the history
  • Loading branch information
msvrtan committed Jul 28, 2017
1 parent 5e2130b commit 7c84d69
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
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);
}
}
9 changes: 9 additions & 0 deletions src/NullDev/Skeleton/SourceFactory/SourceFactory.php
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 src/NullDev/Skeleton/SourceFactory/UuidIdentitySourceFactory.php
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;
}
}
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');
}
}

0 comments on commit 7c84d69

Please sign in to comment.