Skip to content

Commit 431b22b

Browse files
felixureclaude
authored andcommitted
Tests: replace ContainerLoader with ContainerBuilder from contributte/tester
Replace Nette\DI\ContainerLoader with Contributte\Tester\Utils\ContainerBuilder and FileMock::create with Neonkit::load for better integration with the contributte/tester package.
1 parent e01516c commit 431b22b

File tree

5 files changed

+203
-271
lines changed

5 files changed

+203
-271
lines changed

tests/Cases/Command/Command.HelperSet.phpt

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
<?php declare(strict_types = 1);
22

33
use Contributte\Console\DI\ConsoleExtension;
4-
use Contributte\Tester\Environment;
54
use Contributte\Tester\Toolkit;
5+
use Contributte\Tester\Utils\ContainerBuilder;
6+
use Contributte\Tester\Utils\Neonkit;
67
use Nette\DI\Compiler;
7-
use Nette\DI\Container;
8-
use Nette\DI\ContainerLoader;
98
use Symfony\Component\Console\Application;
109
use Symfony\Component\Console\Helper\HelperSet;
1110
use Tester\Assert;
12-
use Tester\FileMock;
1311
use Tests\Fixtures\HelperSetCommand;
1412

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

1715
// Test auto filling helperSet in command
1816
Toolkit::test(function (): void {
19-
$loader = new ContainerLoader(Environment::getTestDir(), true);
20-
$class = $loader->load(function (Compiler $compiler): void {
21-
$compiler->addExtension('console', new ConsoleExtension(true));
22-
$compiler->loadConfig(FileMock::create('
23-
console:
24-
services:
25-
- Tests\Fixtures\HelperSetCommand
26-
', 'neon'));
27-
}, [getmypid(), 1]);
28-
29-
/** @var Container $container */
30-
$container = new $class();
17+
$container = ContainerBuilder::of()
18+
->withCompiler(function (Compiler $compiler): void {
19+
$compiler->addExtension('console', new ConsoleExtension(true));
20+
$compiler->addConfig(Neonkit::load(<<<'NEON'
21+
console:
22+
services:
23+
- Tests\Fixtures\HelperSetCommand
24+
NEON));
25+
})->build();
3126

3227
/** @var Application $application */
3328
$application = $container->getByType(Application::class);

tests/Cases/DI/ConsoleExtension.EventDispatcher.phpt

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,30 @@
22

33
use Contributte\Console\Application;
44
use Contributte\Console\DI\ConsoleExtension;
5-
use Contributte\Tester\Environment;
65
use Contributte\Tester\Toolkit;
6+
use Contributte\Tester\Utils\ContainerBuilder;
7+
use Contributte\Tester\Utils\Neonkit;
78
use Nette\DI\Compiler;
8-
use Nette\DI\Container;
9-
use Nette\DI\ContainerLoader;
109
use Symfony\Component\Console\ConsoleEvents;
1110
use Symfony\Component\Console\Event\ConsoleErrorEvent;
1211
use Symfony\Component\Console\Input\ArrayInput;
1312
use Symfony\Component\Console\Output\NullOutput;
1413
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1514
use Tester\Assert;
16-
use Tester\FileMock;
1715
use Tests\Fixtures\ThrowingCommand;
1816

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

2119
Toolkit::test(function (): void {
22-
$loader = new ContainerLoader(Environment::getTestDir(), true);
23-
$class = $loader->load(function (Compiler $compiler): void {
24-
$compiler->addExtension('console', new ConsoleExtension(true));
25-
$compiler->loadConfig(FileMock::create('
26-
services:
27-
- Tests\Fixtures\ThrowingCommand
28-
- Symfony\Component\EventDispatcher\EventDispatcher
29-
', 'neon'));
30-
}, [getmypid(), 1]);
31-
32-
/** @var Container $container */
33-
$container = new $class();
20+
$container = ContainerBuilder::of()
21+
->withCompiler(function (Compiler $compiler): void {
22+
$compiler->addExtension('console', new ConsoleExtension(true));
23+
$compiler->addConfig(Neonkit::load(<<<'NEON'
24+
services:
25+
- Tests\Fixtures\ThrowingCommand
26+
- Symfony\Component\EventDispatcher\EventDispatcher
27+
NEON));
28+
})->build();
3429

3530
/** @var Application $application */
3631
$application = $container->getByType(Application::class);
Lines changed: 42 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,72 @@
11
<?php declare(strict_types = 1);
22

33
use Contributte\Console\DI\ConsoleExtension;
4-
use Contributte\Tester\Environment;
54
use Contributte\Tester\Toolkit;
5+
use Contributte\Tester\Utils\ContainerBuilder;
6+
use Contributte\Tester\Utils\Neonkit;
67
use Nette\DI\Compiler;
7-
use Nette\DI\Container;
8-
use Nette\DI\ContainerLoader;
98
use Nette\DI\InvalidConfigurationException;
109
use Symfony\Component\Console\Application;
1110
use Tester\Assert;
12-
use Tester\FileMock;
1311
use Tests\Fixtures\FooHelperSet;
1412

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

1715
// Default helperSet
1816
Toolkit::test(function (): void {
19-
$loader = new ContainerLoader(Environment::getTestDir(), true);
20-
$class = $loader->load(function (Compiler $compiler): void {
21-
$compiler->addExtension('console', new ConsoleExtension(true));
22-
}, [getmypid(), 1]);
23-
24-
/** @var Container $container */
25-
$container = new $class();
17+
$container = ContainerBuilder::of()
18+
->withCompiler(function (Compiler $compiler): void {
19+
$compiler->addExtension('console', new ConsoleExtension(true));
20+
})->build();
2621

2722
// 4 default helpers
2823
Assert::count(4, $container->getByType(Application::class)->getHelperSet()->getIterator());
2924
});
3025

3126
// Own helperSet
3227
Toolkit::test(function (): void {
33-
$loader = new ContainerLoader(Environment::getTestDir(), true);
34-
$class = $loader->load(function (Compiler $compiler): void {
35-
$compiler->addExtension('console', new ConsoleExtension(true));
36-
$compiler->loadConfig(FileMock::create('
37-
console:
38-
helperSet: Tests\Fixtures\FooHelperSet
39-
', 'neon'));
40-
}, [getmypid(), 2]);
41-
42-
/** @var Container $container */
43-
$container = new $class();
28+
$container = ContainerBuilder::of()
29+
->withCompiler(function (Compiler $compiler): void {
30+
$compiler->addExtension('console', new ConsoleExtension(true));
31+
$compiler->addConfig(Neonkit::load(<<<'NEON'
32+
console:
33+
helperSet: Tests\Fixtures\FooHelperSet
34+
NEON));
35+
})->build();
4436

4537
// Our helper set
4638
Assert::type(FooHelperSet::class, $container->getByType(Application::class)->getHelperSet());
4739
});
4840

4941
// Own helperSet as service
5042
Toolkit::test(function (): void {
51-
$loader = new ContainerLoader(Environment::getTestDir(), true);
52-
$class = $loader->load(function (Compiler $compiler): void {
53-
$compiler->addExtension('console', new ConsoleExtension(true));
54-
$compiler->loadConfig(FileMock::create('
55-
console:
56-
helperSet: @Tests\Fixtures\FooHelperSet
57-
58-
services:
59-
- Tests\Fixtures\FooHelperSet
60-
', 'neon'));
61-
}, [getmypid(), 3]);
43+
$container = ContainerBuilder::of()
44+
->withCompiler(function (Compiler $compiler): void {
45+
$compiler->addExtension('console', new ConsoleExtension(true));
46+
$compiler->addConfig(Neonkit::load(<<<'NEON'
47+
console:
48+
helperSet: @Tests\Fixtures\FooHelperSet
6249
63-
/** @var Container $container */
64-
$container = new $class();
50+
services:
51+
- Tests\Fixtures\FooHelperSet
52+
NEON));
53+
})->build();
6554

6655
// Our helper set
6756
Assert::type(FooHelperSet::class, $container->getByType(Application::class)->getHelperSet());
6857
});
6958

7059
// Own helper
7160
Toolkit::test(function (): void {
72-
$loader = new ContainerLoader(Environment::getTestDir(), true);
73-
$class = $loader->load(function (Compiler $compiler): void {
74-
$compiler->addExtension('console', new ConsoleExtension(true));
75-
$compiler->loadConfig(FileMock::create('
76-
console:
77-
helpers:
78-
- Tests\Fixtures\FooHelper
79-
', 'neon'));
80-
}, [getmypid(), 4]);
81-
82-
/** @var Container $container */
83-
$container = new $class();
61+
$container = ContainerBuilder::of()
62+
->withCompiler(function (Compiler $compiler): void {
63+
$compiler->addExtension('console', new ConsoleExtension(true));
64+
$compiler->addConfig(Neonkit::load(<<<'NEON'
65+
console:
66+
helpers:
67+
- Tests\Fixtures\FooHelper
68+
NEON));
69+
})->build();
8470

8571
// 4 default helpers
8672
// 1 foo helper
@@ -90,13 +76,13 @@ Toolkit::test(function (): void {
9076
// Null helperSet
9177
Toolkit::test(function (): void {
9278
Assert::exception(function (): void {
93-
$loader = new ContainerLoader(Environment::getTestDir(), true);
94-
$loader->load(function (Compiler $compiler): void {
95-
$compiler->addExtension('console', new ConsoleExtension(true));
96-
$compiler->loadConfig(FileMock::create('
97-
console:
98-
helperSet: null
99-
', 'neon'));
100-
}, [getmypid(), 5]);
101-
}, InvalidConfigurationException::class, "The item 'console › helperSet' expects to be string|Nette\DI\Definitions\Statement, null given.");
79+
ContainerBuilder::of()
80+
->withCompiler(function (Compiler $compiler): void {
81+
$compiler->addExtension('console', new ConsoleExtension(true));
82+
$compiler->addConfig(Neonkit::load(<<<'NEON'
83+
console:
84+
helperSet: null
85+
NEON));
86+
})->build();
87+
}, InvalidConfigurationException::class, "~The item 'console.+helperSet' expects to be string\|Nette\\\\DI\\\\Definitions\\\\Statement, null given\.~");
10288
});

tests/Cases/DI/ConsoleExtension.lazy.phpt

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,28 @@
33
use Contributte\Console\Application;
44
use Contributte\Console\CommandLoader\ContainerCommandLoader;
55
use Contributte\Console\DI\ConsoleExtension;
6-
use Contributte\Tester\Environment;
76
use Contributte\Tester\Toolkit;
7+
use Contributte\Tester\Utils\ContainerBuilder;
8+
use Contributte\Tester\Utils\Neonkit;
89
use Nette\DI\Compiler;
9-
use Nette\DI\Container;
10-
use Nette\DI\ContainerLoader;
1110
use Symfony\Component\Console\Command\Command;
1211
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
1312
use Tester\Assert;
14-
use Tester\FileMock;
1513
use Tests\Fixtures\FooCommand;
1614

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

1917
// 1 command of type FooCommand lazy-loading
2018
Toolkit::test(function (): void {
21-
$loader = new ContainerLoader(Environment::getTestDir(), true);
22-
$class = $loader->load(function (Compiler $compiler): void {
23-
$compiler->addExtension('console', new ConsoleExtension(true));
24-
$compiler->loadConfig(FileMock::create('
25-
console:
26-
services:
27-
foo: Tests\Fixtures\FooCommand
28-
', 'neon'));
29-
}, [getmypid(), 1]);
30-
31-
/** @var Container $container */
32-
$container = new $class();
19+
$container = ContainerBuilder::of()
20+
->withCompiler(function (Compiler $compiler): void {
21+
$compiler->addExtension('console', new ConsoleExtension(true));
22+
$compiler->addConfig(Neonkit::load(<<<'NEON'
23+
console:
24+
services:
25+
foo: Tests\Fixtures\FooCommand
26+
NEON));
27+
})->build();
3328

3429
Assert::type(Application::class, $container->getByType(Application::class));
3530

0 commit comments

Comments
 (0)