Completed
Push — master ( 9de1be...100987 )
by David
8s
created

RuleMatcherTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testRequestMatcherCalled() 0 10 1
A testAdditionalCacheableStatus() 0 8 1
A testMatchResponse() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCacheBundle\Tests\Unit\Http;
13
14
use FOS\HttpCacheBundle\Http\RuleMatcher;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\RequestMatcher;
17
use Symfony\Component\HttpFoundation\Response;
18
19
class RuleMatcherTest extends \PHPUnit_Framework_TestCase
20
{
21
    public function testRequestMatcherCalled()
22
    {
23
        $requestMatcher = new RequestMatcher(null, null, null, null, array('_controller' => '^AcmeBundle:Default:index$'));
24
        $ruleMatcher = new RuleMatcher($requestMatcher, array());
25
26
        $request = new Request();
27
        $request->attributes->set('_controller', 'AcmeBundle:Default:index');
28
29
        $this->assertTrue($ruleMatcher->matches($request, new Response()));
30
    }
31
32
    public function testAdditionalCacheableStatus()
33
    {
34
        $ruleMatcher = new RuleMatcher(new RequestMatcher(), array('additional_cacheable_status' => array(400, 500)));
35
36
        $this->assertFalse($ruleMatcher->matches(new Request(), new Response('', 504)));
37
        $this->assertTrue($ruleMatcher->matches(new Request(), new Response('', 500)));
38
        $this->assertTrue($ruleMatcher->matches(new Request(), new Response('', 200)));
39
    }
40
41
    public function testMatchResponse()
42
    {
43
        $ruleMatcher = new RuleMatcher(new RequestMatcher(), array('match_response' => 'response.getStatusCode() >= 300'));
44
45
        $this->assertFalse($ruleMatcher->matches(new Request(), new Response('', 100)));
46
        $this->assertTrue($ruleMatcher->matches(new Request(), new Response('', 500)));
47
    }
48
}
49