Ajout des vendor

This commit is contained in:
2022-04-07 13:06:23 +02:00
parent ea47c93aa7
commit 5c116e15b1
1348 changed files with 184572 additions and 1 deletions

View File

@ -0,0 +1,191 @@
<?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 Symfony\Bundle\FrameworkBundle\Test;
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\LogicalAnd;
use PHPUnit\Framework\Constraint\LogicalNot;
use PHPUnit\Framework\ExpectationFailedException;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Test\Constraint as BrowserKitConstraint;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Test\Constraint as ResponseConstraint;
/**
* Ideas borrowed from Laravel Dusk's assertions.
*
* @see https://laravel.com/docs/5.7/dusk#available-assertions
*/
trait BrowserKitAssertionsTrait
{
public static function assertResponseIsSuccessful(string $message = ''): void
{
self::assertThatForResponse(new ResponseConstraint\ResponseIsSuccessful(), $message);
}
public static function assertResponseStatusCodeSame(int $expectedCode, string $message = ''): void
{
self::assertThatForResponse(new ResponseConstraint\ResponseStatusCodeSame($expectedCode), $message);
}
public static function assertResponseFormatSame(?string $expectedFormat, string $message = ''): void
{
self::assertThatForResponse(new ResponseConstraint\ResponseFormatSame(self::getRequest(), $expectedFormat), $message);
}
public static function assertResponseRedirects(string $expectedLocation = null, int $expectedCode = null, string $message = ''): void
{
$constraint = new ResponseConstraint\ResponseIsRedirected();
if ($expectedLocation) {
$constraint = LogicalAnd::fromConstraints($constraint, new ResponseConstraint\ResponseHeaderSame('Location', $expectedLocation));
}
if ($expectedCode) {
$constraint = LogicalAnd::fromConstraints($constraint, new ResponseConstraint\ResponseStatusCodeSame($expectedCode));
}
self::assertThatForResponse($constraint, $message);
}
public static function assertResponseHasHeader(string $headerName, string $message = ''): void
{
self::assertThatForResponse(new ResponseConstraint\ResponseHasHeader($headerName), $message);
}
public static function assertResponseNotHasHeader(string $headerName, string $message = ''): void
{
self::assertThatForResponse(new LogicalNot(new ResponseConstraint\ResponseHasHeader($headerName)), $message);
}
public static function assertResponseHeaderSame(string $headerName, string $expectedValue, string $message = ''): void
{
self::assertThatForResponse(new ResponseConstraint\ResponseHeaderSame($headerName, $expectedValue), $message);
}
public static function assertResponseHeaderNotSame(string $headerName, string $expectedValue, string $message = ''): void
{
self::assertThatForResponse(new LogicalNot(new ResponseConstraint\ResponseHeaderSame($headerName, $expectedValue)), $message);
}
public static function assertResponseHasCookie(string $name, string $path = '/', string $domain = null, string $message = ''): void
{
self::assertThatForResponse(new ResponseConstraint\ResponseHasCookie($name, $path, $domain), $message);
}
public static function assertResponseNotHasCookie(string $name, string $path = '/', string $domain = null, string $message = ''): void
{
self::assertThatForResponse(new LogicalNot(new ResponseConstraint\ResponseHasCookie($name, $path, $domain)), $message);
}
public static function assertResponseCookieValueSame(string $name, string $expectedValue, string $path = '/', string $domain = null, string $message = ''): void
{
self::assertThatForResponse(LogicalAnd::fromConstraints(
new ResponseConstraint\ResponseHasCookie($name, $path, $domain),
new ResponseConstraint\ResponseCookieValueSame($name, $expectedValue, $path, $domain)
), $message);
}
public static function assertResponseIsUnprocessable(string $message = ''): void
{
self::assertThatForResponse(new ResponseConstraint\ResponseIsUnprocessable(), $message);
}
public static function assertBrowserHasCookie(string $name, string $path = '/', string $domain = null, string $message = ''): void
{
self::assertThatForClient(new BrowserKitConstraint\BrowserHasCookie($name, $path, $domain), $message);
}
public static function assertBrowserNotHasCookie(string $name, string $path = '/', string $domain = null, string $message = ''): void
{
self::assertThatForClient(new LogicalNot(new BrowserKitConstraint\BrowserHasCookie($name, $path, $domain)), $message);
}
public static function assertBrowserCookieValueSame(string $name, string $expectedValue, bool $raw = false, string $path = '/', string $domain = null, string $message = ''): void
{
self::assertThatForClient(LogicalAnd::fromConstraints(
new BrowserKitConstraint\BrowserHasCookie($name, $path, $domain),
new BrowserKitConstraint\BrowserCookieValueSame($name, $expectedValue, $raw, $path, $domain)
), $message);
}
public static function assertRequestAttributeValueSame(string $name, string $expectedValue, string $message = ''): void
{
self::assertThat(self::getRequest(), new ResponseConstraint\RequestAttributeValueSame($name, $expectedValue), $message);
}
public static function assertRouteSame(string $expectedRoute, array $parameters = [], string $message = ''): void
{
$constraint = new ResponseConstraint\RequestAttributeValueSame('_route', $expectedRoute);
$constraints = [];
foreach ($parameters as $key => $value) {
$constraints[] = new ResponseConstraint\RequestAttributeValueSame($key, $value);
}
if ($constraints) {
$constraint = LogicalAnd::fromConstraints($constraint, ...$constraints);
}
self::assertThat(self::getRequest(), $constraint, $message);
}
public static function assertThatForResponse(Constraint $constraint, string $message = ''): void
{
try {
self::assertThat(self::getResponse(), $constraint, $message);
} catch (ExpectationFailedException $exception) {
if (($serverExceptionMessage = self::getResponse()->headers->get('X-Debug-Exception'))
&& ($serverExceptionFile = self::getResponse()->headers->get('X-Debug-Exception-File'))) {
$serverExceptionFile = explode(':', $serverExceptionFile);
$exception->__construct($exception->getMessage(), $exception->getComparisonFailure(), new \ErrorException(rawurldecode($serverExceptionMessage), 0, 1, rawurldecode($serverExceptionFile[0]), $serverExceptionFile[1]), $exception->getPrevious());
}
throw $exception;
}
}
public static function assertThatForClient(Constraint $constraint, string $message = ''): void
{
self::assertThat(self::getClient(), $constraint, $message);
}
private static function getClient(AbstractBrowser $newClient = null): ?AbstractBrowser
{
static $client;
if (0 < \func_num_args()) {
return $client = $newClient;
}
if (!$client instanceof AbstractBrowser) {
static::fail(sprintf('A client must be set to make assertions on it. Did you forget to call "%s::createClient()"?', __CLASS__));
}
return $client;
}
private static function getResponse(): Response
{
if (!$response = self::getClient()->getResponse()) {
static::fail('A client must have an HTTP Response to make assertions. Did you forget to make an HTTP request?');
}
return $response;
}
private static function getRequest(): Request
{
if (!$request = self::getClient()->getRequest()) {
static::fail('A client must have an HTTP Request to make assertions. Did you forget to make an HTTP request?');
}
return $request;
}
}

