Commit c8e9d4fa authored by Fabien Potencier's avatar Fabien Potencier

merged branch l3l0/add-lazy-url-matcher-test (PR #404)

Commits
-------

b4f7ce21 Fixed typo
cb3fd7d5 Changed in phpunit.xml.dist and added testsfor lazy url matcher

Discussion
----------

Changed in phpunit.xml.dist and added testsfor lazy url matcher

* Changed in phpunit.xml.dist make sure that tests will covers only code in src directory.
* Added lazy url matcher

Tests passed: [![Build Status](https://secure.travis-ci.org/l3l0/Silex.png?branch=add-lazy-url-matcher-test)](http://travis-ci.org/l3l0/Silex)

---------------------------------------------------------------------------

by igorw at 2012-06-30T12:45:18Z

Nice 👍

Also, how about adding this to .travis.yml:

    script: phpunit --coverage-text

---------------------------------------------------------------------------

by l3l0 at 2012-06-30T14:39:59Z

@igorw Ok I tried but error appear for php 5.3 cause try to cover all code under src even traits: http://travis-ci.org/#!/l3l0/Silex/jobs/1743756

I removed "--coverage-text" in next commit 1201230
parents 4b6c46ee b4f7ce21
......@@ -16,4 +16,9 @@
<directory>./tests/Silex/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Silex\Tests;
use Silex\LazyUrlMatcher;
/**
* LazyUrlMatcher test case.
*
* @author Leszek Prabucki <leszek.prabucki@gmail.com>
*/
class LazyUrlMatcherTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Silex\LazyUrlMatcher::getUrlMatcher
*/
public function testUserMatcherIsCreatedLazily()
{
$callCounter = 0;
$urlMatcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface');
$matcher = new LazyUrlMatcher(function () use ($urlMatcher, &$callCounter) {
$callCounter++;
return $urlMatcher;
});
$this->assertEquals(0, $callCounter);
$matcher->match('path');
$this->assertEquals(1, $callCounter);
}
/**
* @expectedException LogicException
* @expectedExceptionMessage Factory supplied to LazyUrlMatcher must return implementation of UrlMatcherInterface.
*/
public function testThatCanInjectUrlMatcherOnly()
{
$matcher = new LazyUrlMatcher(function () {
return 'someMatcher';
});
$matcher->match('path');
}
/**
* @covers Silex\LazyUrlMatcher::match
*/
public function testMatchIsProxy()
{
$urlMatcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface');
$urlMatcher->expects($this->once())
->method('match')
->with('path')
->will($this->returnValue('matcherReturnValue'));
$matcher = new LazyUrlMatcher(function () use ($urlMatcher) {
return $urlMatcher;
});
$result = $matcher->match('path');
$this->assertEquals('matcherReturnValue', $result);
}
/**
* @covers Silex\LazyUrlMatcher::setContext
*/
public function testSetContextIsProxy()
{
$context = $this->getMock('Symfony\Component\Routing\RequestContext');
$urlMatcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface');
$urlMatcher->expects($this->once())
->method('setContext')
->with($context);
$matcher = new LazyUrlMatcher(function () use ($urlMatcher) {
return $urlMatcher;
});
$result = $matcher->setContext($context);
}
/**
* @covers Silex\LazyUrlMatcher::getContext
*/
public function testGetContextIsProxy()
{
$context = $this->getMock('Symfony\Component\Routing\RequestContext');
$urlMatcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface');
$urlMatcher->expects($this->once())
->method('getContext')
->will($this->returnValue($context));
$matcher = new LazyUrlMatcher(function () use ($urlMatcher) {
return $urlMatcher;
});
$resultContext = $matcher->getContext();
$this->assertSame($resultContext, $context);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment