Completed
Pull Request — master (#299)
by David
67:30 queued 64:42
created

getStatusCodesThatTriggerInvalidation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Functional\EventListener;
13
14
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
15
16
class InvalidationSubscriberTest extends WebTestCase
17
{
18
    public function testInvalidateRoute()
19
    {
20
        $client = static::createClient();
21
22
        $client->getContainer()->mock(
0 ignored issues
show
Bug introduced by
The method mock() does not seem to exist on object<Symfony\Component...ion\ContainerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
            'fos_http_cache.cache_manager',
24
            '\FOS\HttpCacheBundle\CacheManager'
25
        )
26
            ->shouldReceive('supports')->andReturn(true)
27
            ->shouldReceive('invalidateRoute')->once()->with('test_noncached', array())
28
            ->shouldReceive('invalidateRoute')->once()->with('test_cached', array('id' => 'myhardcodedid'))
29
            ->shouldReceive('invalidateRoute')->once()->with('tag_one', array('id' => '42'))
30
            ->shouldReceive('flush')->once()
31
        ;
32
33
        $client->request('POST', '/invalidate/route/42');
34
    }
35
36
    /**
37
     * @dataProvider getStatusCodesThatTriggerInvalidation
38
     */
39
    public function testInvalidatePath($statusCode)
40
    {
41
        $client = static::createClient();
42
43
        $client->getContainer()->mock(
0 ignored issues
show
Bug introduced by
The method mock() does not seem to exist on object<Symfony\Component...ion\ContainerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
            'fos_http_cache.cache_manager',
45
            '\FOS\HttpCacheBundle\CacheManager'
46
        )
47
            ->shouldReceive('supports')->andReturn(true)
48
            ->shouldReceive('invalidatePath')->once()->with('/cached')
49
            ->shouldReceive('invalidatePath')->once()->with(
50
                sprintf('/invalidate/path/%s', $statusCode)
51
            )
52
            ->shouldReceive('flush')->once()
53
        ;
54
55
        $client->request('POST', sprintf('/invalidate/path/%s', $statusCode));
56
    }
57
58 View Code Duplication
    public function testErrorIsNotInvalidated()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $client = static::createClient();
61
62
        $client->getContainer()->mock(
0 ignored issues
show
Bug introduced by
The method mock() does not seem to exist on object<Symfony\Component...ion\ContainerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
            'fos_http_cache.cache_manager',
64
            '\FOS\HttpCacheBundle\CacheManager'
65
        )
66
            ->shouldReceive('supports')->andReturn(true)
67
            ->shouldReceive('invalidatePath')->never()
68
            ->shouldReceive('flush')->once()
69
        ;
70
71
        $client->request('POST', '/invalidate/error');
72
    }
73
74
    public function getStatusCodesThatTriggerInvalidation()
75
    {
76
        return array(array(200), array(204), array(302));
77
    }
78
79
    protected function tearDown()
80
    {
81
        static::createClient()->getContainer()->unmock('fos_http_cache.cache_manager');
0 ignored issues
show
Bug introduced by
The method unmock() does not seem to exist on object<Symfony\Component...ion\ContainerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
    }
83
}
84