View File

@ -0,0 +1,129 @@
<?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 Symfony\Bundle\FrameworkBundle\Test;
use PHPUnit\Framework\Constraint\LogicalAnd;
use PHPUnit\Framework\Constraint\LogicalNot;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\DomCrawler\Test\Constraint as DomCrawlerConstraint;
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorAttributeValueSame;
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorExists;
/**
* Ideas borrowed from Laravel Dusk's assertions.
*
* @see https://laravel.com/docs/5.7/dusk#available-assertions
*/
trait DomCrawlerAssertionsTrait
{
public static function assertSelectorExists(string $selector, string $message = ''): void
{
self::assertThat(self::getCrawler(), new DomCrawlerConstraint\CrawlerSelectorExists($selector), $message);
}
public static function assertSelectorNotExists(string $selector, string $message = ''): void
{
self::assertThat(self::getCrawler(), new LogicalNot(new DomCrawlerConstraint\CrawlerSelectorExists($selector)), $message);
}
public static function assertSelectorTextContains(string $selector, string $text, string $message = ''): void
{
self::assertThat(self::getCrawler(), LogicalAnd::fromConstraints(
new DomCrawlerConstraint\CrawlerSelectorExists($selector),
new DomCrawlerConstraint\CrawlerSelectorTextContains($selector, $text)
), $message);
}
public static function assertSelectorTextSame(string $selector, string $text, string $message = ''): void
{
self::assertThat(self::getCrawler(), LogicalAnd::fromConstraints(
new DomCrawlerConstraint\CrawlerSelectorExists($selector),
new DomCrawlerConstraint\CrawlerSelectorTextSame($selector, $text)
), $message);
}
public static function assertSelectorTextNotContains(string $selector, string $text, string $message = ''): void
{
self::assertThat(self::getCrawler(), LogicalAnd::fromConstraints(
new DomCrawlerConstraint\CrawlerSelectorExists($selector),
new LogicalNot(new DomCrawlerConstraint\CrawlerSelectorTextContains($selector, $text))
), $message);
}
public static function assertPageTitleSame(string $expectedTitle, string $message = ''): void
{
self::assertSelectorTextSame('title', $expectedTitle, $message);
}
public static function assertPageTitleContains(string $expectedTitle, string $message = ''): void
{
self::assertSelectorTextContains('title', $expectedTitle, $message);
}
public static function assertInputValueSame(string $fieldName, string $expectedValue, string $message = ''): void
{
self::assertThat(self::getCrawler(), LogicalAnd::fromConstraints(
new DomCrawlerConstraint\CrawlerSelectorExists("input[name=\"$fieldName\"]"),
new DomCrawlerConstraint\CrawlerSelectorAttributeValueSame("input[name=\"$fieldName\"]", 'value', $expectedValue)
), $message);
}
public static function assertInputValueNotSame(string $fieldName, string $expectedValue, string $message = ''): void
{
self::assertThat(self::getCrawler(), LogicalAnd::fromConstraints(
new DomCrawlerConstraint\CrawlerSelectorExists("input[name=\"$fieldName\"]"),
new LogicalNot(new DomCrawlerConstraint\CrawlerSelectorAttributeValueSame("input[name=\"$fieldName\"]", 'value', $expectedValue))
), $message);
}
public static function assertCheckboxChecked(string $fieldName, string $message = ''): void
{
self::assertThat(self::getCrawler(), LogicalAnd::fromConstraints(
new CrawlerSelectorExists("input[name=\"$fieldName\"]"),
new CrawlerSelectorAttributeValueSame("input[name=\"$fieldName\"]", 'checked', 'checked')
), $message);
}
public static function assertCheckboxNotChecked(string $fieldName, string $message = ''): void
{
self::assertThat(self::getCrawler(), LogicalAnd::fromConstraints(
new CrawlerSelectorExists("input[name=\"$fieldName\"]"),
new LogicalNot(new CrawlerSelectorAttributeValueSame("input[name=\"$fieldName\"]", 'checked', 'checked'))
), $message);
}
public static function assertFormValue(string $formSelector, string $fieldName, string $value, string $message = ''): void
{
$node = self::getCrawler()->filter($formSelector);
self::assertNotEmpty($node, sprintf('Form "%s" not found.', $formSelector));
$values = $node->form()->getValues();
self::assertArrayHasKey($fieldName, $values, $message ?: sprintf('Field "%s" not found in form "%s".', $fieldName, $formSelector));
self::assertSame($value, $values[$fieldName]);
}
public static function assertNoFormValue(string $formSelector, string $fieldName, string $message = ''): void
{
$node = self::getCrawler()->filter($formSelector);
self::assertNotEmpty($node, sprintf('Form "%s" not found.', $formSelector));
$values = $node->form()->getValues();
self::assertArrayNotHasKey($fieldName, $values, $message ?: sprintf('Field "%s" has a value in form "%s".', $fieldName, $formSelector));
}
private static function getCrawler(): Crawler
{
if (!$crawler = self::getClient()->getCrawler()) {
static::fail('A client must have a crawler to make assertions. Did you forget to make an HTTP request?');
}
return $crawler;
}
}

