first commit

This commit is contained in:
Sampanna Rimal
2024-08-27 17:48:06 +05:45
commit 53c0140f58
10839 changed files with 1125847 additions and 0 deletions

View File

@ -0,0 +1,48 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Request;
final class RequestAttributeValueSame extends Constraint
{
private string $name;
private string $value;
public function __construct(string $name, string $value)
{
$this->name = $name;
$this->value = $value;
}
public function toString(): string
{
return sprintf('has attribute "%s" with value "%s"', $this->name, $this->value);
}
/**
* @param Request $request
*/
protected function matches($request): bool
{
return $this->value === $request->attributes->get($this->name);
}
/**
* @param Request $request
*/
protected function failureDescription($request): string
{
return 'the Request '.$this->toString();
}
}

View File

@ -0,0 +1,76 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
final class ResponseCookieValueSame extends Constraint
{
private string $name;
private string $value;
private string $path;
private ?string $domain;
public function __construct(string $name, string $value, string $path = '/', ?string $domain = null)
{
$this->name = $name;
$this->value = $value;
$this->path = $path;
$this->domain = $domain;
}
public function toString(): string
{
$str = sprintf('has cookie "%s"', $this->name);
if ('/' !== $this->path) {
$str .= sprintf(' with path "%s"', $this->path);
}
if ($this->domain) {
$str .= sprintf(' for domain "%s"', $this->domain);
}
$str .= sprintf(' with value "%s"', $this->value);
return $str;
}
/**
* @param Response $response
*/
protected function matches($response): bool
{
$cookie = $this->getCookie($response);
if (!$cookie) {
return false;
}
return $this->value === (string) $cookie->getValue();
}
/**
* @param Response $response
*/
protected function failureDescription($response): string
{
return 'the Response '.$this->toString();
}
protected function getCookie(Response $response): ?Cookie
{
$cookies = $response->headers->getCookies();
$filteredCookies = array_filter($cookies, fn (Cookie $cookie) => $cookie->getName() === $this->name && $cookie->getPath() === $this->path && $cookie->getDomain() === $this->domain);
return reset($filteredCookies) ?: null;
}
}

View File

@ -0,0 +1,62 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Asserts that the response is in the given format.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class ResponseFormatSame extends Constraint
{
private Request $request;
private ?string $format;
public function __construct(Request $request, ?string $format)
{
$this->request = $request;
$this->format = $format;
}
public function toString(): string
{
return 'format is '.($this->format ?? 'null');
}
/**
* @param Response $response
*/
protected function matches($response): bool
{
return $this->format === $this->request->getFormat($response->headers->get('Content-Type'));
}
/**
* @param Response $response
*/
protected function failureDescription($response): string
{
return 'the Response '.$this->toString();
}
/**
* @param Response $response
*/
protected function additionalFailureDescription($response): string
{
return (string) $response;
}
}

View File

@ -0,0 +1,68 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
final class ResponseHasCookie extends Constraint
{
private string $name;
private string $path;
private ?string $domain;
public function __construct(string $name, string $path = '/', ?string $domain = null)
{
$this->name = $name;
$this->path = $path;
$this->domain = $domain;
}
public function toString(): string
{
$str = sprintf('has cookie "%s"', $this->name);
if ('/' !== $this->path) {
$str .= sprintf(' with path "%s"', $this->path);
}
if ($this->domain) {
$str .= sprintf(' for domain "%s"', $this->domain);
}
return $str;
}
/**
* @param Response $response
*/
protected function matches($response): bool
{
return null !== $this->getCookie($response);
}
/**
* @param Response $response
*/
protected function failureDescription($response): string
{
return 'the Response '.$this->toString();
}
private function getCookie(Response $response): ?Cookie
{
$cookies = $response->headers->getCookies();
$filteredCookies = array_filter($cookies, fn (Cookie $cookie) => $cookie->getName() === $this->name && $cookie->getPath() === $this->path && $cookie->getDomain() === $this->domain);
return reset($filteredCookies) ?: null;
}
}

View File

