forked from dotkernel/dot-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginManagerFactoryTest.php
More file actions
99 lines (84 loc) · 3.21 KB
/
PluginManagerFactoryTest.php
File metadata and controls
99 lines (84 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
declare(strict_types=1);
namespace DotTest\Controller\Factory;
use Dot\Controller\Factory\PluginManagerFactory as Subject;
use Dot\Controller\Plugin\PluginManager;
use Dot\Controller\Plugin\TemplatePlugin;
use Dot\Controller\Plugin\UrlHelperPlugin;
use Mezzio\Helper\UrlHelper;
use Mezzio\Template\TemplateRendererInterface;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
class PluginManagerFactoryTest extends TestCase
{
private Subject $subject;
private ContainerInterface|MockObject $container;
private TemplateRendererInterface|MockObject $templateRenderer;
private UrlHelper|MockObject $urlHelper;
/**
* @throws Exception
*/
public function setUp(): void
{
$this->subject = new Subject();
$this->container = $this->createMock(ContainerInterface::class);
$this->templateRenderer = $this->createMock(TemplateRendererInterface::class);
$this->urlHelper = $this->createMock(UrlHelper::class);
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function testInvokeWithUrlHelper(): void
{
$config = [
'dot_controller' => [
'plugin_manager' => [],
],
];
$this->container->method('has')->willReturnMap([
[UrlHelper::class, true],
[TemplateRendererInterface::class, false],
]);
$this->container->method('get')->willReturnMap([
[TemplateRendererInterface::class, $this->templateRenderer],
[UrlHelper::class, $this->urlHelper],
['config', $config],
]);
$pluginManager = $this->subject->__invoke($this->container);
$this->assertContainsOnlyInstancesOf(PluginManager::class, [$pluginManager]);
$this->assertTrue($pluginManager->has('url'));
$this->assertFalse($pluginManager->has('template'));
$this->assertInstanceOf(UrlHelperPlugin::class, $pluginManager->get('url'));
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function testInvokeWithTemplateRenderer(): void
{
$config = [
'dot_controller' => [
'plugin_manager' => [],
],
];
$this->container->method('has')->willReturnMap([
[UrlHelper::class, false],
[TemplateRendererInterface::class, true],
]);
$this->container->method('get')->willReturnMap([
[TemplateRendererInterface::class, $this->templateRenderer],
[UrlHelper::class, $this->urlHelper],
['config', $config],
]);
$pluginManager = $this->subject->__invoke($this->container);
$this->assertContainsOnlyInstancesOf(PluginManager::class, [$pluginManager]);
$this->assertTrue($pluginManager->has('template'));
$this->assertFalse($pluginManager->has('url'));
$this->assertInstanceOf(TemplatePlugin::class, $pluginManager->get('template'));
}
}