PantherPortalTest::testPortal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\MediaBundle\Tests\CDN;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\MediaBundle\CDN\PantherPortal;
18
19
class PantherPortalTest extends TestCase
20
{
21
    public function testPortal(): void
22
    {
23
        $client = $this->createMock(ClientSpy::class);
24
        $client->expects($this->exactly(3))->method('flush')->willReturn('Flush successfully submitted.');
25
26
        $panther = new PantherPortal('/foo', 'login', 'pass', 42);
27
        $panther->setClient($client);
28
29
        $this->assertSame('/foo/bar.jpg', $panther->getPath('bar.jpg', true));
30
31
        $path = '/mypath/file.jpg';
32
33
        $panther->flushByString($path);
34
        $panther->flush($path);
35
        $panther->flushPaths([$path]);
36
    }
37
38
    public function testException(): void
39
    {
40
        $this->expectException(\RuntimeException::class);
41
        $this->expectExceptionMessage('Unable to flush : Failed!!');
42
43
        $client = $this->createMock(ClientSpy::class);
44
        $client->expects($this->once())->method('flush')->willReturn('Failed!!');
45
46
        $panther = new PantherPortal('/foo', 'login', 'pass', 42);
47
        $panther->setClient($client);
48
49
        $panther->flushPaths(['boom']);
50
    }
51
}
52
53
class ClientSpy extends \SoapClient
54
{
55
    public function flush(): string
56
    {
57
        return 'hello';
58
    }
59
}
60