Skip to content

Commit 2a89ae2

Browse files
added functional testcases
1 parent 7ac6a59 commit 2a89ae2

File tree

6 files changed

+66
-5
lines changed

6 files changed

+66
-5
lines changed

src/DependencyInjection/HandlerCompilerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function process(ContainerBuilder $container)
3333
foreach ($tags as $attributes) {
3434
$definition->addMethodCall(
3535
self::ADD_FUNCTION_NAME,
36-
[$attributes['name'], new Reference($id)]
36+
[$attributes['handler-name'], new Reference($id)]
3737
);
3838
}
3939
}

tests/Functional/SchedulerTest.php renamed to tests/Functional/BootstrapTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Task\SchedulerInterface;
77
use Task\Storage\ArrayStorage;
88

9-
class SchedulerTest extends KernelTestCase
9+
class BootstrapTest extends KernelTestCase
1010
{
1111
public function testBootstrap()
1212
{

tests/Functional/HandlerTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Functional;
4+
5+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6+
7+
class HandlerTest extends KernelTestCase
8+
{
9+
protected function setUp()
10+
{
11+
parent::setUp();
12+
13+
$this->bootKernel();
14+
}
15+
16+
public function testHas()
17+
{
18+
$registry = self::$kernel->getContainer()->get('task.handler_registry');
19+
20+
$this->assertTrue($registry->has('test'));
21+
}
22+
23+
public function testRun()
24+
{
25+
$registry = self::$kernel->getContainer()->get('task.handler_registry');
26+
27+
$this->assertEquals('daolkrow', $registry->run('test', 'workload'));
28+
}
29+
}

tests/Unit/DependencyInjection/HandlerCompilerPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public function testProcess()
2121
->willReturn(
2222
[
2323
'id-1' => [
24-
['name' => 'name-1'],
24+
['handler-name' => 'name-1'],
2525
],
2626
'id-2' => [
27-
['name' => 'name-2-1'],
28-
['name' => 'name-2-2'],
27+
['handler-name' => 'name-2-1'],
28+
['handler-name' => 'name-2-2'],
2929
],
3030
]
3131
);

tests/app/TestKernel.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3+
use Symfony\Component\Config\FileLocator;
34
use Symfony\Component\Config\Loader\LoaderInterface;
5+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
46
use Symfony\Component\HttpKernel\Kernel;
57
use Task\TaskBundle\TaskBundle;
68

@@ -25,4 +27,24 @@ public function registerContainerConfiguration(LoaderInterface $loader)
2527
{
2628
$loader->load(sprintf('%s/config/config.%s.yml', __DIR__, getenv(self::STORAGE_VAR_NAME)));
2729
}
30+
31+
protected function buildContainer()
32+
{
33+
$container = parent::buildContainer();
34+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/config'));
35+
$loader->load('services.xml');
36+
37+
return $container;
38+
}
39+
}
40+
41+
class TestHandler implements \Task\Handler\HandlerInterface
42+
{
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function handle($workload)
47+
{
48+
return strrev($workload);
49+
}
2850
}

tests/app/config/services.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
<services>
6+
<service id="test.handler" class="TestHandler">
7+
<tag name="task.handler" handler-name="test"/>
8+
</service>
9+
</services>
10+
</container>

0 commit comments

Comments
 (0)