@ -0,0 +1,46 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Response;
final class ResponseHasHeader extends Constraint
{
private string $headerName;
public function __construct(string $headerName)
{
$this->headerName = $headerName;
}
public function toString(): string
{
return sprintf('has header "%s"', $this->headerName);
}
/**
* @param Response $response
*/
protected function matches($response): bool
{
return $response->headers->has($this->headerName);
}
/**
* @param Response $response
*/
protected function failureDescription($response): string
{
return 'the Response '.$this->toString();
}
}

View File

@ -0,0 +1,65 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class ResponseHeaderLocationSame extends Constraint
{
public function __construct(private Request $request, private string $expectedValue)
{
}
public function toString(): string
{
return sprintf('has header "Location" matching "%s"', $this->expectedValue);
}
protected function matches($other): bool
{
if (!$other instanceof Response) {
return false;
}
$location = $other->headers->get('Location');
if (null === $location) {
return false;
}
return $this->toFullUrl($this->expectedValue) === $this->toFullUrl($location);
}
protected function failureDescription($other): string
{
return 'the Response '.$this->toString();
}
private function toFullUrl(string $url): string
{
if (null === parse_url($url, \PHP_URL_PATH)) {
$url .= '/';
}
if (str_starts_with($url, '//')) {
return sprintf('%s:%s', $this->request->getScheme(), $url);
}
if (str_starts_with($url, '/')) {
return $this->request->getSchemeAndHttpHost().$url;
}
return $url;
}
}

View File

@ -0,0 +1,48 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Response;
final class ResponseHeaderSame extends Constraint
{
private string $headerName;
private string $expectedValue;
public function __construct(string $headerName, string $expectedValue)
{
$this->headerName = $headerName;
$this->expectedValue = $expectedValue;
}
public function toString(): string
{
return sprintf('has header "%s" with value "%s"', $this->headerName, $this->expectedValue);
}
/**
* @param Response $response
*/
protected function matches($response): bool
{
return $this->expectedValue === $response->headers->get($this->headerName, null);
}
/**
* @param Response $response
*/
protected function failureDescription($response): string
{
return 'the Response '.$this->toString();
}
}

View File

@ -0,0 +1,47 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Response;
final class ResponseIsRedirected extends Constraint
{
public function toString(): string
{
return 'is redirected';
}
/**
* @param Response $response
*/
protected function matches($response): bool
{
return $response->isRedirect();
}
/**
* @param Response $response
*/
protected function failureDescription($response): string
{
return 'the Response '.$this->toString();
}
/**
* @param Response $response
*/
protected function additionalFailureDescription($response): string
{
return (string) $response;
}
}

View File

@ -0,0 +1,47 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Response;
final class ResponseIsSuccessful extends Constraint
{
public function toString(): string
{
return 'is successful';
}
/**
* @param Response $response
*/
protected function matches($response): bool
{
return $response->isSuccessful();
}
/**
* @param Response $response
*/
protected function failureDescription($response): string
{
return 'the Response '.$this->toString();
}
/**
* @param Response $response
*/
protected function additionalFailureDescription($response): string
{
return (string) $response;
}
}

View File

@ -0,0 +1,47 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Response;
final class ResponseIsUnprocessable extends Constraint
{
public function toString(): string
{
return 'is unprocessable';
}
/**
* @param Response $other
*/
protected function matches($other): bool
{
return Response::HTTP_UNPROCESSABLE_ENTITY === $other->getStatusCode();
}
/**
* @param Response $other
*/
protected function failureDescription($other): string
{
return 'the Response '.$this->toString();
}
/**
* @param Response $other
*/
protected function additionalFailureDescription($other): string
{
return (string) $other;
}
}

View File

@ -0,0 +1,54 @@
<?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\Component\HttpFoundation\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Response;
final class ResponseStatusCodeSame extends Constraint
{
private int $statusCode;
public function __construct(int $statusCode)
{
$this->statusCode = $statusCode;
}
public function toString(): string
{
return 'status code is '.$this->statusCode;
}
/**
* @param Response $response
*/
protected function matches($response): bool
{
return $this->statusCode === $response->getStatusCode();
}
/**
* @param Response $response
*/
protected function failureDescription($response): string
{
return 'the Response '.$this->toString();
}
/**
* @param Response $response
*/
protected function additionalFailureDescription($response): string
{
return (string) $response;
}
}