Skip to content

Commit

Permalink
Simplify extension test
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar authored and Milan Felix Šulc committed May 29, 2019
1 parent 503fcd4 commit 7202b4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 40 deletions.
19 changes: 0 additions & 19 deletions tests/NeonLoader.php

This file was deleted.

27 changes: 6 additions & 21 deletions tests/Unit/DI/MonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,13 @@
use Nette\DI\ContainerLoader;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Tests\Contributte\Monolog\NeonLoader;

class MonologExtensionTest extends TestCase
{

public function testRegistration(): void
{
$container = $this->createContainer(NeonLoader::load('
monolog:
channel:
default:
handlers:
- Monolog\Handler\NullHandler
foo:
handlers:
- Monolog\Handler\NullHandler
manager:
enabled: true
'));
$container = $this->createContainer(__DIR__ . '/config.neon');

/** @var Logger $default */
$default = $container->getByType(LoggerInterface::class);
Expand Down Expand Up @@ -58,19 +46,16 @@ public function testRegistrationNoDefault(): void
$this->expectException(InvalidStateException::class);
$this->expectExceptionMessage('monolog.channel.default is required.');

$container = $this->createContainer([]);
$container = $this->createContainer(__DIR__ . '/empty.neon');
}

/**
* @param mixed[] $config
*/
private function createContainer(array $config): Container
private function createContainer(string $configFile): Container
{
$loader = new ContainerLoader(__DIR__ . '/../../../temp/tests/' . getmypid(), true);
$class = $loader->load(function (Compiler $compiler) use ($config): void {
$compiler->addConfig($config);
$class = $loader->load(function (Compiler $compiler) use ($configFile): void {
$compiler->loadConfig($configFile);
$compiler->addExtension('monolog', new MonologExtension());
}, serialize($config));
}, random_bytes(10));

/** @var Container $container */
return new $class();
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/DI/config.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
monolog:
channel:
default:
handlers:
- Monolog\Handler\NullHandler
foo:
handlers:
- Monolog\Handler\NullHandler
manager:
enabled: true
Empty file added tests/Unit/DI/empty.neon
Empty file.

0 comments on commit 7202b4f

Please sign in to comment.