Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Mailer\Test;
13
 
14
use PHPUnit\Framework\TestCase;
15
use Psr\Log\LoggerInterface;
16
use Symfony\Component\Mailer\Exception\IncompleteDsnException;
17
use Symfony\Component\Mailer\Exception\UnsupportedSchemeException;
18
use Symfony\Component\Mailer\Transport\Dsn;
19
use Symfony\Component\Mailer\Transport\TransportFactoryInterface;
20
use Symfony\Component\Mailer\Transport\TransportInterface;
21
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
22
use Symfony\Contracts\HttpClient\HttpClientInterface;
23
 
24
/**
25
 * A test case to ease testing Transport Factory.
26
 *
27
 * @author Konstantin Myakshin <molodchick@gmail.com>
28
 */
29
abstract class TransportFactoryTestCase extends TestCase
30
{
31
    protected const USER = 'u$er';
32
    protected const PASSWORD = 'pa$s';
33
 
34
    protected $dispatcher;
35
    protected $client;
36
    protected $logger;
37
 
38
    abstract public function getFactory(): TransportFactoryInterface;
39
 
688 lars 40
    abstract public static function supportsProvider(): iterable;
148 lars 41
 
688 lars 42
    abstract public static function createProvider(): iterable;
148 lars 43
 
688 lars 44
    public static function unsupportedSchemeProvider(): iterable
148 lars 45
    {
46
        return [];
47
    }
48
 
688 lars 49
    public static function incompleteDsnProvider(): iterable
148 lars 50
    {
51
        return [];
52
    }
53
 
54
    /**
55
     * @dataProvider supportsProvider
56
     */
57
    public function testSupports(Dsn $dsn, bool $supports)
58
    {
59
        $factory = $this->getFactory();
60
 
61
        $this->assertSame($supports, $factory->supports($dsn));
62
    }
63
 
64
    /**
65
     * @dataProvider createProvider
66
     */
67
    public function testCreate(Dsn $dsn, TransportInterface $transport)
68
    {
69
        $factory = $this->getFactory();
70
 
71
        $this->assertEquals($transport, $factory->create($dsn));
72
        if (str_contains('smtp', $dsn->getScheme())) {
73
            $this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', (string) $transport);
74
        }
75
    }
76
 
77
    /**
78
     * @dataProvider unsupportedSchemeProvider
79
     */
80
    public function testUnsupportedSchemeException(Dsn $dsn, string $message = null)
81
    {
82
        $factory = $this->getFactory();
83
 
84
        $this->expectException(UnsupportedSchemeException::class);
85
        if (null !== $message) {
86
            $this->expectExceptionMessage($message);
87
        }
88
 
89
        $factory->create($dsn);
90
    }
91
 
92
    /**
93
     * @dataProvider incompleteDsnProvider
94
     */
95
    public function testIncompleteDsnException(Dsn $dsn)
96
    {
97
        $factory = $this->getFactory();
98
 
99
        $this->expectException(IncompleteDsnException::class);
100
        $factory->create($dsn);
101
    }
102
 
103
    protected function getDispatcher(): EventDispatcherInterface
104
    {
105
        return $this->dispatcher ??= $this->createMock(EventDispatcherInterface::class);
106
    }
107
 
108
    protected function getClient(): HttpClientInterface
109
    {
110
        return $this->client ??= $this->createMock(HttpClientInterface::class);
111
    }
112
 
113
    protected function getLogger(): LoggerInterface
114
    {
115
        return $this->logger ??= $this->createMock(LoggerInterface::class);
116
    }
117
}