Вход Регистрация
Файл: vendor/symfony/mailer/Test/TransportFactoryTestCase.php
Строк: 157
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyComponentMailerTest;

use 
PHPUnitFrameworkTestCase;
use 
PsrLogLoggerInterface;
use 
SymfonyComponentMailerExceptionIncompleteDsnException;
use 
SymfonyComponentMailerExceptionUnsupportedSchemeException;
use 
SymfonyComponentMailerTransportDsn;
use 
SymfonyComponentMailerTransportTransportFactoryInterface;
use 
SymfonyComponentMailerTransportTransportInterface;
use 
SymfonyContractsEventDispatcherEventDispatcherInterface;
use 
SymfonyContractsHttpClientHttpClientInterface;

/**
 * A test case to ease testing Transport Factory.
 *
 * @author Konstantin Myakshin <molodchick@gmail.com>
 */
abstract class TransportFactoryTestCase extends TestCase
{
    protected const 
USER 'u$er';
    protected const 
PASSWORD 'pa$s';

    protected 
$dispatcher;
    protected 
$client;
    protected 
$logger;

    abstract public function 
getFactory(): TransportFactoryInterface;

    abstract public function 
supportsProvider(): iterable;

    abstract public function 
createProvider(): iterable;

    public function 
unsupportedSchemeProvider(): iterable
    
{
        return [];
    }

    public function 
incompleteDsnProvider(): iterable
    
{
        return [];
    }

    
/**
     * @dataProvider supportsProvider
     */
    
public function testSupports(Dsn $dsnbool $supports)
    {
        
$factory $this->getFactory();

        
$this->assertSame($supports$factory->supports($dsn));
    }

    
/**
     * @dataProvider createProvider
     */
    
public function testCreate(Dsn $dsnTransportInterface $transport)
    {
        
$factory $this->getFactory();

        
$this->assertEquals($transport$factory->create($dsn));
        if (
str_contains('smtp'$dsn->getScheme())) {
            
$this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', (string) $transport);
        }
    }

    
/**
     * @dataProvider unsupportedSchemeProvider
     */
    
public function testUnsupportedSchemeException(Dsn $dsnstring $message null)
    {
        
$factory $this->getFactory();

        
$this->expectException(UnsupportedSchemeException::class);
        if (
null !== $message) {
            
$this->expectExceptionMessage($message);
        }

        
$factory->create($dsn);
    }

    
/**
     * @dataProvider incompleteDsnProvider
     */
    
public function testIncompleteDsnException(Dsn $dsn)
    {
        
$factory $this->getFactory();

        
$this->expectException(IncompleteDsnException::class);
        
$factory->create($dsn);
    }

    protected function 
getDispatcher(): EventDispatcherInterface
    
{
        return 
$this->dispatcher ?? $this->dispatcher $this->createMock(EventDispatcherInterface::class);
    }

    protected function 
getClient(): HttpClientInterface
    
{
        return 
$this->client ?? $this->client $this->createMock(HttpClientInterface::class);
    }

    protected function 
getLogger(): LoggerInterface
    
{
        return 
$this->logger ?? $this->logger $this->createMock(LoggerInterface::class);
    }
}
Онлайн: 0
Реклама