Completed
Push — master ( 8a830f...5a3013 )
by Sullivan
03:44
created

CloudFrontResultSpy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
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 Sonata\MediaBundle\Tests\CDN;
13
14
/**
15
 * @author Javier Spagnoletti <[email protected]>
16
 */
17
class CloudFrontTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @group legacy
21
     */
22
    public function testLegacyCloudFront()
23
    {
24
        $client = $this->getMock('\Aws\CloudFront\CloudFrontClient', array('createInvalidation'), array(), '', false);
25
        $client->expects($this->exactly(3))->method('createInvalidation')->will($this->returnValue(new CloudFrontResultSpy()));
26
27
        $cloudFront = $this->getMockBuilder('Sonata\MediaBundle\CDN\CloudFront')
28
                    ->setConstructorArgs(array('/foo', 'secret', 'key', 'xxxxxxxxxxxxxx'))
29
                    ->setMethods(null)
30
                    ->getMock();
31
        $cloudFront->setClient($client);
32
33
        $this->assertSame('/foo/bar.jpg', $cloudFront->getPath('bar.jpg', true));
34
35
        $path = '/mypath/file.jpg';
36
37
        $cloudFront->flushByString($path);
38
        $cloudFront->flush($path);
39
        $cloudFront->flushPaths(array($path));
40
    }
41
42
    /**
43
     * @group legacy
44
     */
45
    public function testLegacyException()
46
    {
47
        $this->setExpectedException('\RuntimeException', 'Unable to flush : ');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

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...
48
        $client = $this->getMock('\Aws\CloudFront\CloudFrontClient', array('createInvalidation'), array(), '', false);
49
        $client->expects($this->exactly(1))->method('createInvalidation')->will($this->returnValue(new CloudFrontResultSpy(true)));
50
        $cloudFront = $this->getMockBuilder('Sonata\MediaBundle\CDN\CloudFront')
51
                    ->setConstructorArgs(array('/foo', 'secret', 'key', 'xxxxxxxxxxxxxx'))
52
                    ->setMethods(null)
53
                    ->getMock();
54
        $cloudFront->setClient($client);
55
        $cloudFront->flushPaths(array('boom'));
56
    }
57
}
58
59
class CloudFrontResultSpy
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
60
{
61
    protected $fail = false;
62
63
    public function __construct($fail = false)
64
    {
65
        $this->fail = $fail;
66
    }
67
68
    public function get($data)
69
    {
70
        if ('Status' !== $data || $this->fail) {
71
            return;
72
        }
73
74
        return 'InProgress';
75
    }
76
}
77