|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gorynych\Tests\Resource; |
|
6
|
|
|
|
|
7
|
|
|
use Gorynych\Exception\NotExistentResourceException; |
|
8
|
|
|
use Gorynych\Operation\ResourceOperationInterface; |
|
9
|
|
|
use Gorynych\Resource\AbstractResource; |
|
10
|
|
|
use Gorynych\Resource\ResourceLoader; |
|
11
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
use Symfony\Component\Config\FileLocator; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
15
|
|
|
|
|
16
|
|
|
class ResourceLoaderTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var ContainerInterface|MockObject */ |
|
19
|
|
|
private $containerMock; |
|
20
|
|
|
|
|
21
|
|
|
public function setUp(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$this->containerMock = $this->createMock(ContainerInterface::class); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testLoadsResource(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$operationMock = $this->createMock(ResourceOperationInterface::class); |
|
29
|
|
|
|
|
30
|
|
|
$resourceMock = $this->createMock(AbstractResource::class); |
|
31
|
|
|
$resourceMock->expects($this->once())->method('addOperation')->with($operationMock); |
|
32
|
|
|
|
|
33
|
|
|
$this->containerMock |
|
34
|
|
|
->expects($this->exactly(2)) |
|
35
|
|
|
->method('get') |
|
36
|
|
|
->withConsecutive(['TestResource'], ['TestOperation']) |
|
37
|
|
|
->willReturnOnConsecutiveCalls($resourceMock, $operationMock); |
|
38
|
|
|
|
|
39
|
|
|
$this->setUpLoader()->loadResource('TestResource'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testThrowsNotExistentResource(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$this->expectException(NotExistentResourceException::class); |
|
45
|
|
|
|
|
46
|
|
|
$this->setUpLoader()->loadResource('NotExistentResource'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
private function setUpLoader(): ResourceLoader |
|
50
|
|
|
{ |
|
51
|
|
|
return new ResourceLoader($this->containerMock, new FileLocator(__DIR__ . '/Resource')); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|