Skip to content

Commit

Permalink
0.1.11 composer json generator
Browse files Browse the repository at this point in the history
  • Loading branch information
mmp4k committed Nov 4, 2017
1 parent 65c385e commit ba3403f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 5 deletions.
42 changes: 42 additions & 0 deletions spec/Pilsniak/ComposerGenerator/ComposerJsonGeneratorSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace spec\Pilsniak\ComposerGenerator;

use Pilsniak\ComposerGenerator\ComposerJsonGenerator;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ComposerJsonGeneratorSpec extends ObjectBehavior
{
function it_generates_json()
{
$this->generate()->fileContent()->shouldBe($this->jsonContent());
}

protected function jsonContent()
{
return "{
\"require\": {
\"prooph/service-bus\": \"^6.1\",
\"prooph/event-sourcing\": \"^5.2\",
\"prooph/event-store\": \"^7.2\",
\"prooph/pdo-event-store\": \"^1.5\",
\"prooph/event-store-bus-bridge\": \"^3.0\",
\"prooph/snapshotter\": \"^2.0\",
\"prooph/pdo-snapshot-store\": \"^1.3\",
\"ramsey/uuid\": \"^3.7\"
},
\"require-dev\": {
\"phpunit/phpunit\": \"^6.4\",
\"phpspec/phpspec\": \"^4.2\"
},
\"autoload\": {
\"psr-0\": {
\"\": \"src/\",
\"tests\": \"tests/\"
}
}
}
";
}
}
13 changes: 10 additions & 3 deletions spec/Pilsniak/ProophGen/ProophGeneratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace spec\Pilsniak\ProophGen;

use Pilsniak\ComposerGenerator\ComposerJsonGenerator;
use Pilsniak\ProophGen\FileParser;
use Pilsniak\ProophGen\FileSystem;
use Pilsniak\ProophGen\Model\AggregateRoot;
Expand All @@ -17,16 +18,18 @@ class ProophGeneratorSpec extends ObjectBehavior
{
function let(ProophGenerator\CommandGenerator $commandGenerator,
ProophGenerator\AggregateRootGenerator $aggregateRootGenerator,
ProophGenerator\ValueObjectGenerator $valueObjectGenerator)
ProophGenerator\ValueObjectGenerator $valueObjectGenerator,
ComposerJsonGenerator $composerJsonGenerator)
{
$this->beConstructedWith($commandGenerator, $valueObjectGenerator, $aggregateRootGenerator);
$this->beConstructedWith($commandGenerator, $valueObjectGenerator, $aggregateRootGenerator, $composerJsonGenerator);
}

function it_generates_files(FileParser $fileParser,
FileSystem $fileSystem,
ProophGenerator\CommandGenerator $commandGenerator,
ProophGenerator\AggregateRootGenerator $aggregateRootGenerator,
ProophGenerator\ValueObjectGenerator $valueObjectGenerator)
ProophGenerator\ValueObjectGenerator $valueObjectGenerator,
ComposerJsonGenerator $composerJsonGenerator)
{
$command = new Command('Model\Command\RegisterUser');
$event = new Event('UserRegistered');
Expand All @@ -53,9 +56,13 @@ function it_generates_files(FileParser $fileParser,
new FileToSave('./src/Model/CommandHandler/RegisterUserHandler.php', 'somecontent')
]);

$composerJsonGenerator->generate()->shouldBeCalled();
$composerJsonGenerator->generate()->willReturn(new FileToSave('composer.json', 'json'));

$fileSystem->save('./src/Model/ValueObject/Mail.php', 'somecontent')->shouldBeCalled();
$fileSystem->save('./src/Model/Command/RegisterUser.php', 'somecontent')->shouldBeCalled();
$fileSystem->save('./src/Model/CommandHandler/RegisterUserHandler.php', 'somecontent')->shouldBeCalled();
$fileSystem->save('composer.json', 'json')->shouldBeCalled();

