Completed
Push — master ( f99499...153a9a )
by Alex
14s queued 11s
created

ApplicationOptionsProviderTraitTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testWillThrowServiceNotFoundExceptionIfTheApplicationServiceCannotBeFound() 0 21 1
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