View File

@ -0,0 +1,170 @@
<?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 Symfony\Bundle\FrameworkBundle\Test;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Contracts\Service\ResetInterface;
/**
* KernelTestCase is the base class for tests needing a Kernel.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
abstract class KernelTestCase extends TestCase
{
use MailerAssertionsTrait;
protected static $class;
/**
* @var KernelInterface
*/
protected static $kernel;
/**
* @var ContainerInterface
*
* @deprecated since Symfony 5.3, use static::getContainer() instead
*/
protected static $container;
protected static $booted = false;
protected function tearDown(): void
{
static::ensureKernelShutdown();
static::$class = null;
static::$kernel = null;
static::$booted = false;
}
/**
* @return string
*
* @throws \RuntimeException
* @throws \LogicException
*/
protected static function getKernelClass()
{
if (!isset($_SERVER['KERNEL_CLASS']) && !isset($_ENV['KERNEL_CLASS'])) {
throw new \LogicException(sprintf('You must set the KERNEL_CLASS environment variable to the fully-qualified class name of your Kernel in phpunit.xml / phpunit.xml.dist or override the "%1$s::createKernel()" or "%1$s::getKernelClass()" method.', static::class));
}
if (!class_exists($class = $_ENV['KERNEL_CLASS'] ?? $_SERVER['KERNEL_CLASS'])) {
throw new \RuntimeException(sprintf('Class "%s" doesn\'t exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the "%s::createKernel()" method.', $class, static::class));
}
return $class;
}
/**
* Boots the Kernel for this test.
*
* @return KernelInterface
*/
protected static function bootKernel(array $options = [])
{
static::ensureKernelShutdown();
$kernel = static::createKernel($options);
$kernel->boot();
self::$kernel = $kernel;
static::$booted = true;
$container = static::$kernel->getContainer();
static::$container = $container->has('test.service_container') ? $container->get('test.service_container') : $container;
return static::$kernel;
}
/**
* Provides a dedicated test container with access to both public and private
* services. The container will not include private services that have been
* inlined or removed. Private services will be removed when they are not
* used by other services.
*
* Using this method is the best way to get a container from your test code.
*/
protected static function getContainer(): ContainerInterface
{
if (!static::$booted) {
static::bootKernel();
}
try {
return self::$kernel->getContainer()->get('test.service_container');
} catch (ServiceNotFoundException $e) {
throw new \LogicException('Could not find service "test.service_container". Try updating the "framework.test" config to "true".', 0, $e);
}
}
/**
* Creates a Kernel.
*
* Available options:
*
* * environment
* * debug
*
* @return KernelInterface
*/
protected static function createKernel(array $options = [])
{
if (null === static::$class) {
static::$class = static::getKernelClass();
}
if (isset($options['environment'])) {
$env = $options['environment'];
} elseif (isset($_ENV['APP_ENV'])) {
$env = $_ENV['APP_ENV'];
} elseif (isset($_SERVER['APP_ENV'])) {
$env = $_SERVER['APP_ENV'];
} else {
$env = 'test';
}
if (isset($options['debug'])) {
$debug = $options['debug'];
} elseif (isset($_ENV['APP_DEBUG'])) {
$debug = $_ENV['APP_DEBUG'];
} elseif (isset($_SERVER['APP_DEBUG'])) {
$debug = $_SERVER['APP_DEBUG'];
} else {
$debug = true;
}
return new static::$class($env, $debug);
}
/**
* Shuts the kernel down if it was used in the test - called by the tearDown method by default.
*/
protected static function ensureKernelShutdown()
{
if (null !== static::$kernel) {
static::$kernel->boot();
$container = static::$kernel->getContainer();
static::$kernel->shutdown();
static::$booted = false;
if ($container instanceof ResetInterface) {
$container->reset();
}
}
static::$container = null;
}
}

