Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container tests #2

Merged
merged 5 commits into from
Oct 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"require-dev": {
"consistence/coding-standard": "2.2.1",
"jakub-onderka/php-parallel-lint": "0.9.2",
"matthiasnoback/symfony-config-test": "3.0.1",
"matthiasnoback/symfony-dependency-injection-test": "2.2.0",
"phpstan/phpstan-shim": "0.8.4",
"phpunit/phpunit": "6.4.3",
"satooshi/php-coveralls": "1.0.1"
Expand All @@ -44,6 +46,9 @@
]
}
},
"config": {
"sort-packages": true
},
"scripts": {
"build": [
"@composer validate --no-check-all",
Expand Down
76 changes: 76 additions & 0 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types = 1);

namespace Mhujer\JavaScriptErrorHandlerBundle\DependencyInjection;

use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class ConfigurationTest extends TestCase
{

use ConfigurationTestCaseTrait;

public function testEmptyConfigurationIsValid(): void
{
$this->assertConfigurationIsValid(
[
[], // no values at all
]
);
}

public function testEnabledConfigurationIsValid(): void
{
$this->assertConfigurationIsValid(
[
[
'enabled' => true,
],
]
);
}

public function testDisabledConfigurationIsValid(): void
{
$this->assertConfigurationIsValid(
[
[
'enabled' => false,
],
]
);
}

public function testEnabledConfigurationIsValidXX(): void
{
$this->assertConfigurationIsInvalid(
[
[
'enabled' => 1,
],
],
'Invalid type for path "java_script_error_handler.enabled". Expected boolean, but got integer.'
);
}

public function testInvalidConfigurationIsInvalid(): void
{
$this->assertConfigurationIsInvalid(
[
[
'invalid_option' => 1,
],
],
'Unrecognized option "invalid_option" under "java_script_error_handler"'
);
}

protected function getConfiguration(): ConfigurationInterface
{
return new Configuration(true);
}

}
62 changes: 62 additions & 0 deletions tests/DependencyInjection/JavaScriptErrorHandlerExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types = 1);

namespace Mhujer\JavaScriptErrorHandlerBundle\DependencyInjection;

use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Mhujer\JavaScriptErrorHandlerBundle\EventListener\JsErrorToAlertListener;

class JavaScriptErrorHandlerExtensionTest extends AbstractExtensionTestCase
{

private const LISTENER_CLASS_NAME = JsErrorToAlertListener::class;

protected function getContainerExtensions()
{
return [
new JavaScriptErrorHandlerExtension(),
];
}

public function testListenerIsRegisteredInDebugMode(): void
{
$this->container->setParameter('kernel.debug', true);

$this->load();

$this->assertContainerBuilderHasService(self::LISTENER_CLASS_NAME);
}

public function testListenerIsNotRegisteredWithoutDebugMode(): void
{
$this->container->setParameter('kernel.debug', false);

$this->load();

$this->assertContainerBuilderNotHasService(self::LISTENER_CLASS_NAME);
}

public function testKernelDebugCanBeOverriddenToDisable(): void
{
$this->container->setParameter('kernel.debug', true);

$this->load([
'enabled' => false,
]);

$this->assertContainerBuilderNotHasService(self::LISTENER_CLASS_NAME);
}

public function testKernelDebugCanBeOverriddenToEnable(): void
{
$this->container->setParameter('kernel.debug', false);

$this->load([
'enabled' => true,
]);

$this->assertContainerBuilderHasService(self::LISTENER_CLASS_NAME);
}

}