Skip to content

Commit

Permalink
Merge pull request #9 from Pierstoval/update-registry
Browse files Browse the repository at this point in the history
Many updates for next version
  • Loading branch information
Pierstoval committed Jan 25, 2019
2 parents d1711a8 + b7b1f35 commit bf9da96
Show file tree
Hide file tree
Showing 24 changed files with 202 additions and 141 deletions.
21 changes: 4 additions & 17 deletions .travis.yml
Expand Up @@ -7,37 +7,24 @@ cache:
- $HOME/.composer/cache
- $HOME/.app/cache

php: 7.1

env:
global:
- COMPOSER_FLAGS=""
- SYMFONY_VERSION=""
- ENABLE_CODE_COVERAGE="false"
php: 7.2

matrix:
fast_finish: true
include:
- env: 'COMPOSER_FLAGS="--prefer-lowest"'
- env: 'SYMFONY_VERSION="3.4.*"'
- env: 'SYMFONY_VERSION="4.0.*"'
- env: 'SYMFONY_VERSION="^4.1@dev"'
- env: 'ENABLE_CODE_COVERAGE="false"'
- env: 'ENABLE_CODE_COVERAGE="true"'

before_install:
- 'if [[ "$SYMFONY_VERSION" != "" ]]; then sed -r -e "s/(symfony\/[^:]+: \").+(\",?)$/\1$SYMFONY_VERSION\2/" -i composer.json; fi;'
- 'if [[ "$ENABLE_CODE_COVERAGE" != "true" ]]; then phpenv config-rm xdebug.ini; fi;'
- 'if [[ "$ENABLE_CODE_COVERAGE" == "true" ]]; then wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar; fi;'
- 'cat phpunit.xml.dist | sed -e "s/\(<!--\)\|\(-->\)//g" > phpunit.xml'

install:
- composer update --prefer-dist --no-interaction --optimize-autoloader $COMPOSER_FLAGS
- composer update --prefer-dist --no-interaction --optimize-autoloader

script:
- if [[ "$ENABLE_CODE_COVERAGE" == "true" ]]; then vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml; else phpunit; fi;
- if [[ "$ENABLE_CODE_COVERAGE" == "true" ]]; then vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml; else vendor/bin/phpunit; fi;

after_success: |
if [[ "$ENABLE_CODE_COVERAGE" == "true" ]]; then php php-coveralls.phar -v --config .coveralls.yml; fi;
notifications:
email: pierstoval@gmail.com
2 changes: 1 addition & 1 deletion Action/AbstractStepAction.php
Expand Up @@ -20,7 +20,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

abstract class AbstractStepAction implements StepActionInterface
{
Expand Down
2 changes: 1 addition & 1 deletion Controller/GeneratorController.php
Expand Up @@ -21,7 +21,7 @@
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class GeneratorController
{
Expand Down
3 changes: 1 addition & 2 deletions DependencyInjection/Compiler/StepsPass.php
Expand Up @@ -26,7 +26,7 @@
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

/**
Expand Down Expand Up @@ -162,7 +162,6 @@ private function processStepAction(string $managerName, array $config, Definitio
// In this case, we create a new service.
$definition = new Definition($action);
$definition
->setLazy(true)
->setPrivate(true)
->setAutowired(true)
;
Expand Down
8 changes: 4 additions & 4 deletions DependencyInjection/Configuration.php
Expand Up @@ -35,12 +35,12 @@ public function getConfigTreeBuilder()
->arrayNode('managers')
->useAttributeAsKey('name')
->normalizeKeys(true)
->prototype('array')
->arrayPrototype()
->children()
->scalarNode('character_class')->isRequired()->end()
->arrayNode('steps')
->useAttributeAsKey('name')
->prototype('array')
->arrayPrototype()
->children()
->scalarNode('action')
->info('Can be a class or a service. Must implement StepActionInterface or extend abstract Action class.')
Expand All @@ -50,12 +50,12 @@ public function getConfigTreeBuilder()
->arrayNode('dependencies')
->info('Steps that the current step may depend on. If step is not set in session, will throw an exception.')
->defaultValue([])
->prototype('scalar')->end()
->scalarPrototype()->end()
->end()
->arrayNode('onchange_clear')
->info("When this step will be updated, it will clear values for specified steps.\nOnly available for the abstract class")
->defaultValue([])
->prototype('scalar')->end()
->scalarPrototype()->end()
->end()
->end()
->end()
Expand Down
18 changes: 5 additions & 13 deletions Entity/Character.php
Expand Up @@ -30,27 +30,19 @@ abstract class Character implements CharacterInterface
*/
protected $nameSlug;

public function getName(): string
public function __construct(string $name, string $nameSlug)
{
return $this->name ?: '';
$this->name = $name;
$this->nameSlug = $nameSlug;
}

public function setName(string $name): self
public function getName(): string
{
$this->name = $name;

return $this;
return $this->name ?: '';
}

public function getNameSlug(): string
{
return $this->nameSlug ?: '';
}

public function setNameSlug(string $nameSlug): self
{
$this->nameSlug = $nameSlug;

return $this;
}
}
24 changes: 15 additions & 9 deletions Registry/ActionsRegistry.php
Expand Up @@ -25,22 +25,28 @@ public function addStepAction(string $manager, StepActionInterface $action): voi
$this->actions[$manager][$action->getStep()->getName()] = $action;
}

