1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace FH\Bundle\MailerBundle\Tests\DependencyInjection; |
6
|
|
|
|
7
|
|
|
use FH\Bundle\MailerBundle\Composer\EmailComposer; |
8
|
|
|
use FH\Bundle\MailerBundle\Composer\TemplatedEmailComposer; |
9
|
|
|
use FH\Bundle\MailerBundle\DependencyInjection\FHMailerExtension; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
12
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers \FH\Bundle\MailerBundle\DependencyInjection\FHMailerExtension |
16
|
|
|
*/ |
17
|
|
|
final class FHMailerExtensionTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** @var ContainerBuilder */ |
20
|
|
|
private $container; |
21
|
|
|
|
22
|
|
|
/** @var FHMailerExtension */ |
23
|
|
|
private $extension; |
24
|
|
|
|
25
|
|
|
protected function setUp(): void |
26
|
|
|
{ |
27
|
|
|
$this->container = new ContainerBuilder(); |
28
|
|
|
$this->extension = new FHMailerExtension(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testExtensionLoaded(): void |
32
|
|
|
{ |
33
|
|
|
$this->extension->load([], $this->container); |
34
|
|
|
|
35
|
|
|
$this->assertContains(EmailComposer::class, $this->container->getServiceIds()); |
36
|
|
|
$this->assertContains(TemplatedEmailComposer::class, $this->container->getServiceIds()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testConfiguredTagsDefined(): void |
40
|
|
|
{ |
41
|
|
|
$this->extension->load($this->getTestConfig(), $this->container); |
42
|
|
|
|
43
|
|
|
try { |
44
|
|
|
$templatedEmailDefinition = $this->container->findDefinition('fh_mailer.composer.templated_email.to_ms_test'); |
45
|
|
|
$templatedEmailDefinition->setPublic(true); |
46
|
|
|
|
47
|
|
|
$emailDefinition = $this->container->findDefinition('fh_mailer.composer.email.to_ms_test'); |
48
|
|
|
$emailDefinition->setPublic(true); |
49
|
|
|
|
50
|
|
|
$this->container->compile(); |
51
|
|
|
|
52
|
|
|
$templatedEmailService = $this->container->get('fh_mailer.composer.templated_email.to_ms_test'); |
53
|
|
|
$emailService = $this->container->get('fh_mailer.composer.email.to_ms_test'); |
54
|
|
|
} catch (ServiceNotFoundException $exception) { |
55
|
|
|
$this->fail("Service 'fh_mailer.composer.templated_email.to_ms_test' is not defined"); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->assertCount(0, $templatedEmailDefinition->getErrors()); |
59
|
|
|
$this->assertInstanceOf(TemplatedEmailComposer::class, $templatedEmailService); |
60
|
|
|
|
61
|
|
|
$this->assertCount(0, $emailDefinition->getErrors()); |
62
|
|
|
$this->assertInstanceOf(EmailComposer::class, $emailService); |
63
|
|
|
|
64
|
|
|
$this->assertSame( |
65
|
|
|
(string) $templatedEmailDefinition->getArgument('$messageOptions'), |
66
|
|
|
'fh_mailer.composer.templated_email.to_ms_test._message_options' |
67
|
|
|
); |
68
|
|
|
$this->assertSame( |
69
|
|
|
(string) $emailDefinition->getArgument('$messageOptions'), |
70
|
|
|
'fh_mailer.composer.email.to_ms_test._message_options' |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function getTestConfig(): array |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
|
|
'fh_mailer' => [ |
78
|
|
|
'templated_email' => [ |
79
|
|
|
'to_ms_test' => [ |
80
|
|
|
'html_template' => 'test.html.twig', |
81
|
|
|
'subject' => 'Test email', |
82
|
|
|
'participants' => [ |
83
|
|
|
'from' => [ |
84
|
|
|
[ |
85
|
|
|
'name' => 'Mr. Test', |
86
|
|
|
'address' => '[email protected]', |
87
|
|
|
], |
88
|
|
|
], |
89
|
|
|
'to' => [ |
90
|
|
|
[ |
91
|
|
|
'name' => 'Ms. Test', |
92
|
|
|
'address' => '[email protected]', |
93
|
|
|
], |
94
|
|
|
], |
95
|
|
|
], |
96
|
|
|
], |
97
|
|
|
], |
98
|
|
|
'email' => [ |
99
|
|
|
'to_ms_test' => [ |
100
|
|
|
'subject' => 'Test email', |
101
|
|
|
'participants' => [ |
102
|
|
|
'from' => [ |
103
|
|
|
[ |
104
|
|
|
'name' => 'Mr. Test', |
105
|
|
|
'address' => '[email protected]', |
106
|
|
|
], |
107
|
|
|
], |
108
|
|
|
'to' => [ |
109
|
|
|
[ |
110
|
|
|
'name' => 'Ms. Test', |
111
|
|
|
'address' => '[email protected]', |
112
|
|
|
], |
113
|
|
|
], |
114
|
|
|
], |
115
|
|
|
], |
116
|
|
|
], |
117
|
|
|
], |
118
|
|
|
]; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths