1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
declare(strict_types=1);
|
4
|
|
|
|
5
|
|
|
namespace ArpTest\LaminasFactory;
|
6
|
|
|
|
7
|
|
|
use Arp\LaminasFactory\ApplicationOptionsProviderTrait;
|
8
|
|
|
use Arp\LaminasFactory\Exception\ServiceNotFoundException;
|
9
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
10
|
|
|
use PHPUnit\Framework\TestCase;
|
11
|
|
|
use Psr\Container\ContainerInterface;
|
12
|
|
|
|
13
|
|
|
/**
|
14
|
|
|
* @author Alex Patterson <[email protected]>
|
15
|
|
|
* @package ArpTest\LaminasFactory
|
16
|
|
|
*/
|
17
|
|
|
final class ApplicationOptionsProviderTraitTest extends TestCase
|
18
|
|
|
{
|
19
|
|
|
/**
|
20
|
|
|
* @var ContainerInterface|MockObject
|
21
|
|
|
*/
|
22
|
|
|
private $container;
|
23
|
|
|
|
24
|
|
|
/**
|
25
|
|
|
* @var string
|
26
|
|
|
*/
|
27
|
|
|
private $optionsService;
|
28
|
|
|
|
29
|
|
|
/**
|
30
|
|
|
* Setup the test dependencies.
|
31
|
|
|
*/
|
32
|
|
|
public function setUp(): void
|
33
|
|
|
{
|
34
|
|
|
$this->optionsService = 'config';
|
35
|
|
|
|
36
|
|
|
$this->container = $this->getMockForAbstractClass(ContainerInterface::class);
|
37
|
|
|
}
|
38
|
|
|
|
39
|
|
|
/**
|
40
|
|
|
* Assert that the getApplicationOptions() method will throw a ServiceNotFoundException if the configured
|
41
|
|
|
* application service cannot be found within the container.
|
42
|
|
|
*/
|
43
|
|
|
public function testWillThrowServiceNotFoundExceptionIfTheApplicationServiceCannotBeFound(): void
|
44
|
|
|
{
|
45
|
|
|
/** @var ApplicationOptionsProviderTrait|MockObject $subject */
|
46
|
|
|
$subject = $this->getMockForTrait(ApplicationOptionsProviderTrait::class);
|
47
|
|
|
|
48
|
|
|
$this->container->expects($this->once())
|
49
|
|
|
->method('has')
|
50
|
|
|
->with($this->optionsService)
|
51
|
|
|
->willReturn(false);
|
52
|
|
|
|
53
|
|
|
$this->expectException(ServiceNotFoundException::class);
|
54
|
|
|
$this->expectExceptionMessage(
|
55
|
|
|
sprintf(
|
56
|
|
|
'The required application options service \'%s\' could not be found in \'%s::%s\'.',
|
57
|
|
|
$this->optionsService,
|
58
|
|
|
ApplicationOptionsProviderTrait::class,
|
59
|
|
|
'getApplicationOptions'
|
60
|
|
|
)
|
61
|
|
|
);
|
62
|
|
|
|
63
|
|
|
$subject->getApplicationOptions($this->container);
|
64
|
|
|
}
|
65
|
|
|
}
|
66
|
|
|
|