From fb7dc4ec3e17b17fbd46e08a1ae84598349ed31e Mon Sep 17 00:00:00 2001 From: Ricard Clau Date: Fri, 29 Aug 2014 12:13:40 +0100 Subject: [PATCH] add tests and removed someuseless use and bundle construct --- RaulFraileLadybugBundle.php | 7 --- .../LadybugDataCollectorTest.php | 48 ++++++++++++++++++ .../RaulFraileLadybugExtensionTest.php | 49 +++++++++++++++++++ Tests/Twig/Extension/LadybugExtensionTest.php | 33 +++++++++++++ Twig/Extension/LadybugExtension.php | 1 - composer.json | 4 ++ 6 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 Tests/DataCollector/LadybugDataCollectorTest.php create mode 100644 Tests/DependencyInjection/RaulFraileLadybugExtensionTest.php create mode 100644 Tests/Twig/Extension/LadybugExtensionTest.php diff --git a/RaulFraileLadybugBundle.php b/RaulFraileLadybugBundle.php index 739bdce..f75cca5 100644 --- a/RaulFraileLadybugBundle.php +++ b/RaulFraileLadybugBundle.php @@ -2,7 +2,6 @@ namespace RaulFraile\Bundle\LadybugBundle; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; /** @@ -10,10 +9,4 @@ */ class RaulFraileLadybugBundle extends Bundle { - /** - * Constructor. - */ - public function __construct() - { - } } diff --git a/Tests/DataCollector/LadybugDataCollectorTest.php b/Tests/DataCollector/LadybugDataCollectorTest.php new file mode 100644 index 0000000..466405f --- /dev/null +++ b/Tests/DataCollector/LadybugDataCollectorTest.php @@ -0,0 +1,48 @@ +dumper = m::mock('Ladybug\Dumper'); + $this->dumper->shouldReceive('setFormat')->withArgs(array('html')); + } + + protected function tearDown() + { + $this->dumper = null; + } + + public function testLogDataWorksAsExpected() + { + $this->dumper->shouldReceive('dump')->once()->withArgs(array('#foo#', '#bar#'))->andReturn('#html#'); + $this->dumper->shouldReceive('dump')->once()->withArgs(array('#foo2#', '#bar2#'))->andReturn('#html2#'); + + $ladybugDataCollector = new LadybugDataCollector($this->dumper); + $ladybugDataCollector->log('#foo#', '#bar#'); + $ladybugDataCollector->log('#foo2#', '#bar2#'); + $collectedVars = $ladybugDataCollector->getVars(); + + $this->assertCount(2, $collectedVars); + + foreach ($collectedVars as $collected) { + $this->assertArrayHasKey('file', $collected); + $this->assertArrayHasKey('line', $collected); + $this->assertArrayHasKey('content', $collected); + } + + $this->assertEquals('#html#', $collectedVars[0]['content']); + $this->assertEquals('#html2#', $collectedVars[1]['content']); + } +} \ No newline at end of file diff --git a/Tests/DependencyInjection/RaulFraileLadybugExtensionTest.php b/Tests/DependencyInjection/RaulFraileLadybugExtensionTest.php new file mode 100644 index 0000000..1a92ceb --- /dev/null +++ b/Tests/DependencyInjection/RaulFraileLadybugExtensionTest.php @@ -0,0 +1,49 @@ +extension = new RaulFraileLadybugExtension(); + $this->container = new ContainerBuilder(); + } + + protected function tearDown() + { + $this->extension = null; + $this->container = null; + } + + public function testEmptyConfigUsesDefaultValuesAndServicesAreCreated() + { + $this->extension->load(array(), $this->container); + + $this->assertTrue($this->container->has('data_collector.ladybug_data_collector')); + $this->assertTrue($this->container->has('ladybug.twig.extension')); + $this->assertTrue($this->container->has('ladybug.dumper')); + $this->assertTrue($this->container->has('ladybug.event_listener.ladybug_config_listener')); + + $bundleOptions = $this->container->getParameterBag('raul_fraile_ladybug')->get('ladybug.options'); + $this->assertEquals('modern', $bundleOptions['theme']); + $this->assertFalse($bundleOptions['expanded']); + $this->assertFalse($bundleOptions['silenced']); + $this->assertEquals(9, $bundleOptions['array_max_nesting_level']); + $this->assertEquals(3, $bundleOptions['object_max_nesting_level']); + } +} \ No newline at end of file diff --git a/Tests/Twig/Extension/LadybugExtensionTest.php b/Tests/Twig/Extension/LadybugExtensionTest.php new file mode 100644 index 0000000..3c5299b --- /dev/null +++ b/Tests/Twig/Extension/LadybugExtensionTest.php @@ -0,0 +1,33 @@ +dumper = m::mock('Ladybug\Dumper'); + } + + protected function tearDown() + { + $this->dumper = null; + } + + public function testLadybugDumpWorksAsExpectedInsideTwigExtension() + { + $this->dumper->shouldReceive('dump')->once()->withArgs(array('#foo#', '#bar#'))->andReturn('#html#'); + $ladybugExtension = new LadybugExtension($this->dumper); + + $this->assertEquals('#html#', $ladybugExtension->ladybug_dump('#foo#', '#bar#')); + } +} \ No newline at end of file diff --git a/Twig/Extension/LadybugExtension.php b/Twig/Extension/LadybugExtension.php index acbc101..b7d8189 100644 --- a/Twig/Extension/LadybugExtension.php +++ b/Twig/Extension/LadybugExtension.php @@ -2,7 +2,6 @@ namespace RaulFraile\Bundle\LadybugBundle\Twig\Extension; -use Symfony\Component\DependencyInjection\ContainerInterface; use Ladybug\Dumper; /** diff --git a/composer.json b/composer.json index c3e050c..c886d75 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,10 @@ "raulfraile/ladybug": "~1.0.0", "raulfraile/ladybug-plugin-symfony2": "~1.0.0" }, + "require-dev": { + "phpunit/phpunit": "@stable", + "mockery/mockery": "@stable" + }, "replace": { "raulfraile/LadybugBundle": "dev-master" },