Skip to content

Commit

Permalink
merged branch henrikbjorn/tests (PR sensiolabs#60)
Browse files Browse the repository at this point in the history
Commits
-------

bfa8505 [ParamConverter] Change test to be complient with parameter-name-bug branch (pass for master and parameter-name-bug)
cc2cdf8 [ParamConverter] Basic Test for ParamConverterManager

Discussion
----------

Tests

Basic test for ParamConverterManager, better to have a single test than none at all
  • Loading branch information
fabpot committed Nov 7, 2011
2 parents 1407783 + bfa8505 commit 96949b8
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
coverage
phpunit.xml
72 changes: 72 additions & 0 deletions Tests/Request/ParamConverter/ParamConverterManagerTest.php
@@ -0,0 +1,72 @@
<?php

namespace Sensio\Bundle\FrameworkExtraBundle\Tests\Request\ParamConverter;

use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration;
use Symfony\Component\HttpFoundation\Request;

class ParamConverterManagerTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->manager = new ParamConverterManager();
}

public function testPriorities()
{
$this->assertEquals(array(), $this->manager->all());

$high = $this->createParamConverterMock();
$low = $this->createParamConverterMock();

$this->manager->add($low);
$this->manager->add($high, 10);

$this->assertEquals(array(
$high,
$low,
), $this->manager->all());
}

public function testApply()
{
$supported = $this->createParamConverterMock();
$supported
->expects($this->once())
->method('supports')
->will($this->returnValue(true))
;
$supported
->expects($this->once())
->method('apply')
->will($this->returnValue(false))
;

$invalid = $this->createParamConverterMock();
$invalid
->expects($this->once())
->method('supports')
->will($this->returnValue(false))
;
$invalid
->expects($this->never())
->method('apply')
;

$configurations = array(
new Configuration\ParamConverter(array(
'name' => 'var',
)),
);

$this->manager->add($supported);
$this->manager->add($invalid);
$this->manager->apply(new Request(), $configurations);
}

protected function createParamConverterMock()
{
return $this->getMock('Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface');
}
}
12 changes: 12 additions & 0 deletions Tests/bootstrap.php
@@ -0,0 +1,12 @@
<?php

require_once $_SERVER['SYMFONY'] . '/Symfony/Component/ClassLoader/UniversalClassLoader.php';

use Symfony\Component\ClassLoader\UniversalClassLoader;

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Sensio\Bundle\FrameworkExtraBundle' => __DIR__ . '/../../',
'Symfony' => $_SERVER['SYMFONY'],
));
$loader->register();
24 changes: 24 additions & 0 deletions phpunit.xml.dist
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
<!--
<php>
<server name="SYMFONY" value="../../vendor/symfony/src" />
</php>
-->
<testsuites>
<testsuite name="SensioFrameworkExtraBundle">
<directory suffix="Test.php">./Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

0 comments on commit 96949b8

Please sign in to comment.