Skip to content

Commit

Permalink
Add test for compiler extension tasks section
Browse files Browse the repository at this point in the history
  • Loading branch information
Koricz authored and stekycz committed Nov 15, 2017
1 parent fd15b6c commit b92cc7a
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/CronnerTests/DI/CronnerExtension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace stekycz\Cronner\tests\DI;

use Nette\Configurator;
use Nette\DI\Compiler;
use Nette\DI\Statement;
use stekycz\CriticalSection\CriticalSection;
Expand Down Expand Up @@ -76,6 +77,20 @@ class CronnerExtensionTest extends \TestCase
Assert::same(Cronner::class, $runner->getClass());
}

public function testRegisterTasks()
{
\Tester\Helpers::purge(__DIR__ . '/../../tmp/');

$config = new Configurator();
$config->setTempDirectory(__DIR__ . '/../../tmp/');
$config->addConfig(__DIR__ . '/../config/config.neon');
$container = $config->createContainer();

$cronner = $container->getByType('stekycz\Cronner\Cronner');

Assert::same(2, count($cronner->getTasks()));
}

}

run(new CronnerExtensionTest());
11 changes: 11 additions & 0 deletions tests/CronnerTests/config/config.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extensions:
cronner: stekycz\Cronner\DI\CronnerExtension

services:
fooService: stekycz\Cronner\tests\objects\FooService


cronner:
tasks:
- stekycz\Cronner\tests\objects\SimpleTestObjectWithDependency(@fooService)
- stekycz\Cronner\tests\objects\AnotherSimpleTestObjectWithDependency(@fooService)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace stekycz\Cronner\tests\objects;

use Nette\Object;

class AnotherSimpleTestObjectWithDependency extends Object
{

public function __construct(FooService $service)
{
}

/**
* @cronner-task
*/
public function run()
{
}
}
13 changes: 13 additions & 0 deletions tests/CronnerTests/objects/FooService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace stekycz\Cronner\tests\objects;

class FooService
{

public function __construct()
{
}

}

21 changes: 21 additions & 0 deletions tests/CronnerTests/objects/SimpleTestObjectWithDependency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace stekycz\Cronner\tests\objects;

use Nette\Object;

class SimpleTestObjectWithDependency extends Object
{

public function __construct(FooService $service)
{
}

/**
* @cronner-task
*/
public function run()
{
}
}

0 comments on commit b92cc7a

Please sign in to comment.