1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MtMail - e-mail module for Zend Framework |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/mtymek/MtMail |
6
|
|
|
* @copyright Copyright (c) 2013-2017 Mateusz Tymek |
7
|
|
|
* @license BSD 2-Clause |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace MtMailTest\Factory; |
11
|
|
|
|
12
|
|
|
use Interop\Container\ContainerInterface; |
13
|
|
|
use MtMail\ComposerPlugin\PluginInterface; |
14
|
|
|
use MtMail\Factory\ComposerServiceFactory; |
15
|
|
|
use MtMail\Renderer\RendererInterface; |
16
|
|
|
use MtMail\Service\Composer; |
17
|
|
|
use MtMail\Service\ComposerPluginManager; |
18
|
|
|
|
19
|
|
|
class ComposerServiceFactoryTest extends \PHPUnit\Framework\TestCase |
20
|
|
|
{ |
21
|
|
|
public function testCreateService() |
22
|
|
|
{ |
23
|
|
|
$pluginManager = $this->prophesize(ComposerPluginManager::class); |
24
|
|
|
$locator = $this->prophesize(ContainerInterface::class); |
25
|
|
|
$locator->get('Configuration')->willReturn( |
26
|
|
|
[ |
27
|
|
|
'mt_mail' => [ |
28
|
|
|
'renderer' => 'Some\Mail\Renderer', |
29
|
|
|
], |
30
|
|
|
] |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
$renderer = $this->prophesize(RendererInterface::class); |
34
|
|
|
$locator->get('Some\Mail\Renderer')->willReturn($renderer->reveal()); |
35
|
|
|
$locator->get(ComposerPluginManager::class)->willReturn($pluginManager->reveal()); |
36
|
|
|
|
37
|
|
|
$factory = new ComposerServiceFactory(); |
38
|
|
|
$service = $factory($locator->reveal()); |
39
|
|
|
$this->assertInstanceOf(Composer::class, $service); |
40
|
|
|
$this->assertEquals($renderer->reveal(), $service->getRenderer()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testCreateServiceCanInjectPlugins() |
44
|
|
|
{ |
45
|
|
|
$plugin = $this->prophesize(PluginInterface::class); |
46
|
|
|
$pluginManager = $this->prophesize(ComposerPluginManager::class); |
47
|
|
|
$pluginManager->get('SomeMailPlugin') |
48
|
|
|
->willReturn($plugin->reveal()); |
49
|
|
|
|
50
|
|
|
$locator = $this->prophesize(ContainerInterface::class); |
51
|
|
|
$locator->get('Configuration')->willReturn( |
52
|
|
|
[ |
53
|
|
|
'mt_mail' => [ |
54
|
|
|
'renderer' => 'Some\Mail\Renderer', |
55
|
|
|
'composer_plugins' => [ |
56
|
|
|
'SomeMailPlugin', |
57
|
|
|
'SomeMailPlugin', |
58
|
|
|
], |
59
|
|
|
], |
60
|
|
|
] |
61
|
|
|
); |
62
|
|
|
$renderer = $this->prophesize(RendererInterface::class); |
63
|
|
|
$locator->get('Some\Mail\Renderer')->willReturn($renderer->reveal()); |
64
|
|
|
$locator->get(ComposerPluginManager::class)->willReturn($pluginManager->reveal()); |
65
|
|
|
|
66
|
|
|
$factory = new ComposerServiceFactory(); |
67
|
|
|
$service = $factory($locator->reveal()); |
68
|
|
|
$this->assertInstanceOf(Composer::class, $service); |
69
|
|
|
$this->assertEquals($renderer->reveal(), $service->getRenderer()); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|