View File

@ -0,0 +1,132 @@
<?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 Symfony\Bundle\FrameworkBundle\Test;
use PHPUnit\Framework\Constraint\LogicalNot;
use Symfony\Component\Mailer\Event\MessageEvent;
use Symfony\Component\Mailer\Event\MessageEvents;
use Symfony\Component\Mailer\Test\Constraint as MailerConstraint;
use Symfony\Component\Mime\RawMessage;
use Symfony\Component\Mime\Test\Constraint as MimeConstraint;
trait MailerAssertionsTrait
{
public static function assertEmailCount(int $count, string $transport = null, string $message = ''): void
{
self::assertThat(self::getMessageMailerEvents(), new MailerConstraint\EmailCount($count, $transport), $message);
}
public static function assertQueuedEmailCount(int $count, string $transport = null, string $message = ''): void
{
self::assertThat(self::getMessageMailerEvents(), new MailerConstraint\EmailCount($count, $transport, true), $message);
}
public static function assertEmailIsQueued(MessageEvent $event, string $message = ''): void
{
self::assertThat($event, new MailerConstraint\EmailIsQueued(), $message);
}
public static function assertEmailIsNotQueued(MessageEvent $event, string $message = ''): void
{
self::assertThat($event, new LogicalNot(new MailerConstraint\EmailIsQueued()), $message);
}
public static function assertEmailAttachmentCount(RawMessage $email, int $count, string $message = ''): void
{
self::assertThat($email, new MimeConstraint\EmailAttachmentCount($count), $message);
}
public static function assertEmailTextBodyContains(RawMessage $email, string $text, string $message = ''): void
{
self::assertThat($email, new MimeConstraint\EmailTextBodyContains($text), $message);
}
public static function assertEmailTextBodyNotContains(RawMessage $email, string $text, string $message = ''): void
{
self::assertThat($email, new LogicalNot(new MimeConstraint\EmailTextBodyContains($text)), $message);
}
public static function assertEmailHtmlBodyContains(RawMessage $email, string $text, string $message = ''): void
{
self::assertThat($email, new MimeConstraint\EmailHtmlBodyContains($text), $message);
}
public static function assertEmailHtmlBodyNotContains(RawMessage $email, string $text, string $message = ''): void
{
self::assertThat($email, new LogicalNot(new MimeConstraint\EmailHtmlBodyContains($text)), $message);
}
public static function assertEmailHasHeader(RawMessage $email, string $headerName, string $message = ''): void
{
self::assertThat($email, new MimeConstraint\EmailHasHeader($headerName), $message);
}
public static function assertEmailNotHasHeader(RawMessage $email, string $headerName, string $message = ''): void
{
self::assertThat($email, new LogicalNot(new MimeConstraint\EmailHasHeader($headerName)), $message);
}
public static function assertEmailHeaderSame(RawMessage $email, string $headerName, string $expectedValue, string $message = ''): void
{
self::assertThat($email, new MimeConstraint\EmailHeaderSame($headerName, $expectedValue), $message);
}
public static function assertEmailHeaderNotSame(RawMessage $email, string $headerName, string $expectedValue, string $message = ''): void
{
self::assertThat($email, new LogicalNot(new MimeConstraint\EmailHeaderSame($headerName, $expectedValue)), $message);
}
public static function assertEmailAddressContains(RawMessage $email, string $headerName, string $expectedValue, string $message = ''): void
{
self::assertThat($email, new MimeConstraint\EmailAddressContains($headerName, $expectedValue), $message);
}
/**
* @return MessageEvents[]
*/
public static function getMailerEvents(string $transport = null): array
{
return self::getMessageMailerEvents()->getEvents($transport);
}
public static function getMailerEvent(int $index = 0, string $transport = null): ?MessageEvent
{
return self::getMailerEvents($transport)[$index] ?? null;
}
/**
* @return RawMessage[]
*/
public static function getMailerMessages(string $transport = null): array
{
return self::getMessageMailerEvents()->getMessages($transport);
}
public static function getMailerMessage(int $index = 0, string $transport = null): ?RawMessage
{
return self::getMailerMessages($transport)[$index] ?? null;
}
private static function getMessageMailerEvents(): MessageEvents
{
$container = static::getContainer();
if ($container->has('mailer.message_logger_listener')) {
return $container->get('mailer.message_logger_listener')->getEvents();
}
if ($container->has('mailer.logger_message_listener')) {
return $container->get('mailer.logger_message_listener')->getEvents();
}
static::fail('A client must have Mailer enabled to make email assertions. Did you forget to require symfony/mailer?');
}
}

