PantherPortalTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testPortal() 0 16 1
A testException() 0 13 1
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