Completed
Push — master ( 1f2c49...ea4d71 )
by David
9s
created

CacheManagerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
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\Unit;
13
14
use FOS\HttpCache\ProxyClient\Invalidation\BanInterface;
15
use FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface;
16
use FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface;
17
use FOS\HttpCache\ProxyClient\ProxyClientInterface;
18
use FOS\HttpCacheBundle\CacheManager;
19
use Symfony\Component\HttpFoundation\Response;
20
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
21
22
class CacheManagerTest extends \PHPUnit_Framework_TestCase
23
{
24
    protected $proxyClient;
25
26
    public function setUp()
27
    {
28
        $this->proxyClient = \Mockery::mock(ProxyClientInterface::class);
29
    }
30
31
    public function testInvalidateRoute()
32
    {
33
        $httpCache = \Mockery::mock(PurgeInterface::class)
34
            ->shouldReceive('purge')->once()->with('/my/route', array())
35
            ->shouldReceive('purge')->once()->with('/route/with/params/id/123', array())
36
            ->shouldReceive('purge')->once()->with('/route/with/params/id/123', array('X-Foo' => 'bar'))
37
            ->shouldReceive('flush')->once()
38
            ->getMock();
39
40
        $router = \Mockery::mock('\Symfony\Component\Routing\Generator\UrlGeneratorInterface')
41
            ->shouldReceive('generate')
42
            ->with('my_route', array(), UrlGeneratorInterface::ABSOLUTE_PATH)
43
            ->andReturn('/my/route')
44
45
            ->shouldReceive('generate')
46
            ->with('route_with_params', array('id' => 123), UrlGeneratorInterface::ABSOLUTE_PATH)
47
            ->andReturn('/route/with/params/id/123')
48
            ->getMock();
49
50
        $cacheManager = new CacheManager($httpCache, $router);
51
52
        $cacheManager->invalidateRoute('my_route')
53
            ->invalidateRoute('route_with_params', array('id' => 123))
54
            ->invalidateRoute('route_with_params', array('id' => 123), array('X-Foo' => 'bar'))
55
            ->flush();
56
    }
57
58
    public function testRefreshRoute()
59
    {
60
        $httpCache = \Mockery::mock(RefreshInterface::class)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
61
            ->shouldReceive('refresh')->once()->with('/my/route', null)
62
            ->shouldReceive('refresh')->once()->with('/route/with/params/id/123', null)
63
            ->shouldReceive('refresh')->once()->with('/route/with/params/id/123', array('X-Foo' => 'bar'))
64
            ->shouldReceive('flush')->never()
65
            ->getMock();
66
67
        $router = \Mockery::mock('\Symfony\Component\Routing\Generator\UrlGeneratorInterface')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Mockery\Expectation>.

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...
68
            ->shouldReceive('generate')
69
            ->with('my_route', array(), UrlGeneratorInterface::ABSOLUTE_PATH)
70
            ->andReturn('/my/route')
71
72
            ->shouldReceive('generate')
73
            ->with('route_with_params', array('id' => 123), UrlGeneratorInterface::ABSOLUTE_PATH)
74
            ->andReturn('/route/with/params/id/123')
75
            ->getMock();
76
77
        $cacheManager = new CacheManager($httpCache, $router);
78
79
        $cacheManager
80
            ->refreshRoute('my_route')
81
            ->refreshRoute('route_with_params', array('id' => 123))
82
            ->refreshRoute('route_with_params', array('id' => 123), array('X-Foo' => 'bar'))
83
        ;
84
    }
85
86
    /**
87
     * @group legacy
88
     */
89
    public function testTagResponse()
90
    {
91
        $this->markTestSkipped('TODO refactor to use tag handler');
92
        $ban = \Mockery::mock(BanInterface::class);
93
        $router = \Mockery::mock(UrlGeneratorInterface::class);
94
95
        $tags1 = array('post-1', 'posts');
96
        $tags2 = array('post-2');
97
        $tags3 = array('different');
98
99
        $cacheManager = new CacheManager($ban, $router);
100
        $response = new Response();
101
        $response->headers->set($cacheManager->getTagsHeader(), '');
0 ignored issues
show
Bug introduced by
The method getTagsHeader() does not seem to exist on object<FOS\HttpCacheBundle\CacheManager>.

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...
102
        $cacheManager->tagResponse($response, $tags1);
0 ignored issues
show
Deprecated Code introduced by
The method FOS\HttpCacheBundle\CacheManager::tagResponse() has been deprecated with message: Add tags with TagHandler::addTags and then use TagHandler::tagResponse

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
103
        $this->assertTrue($response->headers->has($cacheManager->getTagsHeader()));
0 ignored issues
show
Bug introduced by
The method getTagsHeader() does not seem to exist on object<FOS\HttpCacheBundle\CacheManager>.

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...
104
        $this->assertEquals(implode(',', $tags1), $response->headers->get($cacheManager->getTagsHeader()));
0 ignored issues
show
Bug introduced by
The method getTagsHeader() does not seem to exist on object<FOS\HttpCacheBundle\CacheManager>.

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...
105
106
        $cacheManager->tagResponse($response, $tags2);
0 ignored issues
show
Deprecated Code introduced by
The method FOS\HttpCacheBundle\CacheManager::tagResponse() has been deprecated with message: Add tags with TagHandler::addTags and then use TagHandler::tagResponse

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
107
        $this->assertEquals(implode(',', array_merge($tags1, $tags2)), $response->headers->get($cacheManager->getTagsHeader()));
0 ignored issues
show
Bug introduced by
The method getTagsHeader() does not seem to exist on object<FOS\HttpCacheBundle\CacheManager>.

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...
108
109
        $cacheManager->tagResponse($response, $tags3, true);
0 ignored issues
show
Deprecated Code introduced by
The method FOS\HttpCacheBundle\CacheManager::tagResponse() has been deprecated with message: Add tags with TagHandler::addTags and then use TagHandler::tagResponse

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
110
        $this->assertEquals(implode(',', $tags3), $response->headers->get($cacheManager->getTagsHeader()));
0 ignored issues
show
Bug introduced by
The method getTagsHeader() does not seem to exist on object<FOS\HttpCacheBundle\CacheManager>.

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...
111
    }
112
}
113