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,67 @@
<?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\Mime\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\Mime\Header\MailboxHeader;
use Symfony\Component\Mime\Header\MailboxListHeader;
use Symfony\Component\Mime\RawMessage;
final class EmailAddressContains 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('contains address "%s" with value "%s"', $this->headerName, $this->expectedValue);
}
/**
* @param RawMessage $message
*/
protected function matches($message): bool
{
if (RawMessage::class === $message::class) {
throw new \LogicException('Unable to test a message address on a RawMessage instance.');
}
$header = $message->getHeaders()->get($this->headerName);
if ($header instanceof MailboxHeader) {
return $this->expectedValue === $header->getAddress()->getAddress();
} elseif ($header instanceof MailboxListHeader) {
foreach ($header->getAddresses() as $address) {
if ($this->expectedValue === $address->getAddress()) {
return true;
}
}
return false;
}
throw new \LogicException('Unable to test a message address on a non-address header.');
}
/**
* @param RawMessage $message
*/
protected function failureDescription($message): string
{
return sprintf('the Email %s (value is %s)', $this->toString(), $message->getHeaders()->get($this->headerName)->getBodyAsString());
}
}

View File

@ -0,0 +1,53 @@
<?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\Mime\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\RawMessage;
final class EmailAttachmentCount extends Constraint
{
private int $expectedValue;
private ?string $transport;
public function __construct(int $expectedValue, ?string $transport = null)
{
$this->expectedValue = $expectedValue;
$this->transport = $transport;
}
public function toString(): string
{
return sprintf('has sent "%d" attachment(s)', $this->expectedValue);
}
/**
* @param RawMessage $message
*/
protected function matches($message): bool
{
if (RawMessage::class === $message::class || Message::class === $message::class) {
throw new \LogicException('Unable to test a message attachment on a RawMessage or Message instance.');
}
return $this->expectedValue === \count($message->getAttachments());
}
/**
* @param RawMessage $message
*/
protected function failureDescription($message): string
{
return 'the Email '.$this->toString();
}
}

View File

@ -0,0 +1,50 @@
<?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\Mime\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\Mime\RawMessage;
final class EmailHasHeader 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 RawMessage $message
*/
protected function matches($message): bool
{
if (RawMessage::class === $message::class) {
throw new \LogicException('Unable to test a message header on a RawMessage instance.');
}
return $message->getHeaders()->has($this->headerName);
}
/**
* @param RawMessage $message
*/
protected function failureDescription($message): string
{
return 'the Email '.$this->toString();
}
}

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\Mime\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\Mime\Header\UnstructuredHeader;
use Symfony\Component\Mime\RawMessage;
final class EmailHeaderSame 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 RawMessage $message
*/
protected function matches($message): bool
{
if (RawMessage::class === $message::class) {
throw new \LogicException('Unable to test a message header on a RawMessage instance.');
}
return $this->expectedValue === $this->getHeaderValue($message);
}
/**
* @param RawMessage $message
*/
protected function failureDescription($message): string
{
return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message) ?? 'null');
}
private function getHeaderValue($message): ?string
{
if (null === $header = $message->getHeaders()->get($this->headerName)) {
return null;
}
return $header instanceof UnstructuredHeader ? $header->getValue() : $header->getBodyAsString();
}
}

View File

@ -0,0 +1,51 @@
<?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\Mime\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\RawMessage;
final class EmailHtmlBodyContains extends Constraint
{
private string $expectedText;
public function __construct(string $expectedText)
{
$this->expectedText = $expectedText;
}
public function toString(): string
{
return sprintf('contains "%s"', $this->expectedText);
}
/**
* @param RawMessage $message
*/
protected function matches($message): bool
{
if (RawMessage::class === $message::class || Message::class === $message::class) {
throw new \LogicException('Unable to test a message HTML body on a RawMessage or Message instance.');
}
return str_contains($message->getHtmlBody(), $this->expectedText);
}
/**
* @param RawMessage $message
*/
protected function failureDescription($message): string
{
return 'the Email HTML body '.$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\Mime\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\Mime\Email;
final class EmailSubjectContains extends Constraint
{
public function __construct(
private readonly string $expectedSubjectValue,
) {
}
public function toString(): string
{
return sprintf('contains subject with value "%s"', $this->expectedSubjectValue);
}
protected function matches($other): bool
{
if (!$other instanceof Email) {
throw new \LogicException('Can only test a message subject on an Email instance.');
}
return str_contains((string) $other->getSubject(), $this->expectedSubjectValue);
}
protected function failureDescription($other): string
{
$message = 'The email subject '.$this->toString();
if ($other instanceof Email) {
$message .= sprintf('. The subject was: "%s"', $other->getSubject() ?? '<empty>');
}
return $message;
}
}

View File

@ -0,0 +1,51 @@
<?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\Mime\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\RawMessage;
final class EmailTextBodyContains extends Constraint
{
private string $expectedText;
public function __construct(string $expectedText)
{
$this->expectedText = $expectedText;
}
public function toString(): string
{
return sprintf('contains "%s"', $this->expectedText);
}
/**
* @param RawMessage $message
*/
protected function matches($message): bool
{
if (RawMessage::class === $message::class || Message::class === $message::class) {
throw new \LogicException('Unable to test a message text body on a RawMessage or Message instance.');
}
return str_contains($message->getTextBody(), $this->expectedText);
}
/**
* @param RawMessage $message
*/
protected function failureDescription($message): string
{
return 'the Email text body '.$this->toString();
}
}