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 : '); |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
|
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.