View File

@ -0,0 +1,58 @@
<?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 Symfony\Bundle\FrameworkBundle\Test;
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* A very limited token that is used to login in tests using the KernelBrowser.
*
* @author Wouter de Jong <wouter@wouterj.nl>
*/
class TestBrowserToken extends AbstractToken
{
private $firewallName;
public function __construct(array $roles = [], UserInterface $user = null, string $firewallName = 'main')
{
parent::__construct($roles);
if (null !== $user) {
$this->setUser($user);
}
$this->firewallName = $firewallName;
}
public function getFirewallName(): string
{
return $this->firewallName;
}
public function getCredentials()
{
return null;
}
public function __serialize(): array
{
return [$this->firewallName, parent::__serialize()];
}
public function __unserialize(array $data): void
{
[$this->firewallName, $parentData] = $data;
parent::__unserialize($parentData);
}
}

View File

@ -0,0 +1,159 @@
<?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 Symfony\Bundle\FrameworkBundle\Test;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* A special container used in tests. This gives access to both public and
* private services. The container will not include private services that has
* been inlined or removed. Private services will be removed when they are not
* used by other services.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
class TestContainer extends Container
{
private $kernel;
private $privateServicesLocatorId;
public function __construct(KernelInterface $kernel, string $privateServicesLocatorId)
{
$this->kernel = $kernel;
$this->privateServicesLocatorId = $privateServicesLocatorId;
}
/**
* {@inheritdoc}
*/
public function compile()
{
$this->getPublicContainer()->compile();
}
/**
* {@inheritdoc}
*/
public function isCompiled(): bool
{
return $this->getPublicContainer()->isCompiled();
}
/**
* {@inheritdoc}
*/
public function getParameterBag(): ParameterBagInterface
{
return $this->getPublicContainer()->getParameterBag();
}
/**
* {@inheritdoc}
*
* @return array|bool|float|int|string|\UnitEnum|null
*/
public function getParameter(string $name)
{
return $this->getPublicContainer()->getParameter($name);
}
/**
* {@inheritdoc}
*/
public function hasParameter(string $name): bool
{
return $this->getPublicContainer()->hasParameter($name);
}
/**
* {@inheritdoc}
*/
public function setParameter(string $name, $value)
{
$this->getPublicContainer()->setParameter($name, $value);
}
/**
* {@inheritdoc}
*/
public function set(string $id, $service)
{
$this->getPublicContainer()->set($id, $service);
}
/**
* {@inheritdoc}
*/
public function has(string $id): bool
{
return $this->getPublicContainer()->has($id) || $this->getPrivateContainer()->has($id);
}
/**
* {@inheritdoc}
*/
public function get(string $id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1): ?object
{
return $this->getPrivateContainer()->has($id) ? $this->getPrivateContainer()->get($id) : $this->getPublicContainer()->get($id, $invalidBehavior);
}
/**
* {@inheritdoc}
*/
public function initialized(string $id): bool
{
return $this->getPublicContainer()->initialized($id);
}
/**
* {@inheritdoc}
*/
public function reset()
{
// ignore the call
}
/**
* {@inheritdoc}
*/
public function getServiceIds(): array
{
return $this->getPublicContainer()->getServiceIds();
}
/**
* {@inheritdoc}
*/
public function getRemovedIds(): array
{
return $this->getPublicContainer()->getRemovedIds();
}
private function getPublicContainer(): Container
{
if (null === $container = $this->kernel->getContainer()) {
throw new \LogicException('Cannot access the container on a non-booted kernel. Did you forget to boot it?');
}
return $container;
}
private function getPrivateContainer(): ContainerInterface
{
return $this->getPublicContainer()->get($this->privateServicesLocatorId);
}
}

