Skip to content

Commit

Permalink
Merge pull request #60 from ricardclau/add_tests
Browse files Browse the repository at this point in the history
add tests and removed someuseless use and bundle construct
  • Loading branch information
raulfraile committed Aug 29, 2014
2 parents 8a1b4f3 + fb7dc4e commit e2ef2c9
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 8 deletions.
7 changes: 0 additions & 7 deletions RaulFraileLadybugBundle.php
Expand Up @@ -2,18 +2,11 @@

namespace RaulFraile\Bundle\LadybugBundle;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* The bundle main class.
*/
class RaulFraileLadybugBundle extends Bundle
{
/**
* Constructor.
*/
public function __construct()
{
}
}
48 changes: 48 additions & 0 deletions Tests/DataCollector/LadybugDataCollectorTest.php
@@ -0,0 +1,48 @@
<?php

namespace RaulFraile\Bundle\LadybugBundle\Tests\DataCollector;

use Ladybug\Dumper;
use Mockery as m;
use RaulFraile\Bundle\LadybugBundle\DataCollector\LadybugDataCollector;

class LadybugDataCollectorTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Ladybug\Dumper
*/
private $dumper;

protected function setUp()
{
$this->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']);
}
}
49 changes: 49 additions & 0 deletions Tests/DependencyInjection/RaulFraileLadybugExtensionTest.php
@@ -0,0 +1,49 @@
<?php

namespace RaulFraile\Bundle\LadybugBundle\Tests\DependencyInjection;

use RaulFraile\Bundle\LadybugBundle\DependencyInjection\RaulFraileLadybugExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Yaml\Yaml;

class RaulFraileLadybugExtensionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \RaulFraile\Bundle\LadybugBundle\DependencyInjection\RaulFraileLadybugExtension
*/
private $extension;

/**
* @var \Symfony\Component\DependencyInjection\ContainerBuilder
*/
private $container;

protected function setUp()
{
$this->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']);
}
}
33 changes: 33 additions & 0 deletions Tests/Twig/Extension/LadybugExtensionTest.php
@@ -0,0 +1,33 @@
<?php

namespace RaulFraile\Bundle\LadybugBundle\Tests\Twig\Extension;

use Ladybug\Dumper;
use Mockery as m;
use RaulFraile\Bundle\LadybugBundle\Twig\Extension\LadybugExtension;

class LadybugExtensionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Ladybug\Dumper
*/
private $dumper;

protected function setUp()
{
$this->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#'));
}
}
1 change: 0 additions & 1 deletion Twig/Extension/LadybugExtension.php
Expand Up @@ -2,7 +2,6 @@

namespace RaulFraile\Bundle\LadybugBundle\Twig\Extension;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Ladybug\Dumper;

/**
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Expand Up @@ -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"
},
Expand Down

0 comments on commit e2ef2c9

Please sign in to comment.