diff --git a/argumentsExt/Annotation/StepInjectorArgument.php b/argumentsExt/Annotation/StepInjectorArgument.php new file mode 100644 index 0000000..7f67503 --- /dev/null +++ b/argumentsExt/Annotation/StepInjectorArgument.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gorghoa\StepArgumentInjectorBehatExtension\Annotation; + +/** + * @author Vincent Chalamon + * + */ +interface StepInjectorArgument +{ + /** + * @return string + */ + public function getName(); + + /** + * @return string + */ + public function getArgument(); +} diff --git a/src/Argument/ScenarioStateArgumentOrganiser.php b/argumentsExt/Argument/ArgumentOrganiser.php similarity index 51% rename from src/Argument/ScenarioStateArgumentOrganiser.php rename to argumentsExt/Argument/ArgumentOrganiser.php index 172652a..f55c681 100644 --- a/src/Argument/ScenarioStateArgumentOrganiser.php +++ b/argumentsExt/Argument/ArgumentOrganiser.php @@ -1,7 +1,7 @@ * @@ -9,39 +9,40 @@ * file that was distributed with this source code. */ -namespace Gorghoa\ScenarioStateBehatExtension\Argument; +namespace Gorghoa\StepArgumentInjectorBehatExtension\Argument; -use Behat\Testwork\Argument\ArgumentOrganiser; +use Behat\Testwork\Argument\ArgumentOrganiser as BehatArgumentOrganiser; use Doctrine\Common\Annotations\Reader; -use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument; -use Gorghoa\ScenarioStateBehatExtension\Context\Initializer\ScenarioStateInitializer; +use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepArgumentInjectorArgument; +use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument; +// use Gorghoa\StepArgumentInjectorBehatExtension\Context\Initializer\StepArgumentInjectorInitializer; use ReflectionFunctionAbstract; /** * @author Rodrigue Villetard * @author Vincent Chalamon */ -final class ScenarioStateArgumentOrganiser implements ArgumentOrganiser +final class ArgumentOrganiser implements BehatArgumentOrganiser { /** - * @var ArgumentOrganiser + * @var BehatArgumentOrganiser */ private $baseOrganiser; /** - * @var ScenarioStateInitializer + * @var StepArgumentInjectorInitializer */ - private $store; + private $hookers; /** * @var Reader */ private $reader; - public function __construct(ArgumentOrganiser $organiser, ScenarioStateInitializer $store, Reader $reader) + public function __construct(BehatArgumentOrganiser $organiser, array $hookers, Reader $reader) { $this->baseOrganiser = $organiser; - $this->store = $store; + $this->hookers = $hookers; $this->reader = $reader; } @@ -59,16 +60,21 @@ public function organiseArguments(ReflectionFunctionAbstract $function, array $m return $this->baseOrganiser->organiseArguments($function, $match); } - /** @var ScenarioStateArgument[] $annotations */ + /** @var StepArgumentInjectorArgument[] $annotations */ $annotations = $this->reader->getMethodAnnotations($function); - $store = $this->store->getStore(); + foreach ($annotations as $annotation) { - if ($annotation instanceof ScenarioStateArgument && - in_array($annotation->getArgument(), $paramsKeys) && - $store->hasStateFragment($annotation->getName()) + if ($annotation instanceof StepInjectorArgument && + in_array($annotation->getArgument(), $paramsKeys) ) { - $match[$annotation->getArgument()] = $store->getStateFragment($annotation->getName()); - $match[strval(++$i)] = $store->getStateFragment($annotation->getName()); + foreach ($this->hookers as $hooker) { + if ($hooker->hasStepArgumentFor($annotation->getName())) { + $match[$annotation->getArgument()] + = $match[strval(++$i)] + = $hooker->getStepArgumentFor($annotation->getName()) + ; + } + } } } diff --git a/argumentsExt/Argument/StepArgumentHolder.php b/argumentsExt/Argument/StepArgumentHolder.php new file mode 100644 index 0000000..d82282f --- /dev/null +++ b/argumentsExt/Argument/StepArgumentHolder.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gorghoa\StepArgumentInjectorBehatExtension\Argument; + + +/** + * @author Rodrigue Villetard + */ +interface StepArgumentHolder +{ + public function hasStepArgumentFor($key); + public function getStepArgumentFor($key); +} diff --git a/src/Call/Handler/RuntimeCallHandler.php b/argumentsExt/Call/Handler/RuntimeCallHandler.php similarity index 91% rename from src/Call/Handler/RuntimeCallHandler.php rename to argumentsExt/Call/Handler/RuntimeCallHandler.php index 9a8cb75..a60b3cf 100644 --- a/src/Call/Handler/RuntimeCallHandler.php +++ b/argumentsExt/Call/Handler/RuntimeCallHandler.php @@ -1,7 +1,7 @@ * @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Gorghoa\ScenarioStateBehatExtension\Call\Handler; +namespace Gorghoa\StepArgumentInjectorBehatExtension\Call\Handler; use Behat\Behat\Transformation\Call\TransformationCall; use Behat\Testwork\Call\Call; use Behat\Testwork\Call\Handler\CallHandler; use Behat\Testwork\Environment\Call\EnvironmentCall; use Behat\Testwork\Hook\Call\HookCall; -use Gorghoa\ScenarioStateBehatExtension\Resolver\ArgumentsResolver; +use Gorghoa\StepArgumentInjectorBehatExtension\Resolver\ArgumentsResolver; /** * @author Vincent Chalamon diff --git a/src/Resolver/ArgumentsResolver.php b/argumentsExt/Resolver/ArgumentsResolver.php similarity index 62% rename from src/Resolver/ArgumentsResolver.php rename to argumentsExt/Resolver/ArgumentsResolver.php index d25e4bd..83a908c 100644 --- a/src/Resolver/ArgumentsResolver.php +++ b/argumentsExt/Resolver/ArgumentsResolver.php @@ -1,7 +1,7 @@ * @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Gorghoa\ScenarioStateBehatExtension\Resolver; +namespace Gorghoa\StepArgumentInjectorBehatExtension\Resolver; use Doctrine\Common\Annotations\Reader; -use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument; -use Gorghoa\ScenarioStateBehatExtension\Context\Initializer\ScenarioStateInitializer; +use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument; +use Gorghoa\StepArgumentInjectorBehatExtension\Argument\StepArgumentHolder; /** * @author Vincent Chalamon @@ -21,22 +21,21 @@ class ArgumentsResolver { /** - * @var ScenarioStateInitializer + * @var Reader */ - private $store; + private $reader; /** - * @var Reader + * @var array */ - private $reader; + private $hookers; /** - * @param ScenarioStateInitializer $store * @param Reader $reader */ - public function __construct(ScenarioStateInitializer $store, Reader $reader) + public function __construct(array $hookers, Reader $reader) { - $this->store = $store; + $this->hookers = $hookers; $this->reader = $reader; } @@ -48,25 +47,28 @@ public function __construct(ScenarioStateInitializer $store, Reader $reader) */ public function resolve(\ReflectionMethod $function, array $arguments) { - // No `@ScenarioStateArgument` annotation found - if (null === $this->reader->getMethodAnnotation($function, ScenarioStateArgument::class)) { + // No `@StepArgumentInjectorArgument` annotation found + if (null === $this->reader->getMethodAnnotation($function, StepInjectorArgument::class)) { return $arguments; } $paramsKeys = array_map(function (\ReflectionParameter $element) { return $element->getName(); }, $function->getParameters()); - $store = $this->store->getStore(); + // Prepare arguments from annotations - /** @var ScenarioStateArgument[] $annotations */ + /** @var StepArgumentInjectorArgument[] $annotations */ $annotations = $this->reader->getMethodAnnotations($function); foreach ($annotations as $annotation) { - if ($annotation instanceof ScenarioStateArgument && - in_array($annotation->getArgument(), $paramsKeys) && - $store->hasStateFragment($annotation->getName()) + if ($annotation instanceof StepInjectorArgument && + in_array($annotation->getArgument(), $paramsKeys) ) { - $arguments[$annotation->getArgument()] = $store->getStateFragment($annotation->getName()); + foreach ($this->hookers as $hooker) { + if ($hooker->hasStepArgumentFor($annotation->getName())) { + $arguments[$annotation->getArgument()] = $hooker->getStepArgumentFor($annotation->getName()); + } + } } } diff --git a/argumentsExt/ServiceContainer/StepArgumentInjectorExtension.php b/argumentsExt/ServiceContainer/StepArgumentInjectorExtension.php new file mode 100644 index 0000000..7ffd66f --- /dev/null +++ b/argumentsExt/ServiceContainer/StepArgumentInjectorExtension.php @@ -0,0 +1,133 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gorghoa\StepArgumentInjectorBehatExtension\ServiceContainer; + +use Behat\Behat\Context\ServiceContainer\ContextExtension; +use Behat\Behat\Tester\ServiceContainer\TesterExtension; +use Behat\Testwork\Argument\ServiceContainer\ArgumentExtension; +use Behat\Testwork\Call\ServiceContainer\CallExtension; +use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; +use Behat\Testwork\Hook\ServiceContainer\HookExtension; +use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; +use Behat\Testwork\ServiceContainer\ExtensionManager; +use Doctrine\Common\Annotations\AnnotationReader; +use Gorghoa\ScenarioStateBehatExtension\ServiceContainer\ScenarioStateExtension; +use Gorghoa\StepArgumentInjectorBehatExtension\Argument\ArgumentOrganiser; +use Gorghoa\StepArgumentInjectorBehatExtension\Argument\StepArgumentInjectorArgumentOrganiser; +use Gorghoa\StepArgumentInjectorBehatExtension\Call\Handler\RuntimeCallHandler; +use Gorghoa\StepArgumentInjectorBehatExtension\Hook\Dispatcher\StepArgumentInjectorHookDispatcher; +use Gorghoa\StepArgumentInjectorBehatExtension\Hook\Tester\StepArgumentInjectorHookableScenarioTester; +use Gorghoa\StepArgumentInjectorBehatExtension\Resolver\ArgumentsResolver; +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; + +/** + * Behat store for Behat contexts. + * + * @author Rodrigue Villetard + * @author Vincent Chalamon + */ +class StepArgumentInjectorExtension implements ExtensionInterface +{ + const STEP_ARGUMENT_INJECTOR_ARGUMENT_ORGANISER_ID = 'argument.step_argument_injector.organiser'; + const STEP_ARGUMENT_INJECTOR_DISPATCHER_ID = 'hook.step_argument_injector.dispatcher'; + const STEP_ARGUMENT_INJECTOR_TESTER_ID = 'tester.step_argument_injector.wrapper'; + const STEP_ARGUMENT_INJECTOR_CALL_HANDLER_ID = 'call.step_argument_injector.call_handler'; + const STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID = 'step_argument_injector.arguments_resolver'; + const STEP_ARGUMENT_INJECTOR_STORE_ID = 'behatstore.context_initializer.store_aware'; + const STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID = 'doctrine.reader.annotation'; + const STEP_ARGUMENT_INJECTOR_HOOK_TAG_ID = 'step_argument_injector.hook_tag_id'; + + /** + * {@inheritdoc} + */ + public function getConfigKey() + { + return 'stepargumentinjector'; + } + + /** + * {@inheritdoc} + */ + public function initialize(ExtensionManager $extensionManager) + { + } + + /** + * {@inheritdoc} + */ + public function configure(ArrayNodeDefinition $builder) + { + } + + /** + * {@inheritdoc} + */ + public function load(ContainerBuilder $container, array $config) + { + // Declare Doctrine annotation reader as service + $container->register(self::STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID, AnnotationReader::class) + // Ignore Behat annotations in reader + ->addMethodCall('addGlobalIgnoredName', ['Given']) + ->addMethodCall('addGlobalIgnoredName', ['When']) + ->addMethodCall('addGlobalIgnoredName', ['Then']) + ->addMethodCall('addGlobalIgnoredName', ['Transform']) + ->addMethodCall('addGlobalIgnoredName', ['BeforeStep']) + ->addMethodCall('addGlobalIgnoredName', ['BeforeScenario']) + ->addMethodCall('addGlobalIgnoredName', ['BeforeFeature']) + ->addMethodCall('addGlobalIgnoredName', ['BeforeSuite']) + ->addMethodCall('addGlobalIgnoredName', ['AfterStep']) + ->addMethodCall('addGlobalIgnoredName', ['AfterScenario']) + ->addMethodCall('addGlobalIgnoredName', ['AfterFeature']) + ->addMethodCall('addGlobalIgnoredName', ['AfterSuite']); + + + $taggedServices = array_map(function ($serviceId) { + return new Reference($serviceId); + }, array_keys($container->findTaggedServiceIds(self::STEP_ARGUMENT_INJECTOR_HOOK_TAG_ID))); + + // Arguments resolver: resolve StepArgumentInjector arguments from annotation + $container->register(self::STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID, ArgumentsResolver::class) + ->setArguments([ + $taggedServices, + new Reference(self::STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID), + ]); + + + // Argument organiser + $container->register(self::STEP_ARGUMENT_INJECTOR_ARGUMENT_ORGANISER_ID, ArgumentOrganiser::class) + ->setDecoratedService(ArgumentExtension::PREG_MATCH_ARGUMENT_ORGANISER_ID) + ->setPublic(false) + ->setArguments([ + new Reference(sprintf('%s.inner', self::STEP_ARGUMENT_INJECTOR_ARGUMENT_ORGANISER_ID)), + $taggedServices, + new Reference(self::STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID), + new Reference(self::STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID), + ]); + + // Override calls process + $container->register(self::STEP_ARGUMENT_INJECTOR_CALL_HANDLER_ID, RuntimeCallHandler::class) + ->setDecoratedService(CallExtension::CALL_HANDLER_TAG.'.runtime') + ->setArguments([ + new Reference(self::STEP_ARGUMENT_INJECTOR_CALL_HANDLER_ID.'.inner'), + new Reference(self::STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID), + ]); + } + + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + } +} diff --git a/composer.json b/composer.json index 6411bf0..cbaa576 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "gorghoa/scenariostate-behat-extension", "type": "behat-extension", - "version": "v1.0.3", + "version": "v1.0.4", "description": "Scenario shared state extension for Behat", "keywords": ["behat", "bdd", "stateless api testing"], "license": "MIT", @@ -27,6 +27,7 @@ "autoload": { "psr-4": { + "Gorghoa\\StepArgumentInjectorBehatExtension\\": "argumentsExt/", "Gorghoa\\ScenarioStateBehatExtension\\": "src/", "Symfony\\Component\\Process\\": "vendor/symfony/process/" } diff --git a/src/Annotation/ScenarioStateArgument.php b/src/Annotation/ScenarioStateArgument.php index b447264..a6f58cc 100644 --- a/src/Annotation/ScenarioStateArgument.php +++ b/src/Annotation/ScenarioStateArgument.php @@ -11,13 +11,15 @@ namespace Gorghoa\ScenarioStateBehatExtension\Annotation; +use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument; + /** * @author Vincent Chalamon * * @Annotation * @Target("METHOD") */ -class ScenarioStateArgument +class ScenarioStateArgument implements StepInjectorArgument { /** * Argument name in store. diff --git a/src/Context/Initializer/ScenarioStateInitializer.php b/src/Context/Initializer/ScenarioStateInitializer.php index 379a5d8..0996819 100644 --- a/src/Context/Initializer/ScenarioStateInitializer.php +++ b/src/Context/Initializer/ScenarioStateInitializer.php @@ -17,12 +17,13 @@ use Gorghoa\ScenarioStateBehatExtension\Context\ScenarioStateAwareContext; use Gorghoa\ScenarioStateBehatExtension\ScenarioState; use Gorghoa\ScenarioStateBehatExtension\ScenarioStateInterface; +use Gorghoa\StepArgumentInjectorBehatExtension\Argument\StepArgumentHolder; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * @author Rodrigue Villetard */ -class ScenarioStateInitializer implements ContextInitializer, EventSubscriberInterface +class ScenarioStateInitializer implements ContextInitializer, EventSubscriberInterface, StepArgumentHolder { /** * @var ScenarioStateInterface @@ -68,4 +69,14 @@ public function getStore() { return $this->store; } + + public function hasStepArgumentFor($key) + { + return $this->store->hasStateFragment($key); + } + + public function getStepArgumentFor($key) + { + return $this->store->getStateFragment($key); + } } diff --git a/src/ServiceContainer/ScenarioStateExtension.php b/src/ServiceContainer/ScenarioStateExtension.php index 7bd85fa..1030bed 100644 --- a/src/ServiceContainer/ScenarioStateExtension.php +++ b/src/ServiceContainer/ScenarioStateExtension.php @@ -21,12 +21,13 @@ use Behat\Testwork\ServiceContainer\ExtensionManager; use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationRegistry; -use Gorghoa\ScenarioStateBehatExtension\Argument\ScenarioStateArgumentOrganiser; +use Gorghoa\ScenarioStateBehatExtension\Argument\ArgumentOrganiser; use Gorghoa\ScenarioStateBehatExtension\Call\Handler\RuntimeCallHandler; use Gorghoa\ScenarioStateBehatExtension\Context\Initializer\ScenarioStateInitializer; use Gorghoa\ScenarioStateBehatExtension\Hook\Dispatcher\ScenarioStateHookDispatcher; use Gorghoa\ScenarioStateBehatExtension\Hook\Tester\ScenarioStateHookableScenarioTester; use Gorghoa\ScenarioStateBehatExtension\Resolver\ArgumentsResolver; +use Gorghoa\StepArgumentInjectorBehatExtension\ServiceContainer\StepArgumentInjectorExtension; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -39,13 +40,8 @@ */ class ScenarioStateExtension implements ExtensionInterface { - const SCENARIO_STATE_ARGUMENT_ORGANISER_ID = 'argument.scenario_state.organiser'; - const SCENARIO_STATE_DISPATCHER_ID = 'hook.scenario_state.dispatcher'; - const SCENARIO_STATE_TESTER_ID = 'tester.scenario_state.wrapper'; - const SCENARIO_STATE_CALL_HANDLER_ID = 'call.scenario_state.call_handler'; - const SCENARIO_STATE_ARGUMENTS_RESOLVER_ID = 'scenario_state.arguments_resolver'; const SCENARIO_STATE_STORE_ID = 'behatstore.context_initializer.store_aware'; - const SCENARIO_STATE_DOCTRINE_READER_ID = 'doctrine.reader.annotation'; + const SCENARIO_STATE_ARGUMENT_INJECTOR_STORE_ID = 'behatstore.context_initializer.store_aware'; /** * {@inheritdoc} @@ -78,49 +74,9 @@ public function load(ContainerBuilder $container, array $config) // Load ScenarioState store $container->register(self::SCENARIO_STATE_STORE_ID, ScenarioStateInitializer::class) ->addTag(ContextExtension::INITIALIZER_TAG, ['priority' => 0]) - ->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, ['priority' => 0]); - - // Declare Doctrine annotation reader as service - $container->register(self::SCENARIO_STATE_DOCTRINE_READER_ID, AnnotationReader::class) - // Ignore Behat annotations in reader - ->addMethodCall('addGlobalIgnoredName', ['Given']) - ->addMethodCall('addGlobalIgnoredName', ['When']) - ->addMethodCall('addGlobalIgnoredName', ['Then']) - ->addMethodCall('addGlobalIgnoredName', ['Transform']) - ->addMethodCall('addGlobalIgnoredName', ['BeforeStep']) - ->addMethodCall('addGlobalIgnoredName', ['BeforeScenario']) - ->addMethodCall('addGlobalIgnoredName', ['BeforeFeature']) - ->addMethodCall('addGlobalIgnoredName', ['BeforeSuite']) - ->addMethodCall('addGlobalIgnoredName', ['AfterStep']) - ->addMethodCall('addGlobalIgnoredName', ['AfterScenario']) - ->addMethodCall('addGlobalIgnoredName', ['AfterFeature']) - ->addMethodCall('addGlobalIgnoredName', ['AfterSuite']); - - // Arguments resolver: resolve ScenarioState arguments from annotation - $container->register(self::SCENARIO_STATE_ARGUMENTS_RESOLVER_ID, ArgumentsResolver::class) - ->setArguments([ - new Reference(self::SCENARIO_STATE_STORE_ID), - new Reference(self::SCENARIO_STATE_DOCTRINE_READER_ID), - ]); - - // Argument organiser - $container->register(self::SCENARIO_STATE_ARGUMENT_ORGANISER_ID, ScenarioStateArgumentOrganiser::class) - ->setDecoratedService(ArgumentExtension::PREG_MATCH_ARGUMENT_ORGANISER_ID) - ->setPublic(false) - ->setArguments([ - new Reference(sprintf('%s.inner', self::SCENARIO_STATE_ARGUMENT_ORGANISER_ID)), - new Reference(self::SCENARIO_STATE_STORE_ID), - new Reference(self::SCENARIO_STATE_DOCTRINE_READER_ID), - new Reference(self::SCENARIO_STATE_ARGUMENTS_RESOLVER_ID), - ]); - - // Override calls process - $container->register(self::SCENARIO_STATE_CALL_HANDLER_ID, RuntimeCallHandler::class) - ->setDecoratedService(CallExtension::CALL_HANDLER_TAG.'.runtime') - ->setArguments([ - new Reference(self::SCENARIO_STATE_CALL_HANDLER_ID.'.inner'), - new Reference(self::SCENARIO_STATE_ARGUMENTS_RESOLVER_ID), - ]); + ->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, ['priority' => 0]) + ->addTag(StepArgumentInjectorExtension::STEP_ARGUMENT_INJECTOR_HOOK_TAG_ID, ['priority' => 0]) + ; } /** diff --git a/testapp/behat.yml b/testapp/behat.yml index efdd3fc..9ca9379 100644 --- a/testapp/behat.yml +++ b/testapp/behat.yml @@ -1,3 +1,4 @@ default: extensions: Gorghoa\ScenarioStateBehatExtension\ServiceContainer\ScenarioStateExtension: ~ + Gorghoa\StepArgumentInjectorBehatExtension\ServiceContainer\StepArgumentInjectorExtension: ~ diff --git a/testsSAI/Annotation/ScenarioStateArgumentTest.php b/testsSAI/Annotation/ScenarioStateArgumentTest.php new file mode 100644 index 0000000..8ce684a --- /dev/null +++ b/testsSAI/Annotation/ScenarioStateArgumentTest.php @@ -0,0 +1,56 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gorghoa\ScenarioStateBehatExtension\Annotation; + +/** + * @author Vincent Chalamon + */ +class ScenarioStateArgumentTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getArguments + * + * @param array $arguments + * @param string $name + * @param string $argument + */ + public function testWithValue(array $arguments, $name, $argument) + { + $annotation = new ScenarioStateArgument($arguments); + $this->assertEquals($name, $annotation->name); + $this->assertEquals($argument, $annotation->argument); + } + + /** + * @return array + */ + public function getArguments() + { + return [ + [ + ['value' => 'foo'], + 'foo', + 'foo', + ], + [ + ['name' => 'foo'], + 'foo', + 'foo', + ], + [ + ['name' => 'foo', 'argument' => 'bar'], + 'foo', + 'bar', + ], + ]; + } +} diff --git a/tests/Argument/ScenarioStateArgumentOrganiserTest.php b/testsSAI/Argument/ScenarioStateArgumentOrganiserTest.php similarity index 95% rename from tests/Argument/ScenarioStateArgumentOrganiserTest.php rename to testsSAI/Argument/ScenarioStateArgumentOrganiserTest.php index a5a30e9..575a245 100644 --- a/tests/Argument/ScenarioStateArgumentOrganiserTest.php +++ b/testsSAI/Argument/ScenarioStateArgumentOrganiserTest.php @@ -21,10 +21,10 @@ /** * @author Vincent Chalamon */ -class ScenarioStateArgumentOrganiserTest extends \PHPUnit_Framework_TestCase +class ArgumentOrganiserTest extends \PHPUnit_Framework_TestCase { /** - * @var ScenarioStateArgumentOrganiser + * @var ArgumentOrganiser */ private $organiser; @@ -67,7 +67,7 @@ protected function setUp() $this->readerMock = $this->prophesize(Reader::class); $this->annotationMock = $this->prophesize(ScenarioStateArgument::class); - $this->organiser = new ScenarioStateArgumentOrganiser( + $this->organiser = new ArgumentOrganiser( $this->organiserMock->reveal(), $this->initializerMock->reveal(), $this->readerMock->reveal() diff --git a/tests/Resolver/ArgumentsResolverTest.php b/testsSAI/Resolver/ArgumentsResolverTest.php similarity index 100% rename from tests/Resolver/ArgumentsResolverTest.php rename to testsSAI/Resolver/ArgumentsResolverTest.php