$this->generate($fileParser, $fileSystem);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Pilsniak/Command/DoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use gossi\codegen\generator\CodeFileGenerator;
use League\Flysystem\Adapter\Local;
use Pilsniak\ComposerGenerator\ComposerJsonGenerator;
use Pilsniak\FlySystem\FileSystem;
use Pilsniak\GossiCodeGenerator\AggregateRootGenerator\AggregateRootCodeGenerator;
use Pilsniak\GossiCodeGenerator\AggregateRootGenerator\AggregateRootEventGenerator;
Expand Down Expand Up @@ -85,7 +86,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
)
);

$proophGenerator = new ProophGenerator($commandGenerator, $valueObjectGenerator, $rootGenerator);
$composerGenerator = new ComposerJsonGenerator();

$proophGenerator = new ProophGenerator($commandGenerator, $valueObjectGenerator, $rootGenerator, $composerGenerator);
$proophGenerator->generate($loader, new FileSystem(new \League\Flysystem\Filesystem(new Local('./'))));

}
Expand Down
40 changes: 40 additions & 0 deletions src/Pilsniak/ComposerGenerator/ComposerJsonGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Pilsniak\ComposerGenerator;

use Pilsniak\ProophGen\Model\FileToSave;

class ComposerJsonGenerator
{
public function generate(): FileToSave
{
return new FileToSave('composer.json', $this->content());
}

protected function content(): string
{
return "{
\"require\": {
\"prooph/service-bus\": \"^6.1\",
\"prooph/event-sourcing\": \"^5.2\",
\"prooph/event-store\": \"^7.2\",
\"prooph/pdo-event-store\": \"^1.5\",
\"prooph/event-store-bus-bridge\": \"^3.0\",
\"prooph/snapshotter\": \"^2.0\",
\"prooph/pdo-snapshot-store\": \"^1.3\",
\"ramsey/uuid\": \"^3.7\"
},
\"require-dev\": {
\"phpunit/phpunit\": \"^6.4\",
\"phpspec/phpspec\": \"^4.2\"
},
\"autoload\": {
\"psr-0\": {
\"\": \"src/\",
\"tests\": \"tests/\"
}
}
}
";
}
}
10 changes: 9 additions & 1 deletion src/Pilsniak/ProophGen/ProophGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Pilsniak\ProophGen;

use Pilsniak\ComposerGenerator\ComposerJsonGenerator;
use Pilsniak\ProophGen\Model\FileToSave;
use Pilsniak\ProophGen\ProophGenerator\AggregateRootGenerator;
use Pilsniak\ProophGen\ProophGenerator\CommandGenerator;
Expand All @@ -21,12 +22,17 @@ class ProophGenerator
* @var AggregateRootGenerator
*/
private $aggregateRootGenerator;
/**
* @var ComposerJsonGenerator
*/
private $composerJsonGenerator;

public function __construct(CommandGenerator $commandGenerator, ValueObjectGenerator $valueObjectGenerator, AggregateRootGenerator $aggregateRootGenerator)
public function __construct(CommandGenerator $commandGenerator, ValueObjectGenerator $valueObjectGenerator, AggregateRootGenerator $aggregateRootGenerator, ComposerJsonGenerator $composerJsonGenerator)
{
$this->commandGenerator = $commandGenerator;
$this->valueObjectGenerator = $valueObjectGenerator;
$this->aggregateRootGenerator = $aggregateRootGenerator;
$this->composerJsonGenerator = $composerJsonGenerator;
}

public function generate(FileParser $fileParser, FileSystem $fileSystem)
Expand All @@ -45,6 +51,8 @@ public function generate(FileParser $fileParser, FileSystem $fileSystem)
$toSave = array_merge($toSave, $this->aggregateRootGenerator->generate($aggregateRoot));
}

$toSave[] = $this->composerJsonGenerator->generate();

foreach ($toSave as $fileToSave) {
$fileSystem->save($fileToSave->filename(), $fileToSave->fileContent());
}
Expand Down

0 comments on commit ba3403f

Please sign in to comment.