|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SfCod\EmailEngineBundle\Tests\Sender; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use SfCod\EmailEngineBundle\Example\TestEmailOptions; |
|
7
|
|
|
use SfCod\EmailEngineBundle\Example\TestEmailTemplate; |
|
8
|
|
|
use SfCod\EmailEngineBundle\Mailer\Mailer; |
|
9
|
|
|
use SfCod\EmailEngineBundle\Repository\TwigFileRepository; |
|
10
|
|
|
use SfCod\EmailEngineBundle\Sender\SwiftMailerSender; |
|
11
|
|
|
use SfCod\EmailEngineBundle\Template\Params\ParameterResolver; |
|
12
|
|
|
use SfCod\EmailEngineBundle\Tests\Data\LoadTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class SwiftMailerSenderTest |
|
16
|
|
|
* |
|
17
|
|
|
* @author Virchenko Maksim <[email protected]> |
|
18
|
|
|
* |
|
19
|
|
|
* @package SfCod\EmailEngineBundle\Tests\Sender |
|
20
|
|
|
*/ |
|
21
|
|
|
class SwiftMailerSenderTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
use LoadTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Test sending |
|
27
|
|
|
* |
|
28
|
|
|
* @throws \ReflectionException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testSend() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->configure(SwiftMailerSender::class, TwigFileRepository::class); |
|
33
|
|
|
|
|
34
|
|
|
$mailer = $this->container->get(Mailer::class); |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
$template = $this->mockTemplate(); |
|
37
|
|
|
$sender = $this->mockSender(); |
|
38
|
|
|
|
|
39
|
|
|
$result = $sender->send($template, '[email protected]'); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertTrue($result); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Mock sender |
|
46
|
|
|
* |
|
47
|
|
|
* @return SwiftMailerSender |
|
48
|
|
|
*/ |
|
49
|
|
|
private function mockSender(): SwiftMailerSender |
|
50
|
|
|
{ |
|
51
|
|
|
$sender = new SwiftMailerSender(new \Swift_Mailer(new \Swift_Transport_NullTransport(new \Swift_Events_SimpleEventDispatcher()))); |
|
52
|
|
|
|
|
53
|
|
|
return $sender; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Mock template |
|
58
|
|
|
* |
|
59
|
|
|
* @return TestEmailTemplate |
|
60
|
|
|
* |
|
61
|
|
|
* @throws \ReflectionException |
|
62
|
|
|
* @throws \SfCod\EmailEngineBundle\Exception\RepositoryUnavailableException |
|
63
|
|
|
*/ |
|
64
|
|
|
private function mockTemplate(): TestEmailTemplate |
|
65
|
|
|
{ |
|
66
|
|
|
$template = new TestEmailTemplate(new TestEmailOptions('message', 'filepath')); |
|
67
|
|
|
|
|
68
|
|
|
$filePath = (new \ReflectionClass(get_class($template)))->getFileName(); |
|
69
|
|
|
$directory = dirname($filePath); |
|
70
|
|
|
|
|
71
|
|
|
$repository = new TwigFileRepository(new \Twig_Environment(new \Twig_Loader_Chain([ |
|
72
|
|
|
new \Twig_Loader_Filesystem('Data', $directory), |
|
73
|
|
|
]))); |
|
74
|
|
|
$repository->connect($template); |
|
75
|
|
|
|
|
76
|
|
|
$template->setParameterResolver(new ParameterResolver($this->container)); |
|
|
|
|
|
|
77
|
|
|
$template->setRepository($repository); |
|
78
|
|
|
|
|
79
|
|
|
return $template; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.