View File

@ -0,0 +1,18 @@
<?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 Symfony\Bundle\FrameworkBundle\Test;
trait WebTestAssertionsTrait
{
use BrowserKitAssertionsTrait;
use DomCrawlerAssertionsTrait;
}

View File

@ -0,0 +1,61 @@
<?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 Symfony\Bundle\FrameworkBundle\Test;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
/**
* WebTestCase is the base class for functional tests.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
abstract class WebTestCase extends KernelTestCase
{
use WebTestAssertionsTrait;
protected function tearDown(): void
{
parent::tearDown();
self::getClient(null);
}
/**
* Creates a KernelBrowser.
*
* @param array $options An array of options to pass to the createKernel method
* @param array $server An array of server parameters
*
* @return KernelBrowser
*/
protected static function createClient(array $options = [], array $server = [])
{
if (static::$booted) {
throw new \LogicException(sprintf('Booting the kernel before calling "%s()" is not supported, the kernel should only be booted once.', __METHOD__));
}
$kernel = static::bootKernel($options);
try {
$client = $kernel->getContainer()->get('test.client');
} catch (ServiceNotFoundException $e) {
if (class_exists(KernelBrowser::class)) {
throw new \LogicException('You cannot create the client used in functional tests if the "framework.test" config is not set to true.');
}
throw new \LogicException('You cannot create the client used in functional tests if the BrowserKit component is not available. Try running "composer require symfony/browser-kit".');
}
$client->setServerParameters($server);
return self::getClient($client);
}
}