1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yiisoft\Mailer\SwiftMailer\Tests; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
6
|
|
|
use Psr\Container\ContainerInterface; |
7
|
|
|
use Yiisoft\Di\Container; |
8
|
|
|
use Yiisoft\Mailer\MailerInterface; |
9
|
|
|
use Yiisoft\Mailer\SwiftMailer\Mailer; |
10
|
|
|
|
11
|
|
|
abstract class TestCase extends BaseTestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var ContainerInterface $container |
15
|
|
|
*/ |
16
|
|
|
private $container; |
17
|
|
|
|
18
|
|
|
protected function setUp(): void |
19
|
|
|
{ |
20
|
|
|
parent::setUp(); |
21
|
|
|
$config = require __DIR__ . '/config.php'; |
22
|
|
|
$this->container = new Container($config); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function tearDown(): void |
26
|
|
|
{ |
27
|
|
|
$this->container = null; |
28
|
|
|
parent::tearDown(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function get($id) |
32
|
|
|
{ |
33
|
|
|
return $this->container->get($id); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return Mailer mailer instance. |
38
|
|
|
*/ |
39
|
|
|
protected function getMailer(): Mailer |
40
|
|
|
{ |
41
|
|
|
return $this->get(MailerInterface::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Gets an inaccessible object property. |
46
|
|
|
* @param $object |
47
|
|
|
* @param $propertyName |
48
|
|
|
* @param bool $revoke whether to make property inaccessible after getting |
49
|
|
|
* @return mixed |
50
|
|
|
* @throws \ReflectionException |
51
|
|
|
*/ |
52
|
|
|
protected function getInaccessibleProperty($object, $propertyName, bool $revoke = true) |
53
|
|
|
{ |
54
|
|
|
$class = new \ReflectionClass($object); |
55
|
|
|
while (!$class->hasProperty($propertyName)) { |
56
|
|
|
$class = $class->getParentClass(); |
57
|
|
|
} |
58
|
|
|
$property = $class->getProperty($propertyName); |
59
|
|
|
$property->setAccessible(true); |
60
|
|
|
$result = $property->getValue($object); |
61
|
|
|
if ($revoke) { |
62
|
|
|
$property->setAccessible(false); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $result; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|