Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions features/bootstrap/DemoAppContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
namespace Tests\Functional\BehatContext;

use Behat\Gherkin\Node\PyStringNode;
use DemoApp\AbstractKernel;
use DemoApp\DefaultKernel;
use DemoApp\KernelWithMappingCollectorListener;
use PHPUnit\Framework\Assert;
use Symfony\Component\HttpFoundation\Response;
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface;
Expand All @@ -13,6 +16,16 @@ class DemoAppContext extends AbstractContext
{
/** @var Response|null */
private $lastResponse;
/** @var bool */
private $useKernelWithMappingCollectorListener = false;

/**
* @Given I will use kernel with MappingCollector listener
*/
public function givenIWillUseServerDocCreatedListener()
{
$this->useKernelWithMappingCollectorListener = true;
}

/**
* @When I send following :httpMethod input on :uri demoApp kernel endpoint:
Expand Down Expand Up @@ -69,4 +82,20 @@ public function thenCollectorShouldHaveAMethodWithName($methodClass, $methodName
sprintf('Method "%s" is not an instance of "%s"', $methodName, $methodClass)
);
}
/**
* @return AbstractKernel
*/
public function getDemoAppKernel()
{
$env = 'prod';
$debug = true;

if (true === $this->useKernelWithMappingCollectorListener) {
$kernelClass = KernelWithMappingCollectorListener::class;
} else {
$kernelClass = DefaultKernel::class;
}

return new $kernelClass($env, $debug);
}
}
6 changes: 0 additions & 6 deletions features/demo_app/default_config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,3 @@ services:
class: DemoApp\Method\MethodD
tags:
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledGetAnotherDummy' }

## Mapping aware service
mapping_aware_service:
public: true # In order to allow Behat context to load it later
class: DemoApp\Collector\MappingCollector
tags: ['json_rpc_http_server.method_aware']
5 changes: 5 additions & 0 deletions features/demo_app/mapping_collector_config/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Yoanm\SymfonyJsonRpcHttpServer\JsonRpcHttpServerBundle::class => ['all' => true],
];
5 changes: 5 additions & 0 deletions features/demo_app/mapping_collector_config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
framework:
secret: '%env(APP_SECRET)%'

json_rpc_http_server:
endpoint: '/my-custom-endpoint'
3 changes: 3 additions & 0 deletions features/demo_app/mapping_collector_config/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Import default configuration or write your own
json-rpc-endpoint:
resource: '@JsonRpcHttpServerBundle/Resources/config/routing/endpoint.xml'
25 changes: 25 additions & 0 deletions features/demo_app/mapping_collector_config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Configure JSON-RPC method services.
services:
jsonrpc.method.a:
class: DemoApp\Method\MethodA
tags:
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledMethodA' }
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledMethodAAlias' }
jsonrpc.method.b:
class: DemoApp\Method\MethodB
tags:
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledMethodB' }
jsonrpc.method.c:
class: DemoApp\Method\MethodC
tags:
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledGetDummy' }
jsonrpc.method.d:
class: DemoApp\Method\MethodD
tags:
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledGetAnotherDummy' }

## Mapping aware service
mapping_aware_service:
public: true # In order to allow Behat context to load it later
class: DemoApp\Collector\MappingCollector
tags: ['json_rpc_http_server.method_aware']
48 changes: 48 additions & 0 deletions features/demo_app/src/KernelWithMappingCollectorListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
namespace DemoApp;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Routing\RouteCollectionBuilder;

class KernelWithMappingCollectorListener extends AbstractKernel
{
public function registerBundles(): iterable
{
/** @noinspection PhpIncludeInspection */
$contents = require $this->getProjectDir().'/'.$this->getConfigDirectory().'/bundles.php';
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
}
}

/**
* {@inheritdoc}
*/
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
{
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
$loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
}

/**
* {@inheritdoc}
*/
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
}

/**
* {@inheritdoc}
*/
public function getConfigDirectory() : string
{
return 'mapping_collector_config';
}
}
1 change: 1 addition & 0 deletions features/mapping_collector.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Feature: Mapping collector

Scenario: Check that configured mapping aware service have methods mapping
Given I will use kernel with MappingCollector listener
Then Collector should have "DemoApp\Method\MethodA" JSON-RPC method with name "bundledMethodA"
And Collector should have "DemoApp\Method\MethodA" JSON-RPC method with name "bundledMethodA"
And Collector should have "DemoApp\Method\MethodB" JSON-RPC method with name "bundledMethodB"
Expand Down