Skip to content

Commit

Permalink
Tests: split testing extension into two files (skip lazy if symfony/c…
Browse files Browse the repository at this point in the history
…onsole < 4.x)
  • Loading branch information
f3l1x committed Apr 6, 2018
1 parent 49e596f commit 6883dd5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
44 changes: 44 additions & 0 deletions tests/cases/DI/ConsoleExtension.lazy.phpt
@@ -0,0 +1,44 @@
<?php

/**
* Test: DI\ConsoleExtension [lazy]
*/

use Contributte\Console\Application;
use Contributte\Console\DI\ConsoleExtension;
use Nette\DI\Compiler;
use Nette\DI\Container;
use Nette\DI\ContainerLoader;
use Symfony\Component\Console\Command\Command;
use Tester\Assert;
use Tester\Environment;
use Tester\FileMock;
use Tests\Fixtures\FooCommand;

require_once __DIR__ . '/../../bootstrap.php';

if (!class_exists('Symfony\Component\Console\CommandLoader\CommandLoaderInterface')) {
Environment::skip('symfony/console 4.x is required');
}

// 1 command of type FooCommand lazy-loading
test(function () {
$loader = new ContainerLoader(TEMP_DIR, TRUE);
$class = $loader->load(function (Compiler $compiler) {
$compiler->addExtension('console', new ConsoleExtension());
$compiler->loadConfig(FileMock::create('
console:
lazy: on
services:
foo: Tests\Fixtures\FooCommand
', 'neon'));
}, [microtime(), 3]);

/** @var Container $container */
$container = new $class;

Assert::type(Application::class, $container->getByType(Application::class));
Assert::false($container->isCreated('foo'));
Assert::count(1, $container->findByType(Command::class));
Assert::type(FooCommand::class, $container->getByType(Command::class));
});
22 changes: 0 additions & 22 deletions tests/cases/DI/ConsoleExtension.phpt
Expand Up @@ -50,25 +50,3 @@ test(function () {
Assert::count(1, $container->findByType(Command::class));
Assert::type(FooCommand::class, $container->getByType(Command::class));
});

// 1 command of type FooCommand lazy-loading
test(function () {
$loader = new ContainerLoader(TEMP_DIR, TRUE);
$class = $loader->load(function (Compiler $compiler) {
$compiler->addExtension('console', new ConsoleExtension());
$compiler->loadConfig(FileMock::create('
console:
lazy: on
services:
foo: Tests\Fixtures\FooCommand
', 'neon'));
}, [microtime(), 3]);

/** @var Container $container */
$container = new $class;

Assert::type(Application::class, $container->getByType(Application::class));
Assert::false($container->isCreated('foo'));
Assert::count(1, $container->findByType(Command::class));
Assert::type(FooCommand::class, $container->getByType(Command::class));
});

0 comments on commit 6883dd5

Please sign in to comment.