/**
* @return StepActionInterface[]
*/
public function getActions(): array
{
return $this->actions;
}

public function getAction(string $stepName, string $manager = null): StepActionInterface
{
if (!$this->actions) {
throw new \RuntimeException('No actions in the registry.');
}

if ($manager === null) {
$manager = array_keys($this->actions)[0];
}

if (!isset($this->actions[$manager])) {
throw new \InvalidArgumentException(\sprintf(
'Manager "%s" does not exist.',
$manager
));
}

if (!isset($this->actions[$manager][$stepName])) {
throw new \InvalidArgumentException('Step "'.$stepName.'" not found in registry.');
throw new \InvalidArgumentException(\sprintf(
'Step "%s" not found in manager "%s".',
$stepName, $manager
));
}

return $this->actions[$manager][$stepName];
Expand Down
6 changes: 4 additions & 2 deletions Registry/ActionsRegistryInterface.php
Expand Up @@ -16,7 +16,9 @@
interface ActionsRegistryInterface
{
/**
* @throws \RuntimeException for an action that do not exist.
* @throws \RuntimeException if there are no managers available.
* @throws \InvalidArgumentException for an action that do not exist.
* @throws \InvalidArgumentException for a manager that do not exist.
*/
public function getAction(string $stepName): StepActionInterface;
public function getAction(string $stepName, string $manager = null): StepActionInterface;
}
8 changes: 4 additions & 4 deletions Resources/config/routing.xml
Expand Up @@ -5,23 +5,23 @@
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="pierstoval_character_generator_index" path="/generate">
<default key="_controller">Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController:indexAction</default>
<default key="_controller">Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController::indexAction</default>
<default key="manager" xsi:nil="true" />
</route>

<route id="pierstoval_character_generator_step" path="/generate/{requestStep}">
<default key="_controller">Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController:stepAction</default>
<default key="_controller">Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController::stepAction</default>
<default key="manager" xsi:nil="true" />
<requirement key="requestStep">[\w-]+</requirement>
</route>

<route id="pierstoval_character_generator_reset" path="/reset/">
<default key="_controller">Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController:resetCharacterAction</default>
<default key="_controller">Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController::resetCharacterAction</default>
<default key="manager" xsi:nil="true" />
</route>

<route id="pierstoval_character_generator_reset_step" path="/reset/{requestStep}">
<default key="_controller">Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController:resetStepAction</default>
<default key="_controller">Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController::resetStepAction</default>
<default key="manager" xsi:nil="true" />
<requirement key="requestStep">[\w-]+</requirement>
</route>
Expand Down
9 changes: 7 additions & 2 deletions Resources/config/services.xml
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<defaults autoconfigure="true" public="false" autowire="true" />
<defaults public="false" />

<service id="Pierstoval\Bundle\CharacterManagerBundle\Registry\ActionsRegistry" />
<service id="Pierstoval\Bundle\CharacterManagerBundle\Registry\ActionsRegistryInterface" alias="Pierstoval\Bundle\CharacterManagerBundle\Registry\ActionsRegistry" />
Expand All @@ -15,6 +15,11 @@
</service>
<service id="Pierstoval\Bundle\CharacterManagerBundle\Resolver\StepResolverInterface" alias="Pierstoval\Bundle\CharacterManagerBundle\Resolver\StepResolver" />

<service id="Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController" public="true" />
<service id="Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController" public="true">
<argument type="service" id="Pierstoval\Bundle\CharacterManagerBundle\Resolver\StepResolverInterface" />
<argument type="service" id="Pierstoval\Bundle\CharacterManagerBundle\Registry\ActionsRegistryInterface" />
<argument type="service" id="Symfony\Component\Routing\RouterInterface" />
<argument type="service" id="Symfony\Contracts\Translation\TranslatorInterface" />
</service>
</services>
</container>
18 changes: 18 additions & 0 deletions Resources/translations/PierstovalCharacterManager.en.xlf
@@ -0,0 +1,18 @@
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="PierstovalCharacterManager.en.xlf">
<body>
<trans-unit id="steps.dependency_not_set">
<source>steps.dependency_not_set</source>
<target>The step "%current_step%" depends on "%dependency%" but it has not been initialized for current character being created...</target>
</trans-unit>
<trans-unit id="steps.reset.character">
<source>steps.reset.character</source>
<target>Character being created has been successfully reset!</target>
</trans-unit>
<trans-unit id="steps.reset.step">
<source>steps.reset.step</source>
<target>Current step has been successfully reset!</target>
</trans-unit>
</body>
</file>
</xliff>
25 changes: 0 additions & 25 deletions SheetsManagers/SheetGeneratorInterface.php

This file was deleted.

4 changes: 2 additions & 2 deletions Tests/Action/AbstractActionTest.php
Expand Up @@ -12,7 +12,7 @@
namespace Pierstoval\Bundle\CharacterManagerBundle\Tests\Action;

use InvalidArgumentException;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use Pierstoval\Bundle\CharacterManagerBundle\Model\Step;
use Pierstoval\Bundle\CharacterManagerBundle\Resolver\StepResolver;
use Pierstoval\Bundle\CharacterManagerBundle\Resolver\StepResolverInterface;
Expand All @@ -24,7 +24,7 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class AbstractActionTest extends AbstractGeneratorControllerTest
{
Expand Down
4 changes: 2 additions & 2 deletions Tests/Controller/AbstractGeneratorControllerTest.php
Expand Up @@ -11,7 +11,7 @@

namespace Pierstoval\Bundle\CharacterManagerBundle\Tests\Controller;

use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController;
use Pierstoval\Bundle\CharacterManagerBundle\Registry\ActionsRegistryInterface;
Expand All @@ -20,7 +20,7 @@
use Pierstoval\Bundle\CharacterManagerBundle\Tests\Fixtures\Stubs\Entity\CharacterStub;
use Pierstoval\Bundle\CharacterManagerBundle\Tests\RequestTestTrait;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

abstract class AbstractGeneratorControllerTest extends TestCase
{
Expand Down
Expand Up @@ -18,7 +18,7 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class ResetCharacterActionTest extends AbstractGeneratorControllerTest
{
Expand Down
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class ResetStepActionTest extends AbstractGeneratorControllerTest
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Controller/GeneratorController/StepActionTest.php
Expand Up @@ -20,7 +20,7 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class StepActionTest extends AbstractGeneratorControllerTest
{
Expand Down
3 changes: 1 addition & 2 deletions Tests/DependencyInjection/StepsPassTest.php
Expand Up @@ -16,7 +16,7 @@
use Pierstoval\Bundle\CharacterManagerBundle\Tests\Fixtures\Stubs\Action\ConcreteAbstractActionStub;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Yaml\Yaml;
use Twig\Environment;

Expand Down Expand Up @@ -154,7 +154,6 @@ public function test simple classes are automatically registered as servi
// These should be set by default on every action class not already registered as service
static::assertTrue($definition->isPrivate());
static::assertTrue($definition->isAutowired());
static::assertTrue($definition->isLazy());
static::assertSame(ConcreteAbstractActionStub::class, $definition->getClass());
}

Expand Down
5 changes: 5 additions & 0 deletions Tests/Fixtures/Stubs/Entity/CharacterStub.php
Expand Up @@ -28,6 +28,11 @@ class CharacterStub extends BaseCharacter
*/
protected $id;

public function __construct()
{
parent::__construct('Stub characte', 'stub-character');
}

/**
* @return int
*/
Expand Down

0 comments on commit bf9da96

Please sign in to comment.