Permalink
Browse files

merged branch henrikbjorn/tests (PR #60)

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...
2 parents 1407783 + bfa8505 commit 96949b8535b52ca6f2639f3fb75899545cabd954 @fabpot fabpot committed Nov 7, 2011
Showing with 110 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +72 −0 Tests/Request/ParamConverter/ParamConverterManagerTest.php
  3. +12 −0 Tests/bootstrap.php
  4. +24 −0 phpunit.xml.dist
View
@@ -0,0 +1,2 @@
+coverage
+phpunit.xml
@@ -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');
+ }
+}
View
@@ -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();
View
@@ -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.