diff --git a/composer.json b/composer.json index f201f43..ebad5e6 100644 --- a/composer.json +++ b/composer.json @@ -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" @@ -44,6 +46,9 @@ ] } }, + "config": { + "sort-packages": true + }, "scripts": { "build": [ "@composer validate --no-check-all", diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php new file mode 100644 index 0000000..4735854 --- /dev/null +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -0,0 +1,76 @@ +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); + } + +} diff --git a/tests/DependencyInjection/JavaScriptErrorHandlerExtensionTest.php b/tests/DependencyInjection/JavaScriptErrorHandlerExtensionTest.php new file mode 100644 index 0000000..f497898 --- /dev/null +++ b/tests/DependencyInjection/JavaScriptErrorHandlerExtensionTest.php @@ -0,0 +1,62 @@ +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); + } + +}