One Hat Cyber Team
Your IP:
216.73.216.102
Server IP:
198.54.114.155
Server:
Linux server71.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
Server Software:
LiteSpeed
PHP Version:
5.6.40
Create File
|
Create Folder
Execute
Dir :
~
/
home
/
fluxyjvi
/
public_html
/
assets
/
images
/
View File Name :
Framework.tar
Constraint/Callback.php 0000644 00000002347 15107326341 0011105 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; /** * @psalm-template CallbackInput of mixed * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class Callback extends Constraint { /** * @psalm-var callable(CallbackInput $input): bool */ private readonly mixed $callback; /** * @psalm-param callable(CallbackInput $input): bool $callback */ public function __construct(callable $callback) { $this->callback = $callback; } /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is accepted by specified callback'; } /** * Evaluates the constraint for parameter $value. Returns true if the * constraint is met, false otherwise. * * @psalm-param CallbackInput $other */ protected function matches(mixed $other): bool { return ($this->callback)($other); } } Constraint/String/StringEqualsStringIgnoringLineEndings.php 0000644 00000002623 15107326341 0020301 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function sprintf; use function strtr; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class StringEqualsStringIgnoringLineEndings extends Constraint { private readonly string $string; public function __construct(string $string) { $this->string = $this->normalizeLineEndings($string); } /** * Returns a string representation of the constraint. */ public function toString(): string { return sprintf( 'is equal to "%s" ignoring line endings', $this->string, ); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return $this->string === $this->normalizeLineEndings((string) $other); } private function normalizeLineEndings(string $string): string { return strtr( $string, [ "\r\n" => "\n", "\r" => "\n", ], ); } } Constraint/String/StringMatchesFormatDescription.php 0000644 00000006306 15107326341 0017006 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use const DIRECTORY_SEPARATOR; use function explode; use function implode; use function preg_match; use function preg_quote; use function preg_replace; use function strtr; use SebastianBergmann\Diff\Differ; use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class StringMatchesFormatDescription extends Constraint { private readonly string $formatDescription; public function __construct(string $formatDescription) { $this->formatDescription = $formatDescription; } public function toString(): string { return 'matches format description:' . PHP_EOL . $this->formatDescription; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { $other = $this->convertNewlines($other); $matches = preg_match( $this->regularExpressionForFormatDescription( $this->convertNewlines($this->formatDescription), ), $other, ); return $matches > 0; } protected function failureDescription(mixed $other): string { return 'string matches format description'; } protected function additionalFailureDescription(mixed $other): string { $from = explode("\n", $this->formatDescription); $to = explode("\n", $this->convertNewlines($other)); foreach ($from as $index => $line) { if (isset($to[$index]) && $line !== $to[$index]) { $line = $this->regularExpressionForFormatDescription($line); if (preg_match($line, $to[$index]) > 0) { $from[$index] = $to[$index]; } } } $from = implode("\n", $from); $to = implode("\n", $to); return $this->differ()->diff($from, $to); } private function regularExpressionForFormatDescription(string $string): string { $string = strtr( preg_quote($string, '/'), [ '%%' => '%', '%e' => '\\' . DIRECTORY_SEPARATOR, '%s' => '[^\r\n]+', '%S' => '[^\r\n]*', '%a' => '.+', '%A' => '.*', '%w' => '\s*', '%i' => '[+-]?\d+', '%d' => '\d+', '%x' => '[0-9a-fA-F]+', '%f' => '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', '%c' => '.', ], ); return '/^' . $string . '$/s'; } private function convertNewlines(string $text): string { return preg_replace('/\r\n/', "\n", $text); } private function differ(): Differ { return new Differ(new UnifiedDiffOutputBuilder("--- Expected\n+++ Actual\n")); } } Constraint/String/IsJson.php 0000644 00000004560 15107326341 0012063 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_string; use function json_decode; use function json_last_error; use function sprintf; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsJson extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is valid JSON'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { if (!is_string($other) || $other === '') { return false; } json_decode($other); if (json_last_error()) { return false; } return true; } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { if (!is_string($other)) { return $this->valueToTypeStringFragment($other) . 'is valid JSON'; } if ($other === '') { return 'an empty string is valid JSON'; } return sprintf( 'a string is valid JSON (%s)', $this->determineJsonError($other), ); } private function determineJsonError(string $json): string { json_decode($json); return match (json_last_error()) { JSON_ERROR_NONE => '', JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', default => 'Unknown error', }; } } Constraint/String/StringEndsWith.php 0000644 00000002323 15107326341 0013565 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function str_ends_with; use PHPUnit\Framework\EmptyStringException; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class StringEndsWith extends Constraint { private readonly string $suffix; /** * @throws EmptyStringException */ public function __construct(string $suffix) { if ($suffix === '') { throw new EmptyStringException; } $this->suffix = $suffix; } /** * Returns a string representation of the constraint. */ public function toString(): string { return 'ends with "' . $this->suffix . '"'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return str_ends_with((string) $other, $this->suffix); } } Constraint/String/StringContains.php 0000644 00000010445 15107326341 0013622 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_string; use function mb_detect_encoding; use function mb_stripos; use function mb_strtolower; use function sprintf; use function str_contains; use function strlen; use function strtr; use PHPUnit\Util\Exporter; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class StringContains extends Constraint { private readonly string $needle; private readonly bool $ignoreCase; private readonly bool $ignoreLineEndings; public function __construct(string $needle, bool $ignoreCase = false, bool $ignoreLineEndings = false) { if ($ignoreLineEndings) { $needle = $this->normalizeLineEndings($needle); } $this->needle = $needle; $this->ignoreCase = $ignoreCase; $this->ignoreLineEndings = $ignoreLineEndings; } /** * Returns a string representation of the constraint. */ public function toString(): string { $needle = $this->needle; if ($this->ignoreCase) { $needle = mb_strtolower($this->needle, 'UTF-8'); } return sprintf( 'contains "%s" [%s](length: %s)', $needle, $this->getDetectedEncoding($needle), strlen($needle), ); } public function failureDescription(mixed $other): string { $stringifiedHaystack = Exporter::export($other, true); $haystackEncoding = $this->getDetectedEncoding($other); $haystackLength = $this->getHaystackLength($other); $haystackInformation = sprintf( '%s [%s](length: %s) ', $stringifiedHaystack, $haystackEncoding, $haystackLength, ); $needleInformation = $this->toString(true); return $haystackInformation . $needleInformation; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { $haystack = $other; if ('' === $this->needle) { return true; } if (!is_string($haystack)) { return false; } if ($this->ignoreLineEndings) { $haystack = $this->normalizeLineEndings($haystack); } if ($this->ignoreCase) { /* * We must use the multibyte-safe version, so we can accurately compare non-latin uppercase characters with * their lowercase equivalents. */ return mb_stripos($haystack, $this->needle, 0, 'UTF-8') !== false; } /* * Use the non-multibyte safe functions to see if the string is contained in $other. * * This function is very fast, and we don't care about the character position in the string. * * Additionally, we want this method to be binary safe, so we can check if some binary data is in other binary * data. */ return str_contains($haystack, $this->needle); } private function getDetectedEncoding(mixed $other): string { if ($this->ignoreCase) { return 'Encoding ignored'; } if (!is_string($other)) { return 'Encoding detection failed'; } $detectedEncoding = mb_detect_encoding($other, null, true); if (!$detectedEncoding) { return 'Encoding detection failed'; } return $detectedEncoding; } private function getHaystackLength(mixed $haystack): int { if (!is_string($haystack)) { return 0; } if ($this->ignoreLineEndings) { $haystack = $this->normalizeLineEndings($haystack); } return strlen($haystack); } private function normalizeLineEndings(string $string): string { return strtr( $string, [ "\r\n" => "\n", "\r" => "\n", ], ); } } Constraint/String/RegularExpression.php 0000644 00000002145 15107326341 0014334 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function preg_match; use function sprintf; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class RegularExpression extends Constraint { private readonly string $pattern; public function __construct(string $pattern) { $this->pattern = $pattern; } /** * Returns a string representation of the constraint. */ public function toString(): string { return sprintf( 'matches PCRE pattern "%s"', $this->pattern, ); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return preg_match($this->pattern, $other) > 0; } } Constraint/String/StringStartsWith.php 0000644 00000002333 15107326341 0014155 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function str_starts_with; use PHPUnit\Framework\EmptyStringException; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class StringStartsWith extends Constraint { private readonly string $prefix; /** * @throws EmptyStringException */ public function __construct(string $prefix) { if ($prefix === '') { throw new EmptyStringException; } $this->prefix = $prefix; } /** * Returns a string representation of the constraint. */ public function toString(): string { return 'starts with "' . $this->prefix . '"'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return str_starts_with((string) $other, $this->prefix); } } Constraint/Math/IsNan.php 0000644 00000001520 15107326341 0011302 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_nan; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsNan extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is nan'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return is_nan($other); } } Constraint/Math/IsInfinite.php 0000644 00000001544 15107326341 0012341 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_infinite; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsInfinite extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is infinite'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return is_infinite($other); } } Constraint/Math/IsFinite.php 0000644 00000001534 15107326341 0012011 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_finite; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsFinite extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is finite'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return is_finite($other); } } Constraint/Object/ObjectHasProperty.php 0000644 00000004000 15107326341 0014212 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function gettype; use function is_object; use function sprintf; use ReflectionObject; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class ObjectHasProperty extends Constraint { private readonly string $propertyName; public function __construct(string $propertyName) { $this->propertyName = $propertyName; } /** * Returns a string representation of the constraint. */ public function toString(): string { return sprintf( 'has property "%s"', $this->propertyName, ); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. * * @param mixed $other value or object to evaluate */ protected function matches(mixed $other): bool { if (!is_object($other)) { return false; } return (new ReflectionObject($other))->hasProperty($this->propertyName); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. * * @param mixed $other evaluated value or object */ protected function failureDescription(mixed $other): string { if (is_object($other)) { return sprintf( 'object of class "%s" %s', $other::class, $this->toString(true), ); } return sprintf( '"%s" (%s) %s', $other, gettype($other), $this->toString(true), ); } } Constraint/Object/ObjectEquals.php 0000644 00000010435 15107326341 0013175 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_object; use PHPUnit\Framework\ActualValueIsNotAnObjectException; use PHPUnit\Framework\ComparisonMethodDoesNotAcceptParameterTypeException; use PHPUnit\Framework\ComparisonMethodDoesNotDeclareBoolReturnTypeException; use PHPUnit\Framework\ComparisonMethodDoesNotDeclareExactlyOneParameterException; use PHPUnit\Framework\ComparisonMethodDoesNotDeclareParameterTypeException; use PHPUnit\Framework\ComparisonMethodDoesNotExistException; use ReflectionNamedType; use ReflectionObject; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class ObjectEquals extends Constraint { private readonly object $expected; private readonly string $method; public function __construct(object $object, string $method = 'equals') { $this->expected = $object; $this->method = $method; } public function toString(): string { return 'two objects are equal'; } /** * @throws ActualValueIsNotAnObjectException * @throws ComparisonMethodDoesNotAcceptParameterTypeException * @throws ComparisonMethodDoesNotDeclareBoolReturnTypeException * @throws ComparisonMethodDoesNotDeclareExactlyOneParameterException * @throws ComparisonMethodDoesNotDeclareParameterTypeException * @throws ComparisonMethodDoesNotExistException */ protected function matches(mixed $other): bool { if (!is_object($other)) { throw new ActualValueIsNotAnObjectException; } $object = new ReflectionObject($other); if (!$object->hasMethod($this->method)) { throw new ComparisonMethodDoesNotExistException( $other::class, $this->method, ); } $method = $object->getMethod($this->method); if (!$method->hasReturnType()) { throw new ComparisonMethodDoesNotDeclareBoolReturnTypeException( $other::class, $this->method, ); } $returnType = $method->getReturnType(); if (!$returnType instanceof ReflectionNamedType) { throw new ComparisonMethodDoesNotDeclareBoolReturnTypeException( $other::class, $this->method, ); } if ($returnType->allowsNull()) { throw new ComparisonMethodDoesNotDeclareBoolReturnTypeException( $other::class, $this->method, ); } if ($returnType->getName() !== 'bool') { throw new ComparisonMethodDoesNotDeclareBoolReturnTypeException( $other::class, $this->method, ); } if ($method->getNumberOfParameters() !== 1 || $method->getNumberOfRequiredParameters() !== 1) { throw new ComparisonMethodDoesNotDeclareExactlyOneParameterException( $other::class, $this->method, ); } $parameter = $method->getParameters()[0]; if (!$parameter->hasType()) { throw new ComparisonMethodDoesNotDeclareParameterTypeException( $other::class, $this->method, ); } $type = $parameter->getType(); if (!$type instanceof ReflectionNamedType) { throw new ComparisonMethodDoesNotDeclareParameterTypeException( $other::class, $this->method, ); } $typeName = $type->getName(); if ($typeName === 'self') { $typeName = $other::class; } if (!$this->expected instanceof $typeName) { throw new ComparisonMethodDoesNotAcceptParameterTypeException( $other::class, $this->method, $this->expected::class, ); } return $other->{$this->method}($this->expected); } protected function failureDescription(mixed $other): string { return $this->toString(true); } } Constraint/Exception/ExceptionMessageMatchesRegularExpression.php 0000644 00000003672 15107326341 0021523 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function preg_match; use function sprintf; use Exception; use PHPUnit\Util\Exporter; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ExceptionMessageMatchesRegularExpression extends Constraint { private readonly string $regularExpression; public function __construct(string $regularExpression) { $this->regularExpression = $regularExpression; } public function toString(): string { return 'exception message matches ' . Exporter::export($this->regularExpression); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. * * @throws \PHPUnit\Framework\Exception * @throws Exception */ protected function matches(mixed $other): bool { $match = @preg_match($this->regularExpression, (string) $other); if ($match === false) { throw new \PHPUnit\Framework\Exception( sprintf( 'Invalid expected exception message regular expression given: %s', $this->regularExpression, ), ); } return $match === 1; } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { return sprintf( "exception message '%s' matches '%s'", $other, $this->regularExpression, ); } } Constraint/Exception/ExceptionMessageIsOrContains.php 0000644 00000003376 15107326341 0017111 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function sprintf; use function str_contains; use PHPUnit\Util\Exporter; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ExceptionMessageIsOrContains extends Constraint { private readonly string $expectedMessage; public function __construct(string $expectedMessage) { $this->expectedMessage = $expectedMessage; } public function toString(): string { if ($this->expectedMessage === '') { return 'exception message is empty'; } return 'exception message contains ' . Exporter::export($this->expectedMessage); } protected function matches(mixed $other): bool { if ($this->expectedMessage === '') { return $other === ''; } return str_contains((string) $other, $this->expectedMessage); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { if ($this->expectedMessage === '') { return sprintf( "exception message is empty but is '%s'", $other, ); } return sprintf( "exception message '%s' contains '%s'", $other, $this->expectedMessage, ); } } Constraint/Exception/Exception.php 0000644 00000003770 15107326341 0013306 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function sprintf; use PHPUnit\Util\Filter; use Throwable; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class Exception extends Constraint { private readonly string $className; public function __construct(string $className) { $this->className = $className; } /** * Returns a string representation of the constraint. */ public function toString(): string { return sprintf( 'exception of type "%s"', $this->className, ); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return $other instanceof $this->className; } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. * * @throws \PHPUnit\Framework\Exception */ protected function failureDescription(mixed $other): string { if ($other === null) { return sprintf( 'exception of type "%s" is thrown', $this->className, ); } $message = ''; if ($other instanceof Throwable) { $message = '. Message was: "' . $other->getMessage() . '" at' . "\n" . Filter::getFilteredStacktrace($other); } return sprintf( 'exception of type "%s" matches expected exception "%s"%s', $other::class, $this->className, $message, ); } } Constraint/Exception/ExceptionCode.php 0000644 00000002744 15107326341 0014101 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function sprintf; use PHPUnit\Util\Exporter; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ExceptionCode extends Constraint { private readonly int|string $expectedCode; public function __construct(int|string $expected) { $this->expectedCode = $expected; } public function toString(): string { return 'exception code is ' . $this->expectedCode; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return (string) $other === (string) $this->expectedCode; } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { return sprintf( '%s is equal to expected exception code %s', Exporter::export($other, true), Exporter::export($this->expectedCode, true), ); } } Constraint/Filesystem/IsWritable.php 0000644 00000002372 15107326341 0013600 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_writable; use function sprintf; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsWritable extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is writable'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return is_writable($other); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { return sprintf( '"%s" is writable', $other, ); } } Constraint/Filesystem/FileExists.php 0000644 00000002372 15107326341 0013612 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function file_exists; use function sprintf; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class FileExists extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'file exists'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return file_exists($other); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { return sprintf( 'file "%s" exists', $other, ); } } Constraint/Filesystem/DirectoryExists.php 0000644 00000002377 15107326341 0014704 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_dir; use function sprintf; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class DirectoryExists extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'directory exists'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return is_dir($other); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { return sprintf( 'directory "%s" exists', $other, ); } } Constraint/Filesystem/IsReadable.php 0000644 00000002372 15107326341 0013526 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_readable; use function sprintf; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsReadable extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is readable'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return is_readable($other); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { return sprintf( '"%s" is readable', $other, ); } } Constraint/IsAnything.php 0000644 00000002552 15107326341 0011464 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use PHPUnit\Framework\ExpectationFailedException; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsAnything extends Constraint { /** * Evaluates the constraint for parameter $other. * * If $returnResult is set to false (the default), an exception is thrown * in case of a failure. null is returned otherwise. * * If $returnResult is true, the result of the evaluation is returned as * a boolean value instead: true in case of success, false in case of a * failure. * * @throws ExpectationFailedException */ public function evaluate(mixed $other, string $description = '', bool $returnResult = false): ?bool { return $returnResult ? true : null; } /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is anything'; } /** * Counts the number of constraint elements. */ public function count(): int { return 0; } } Constraint/Type/IsNull.php 0000644 00000001475 15107326342 0011542 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsNull extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is null'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return $other === null; } } Constraint/Type/IsType.php 0000644 00000011324 15107326342 0011543 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function gettype; use function is_array; use function is_bool; use function is_callable; use function is_float; use function is_int; use function is_iterable; use function is_numeric; use function is_object; use function is_scalar; use function is_string; use function sprintf; use PHPUnit\Framework\UnknownTypeException; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsType extends Constraint { /** * @var string */ public const TYPE_ARRAY = 'array'; /** * @var string */ public const TYPE_BOOL = 'bool'; /** * @var string */ public const TYPE_FLOAT = 'float'; /** * @var string */ public const TYPE_INT = 'int'; /** * @var string */ public const TYPE_NULL = 'null'; /** * @var string */ public const TYPE_NUMERIC = 'numeric'; /** * @var string */ public const TYPE_OBJECT = 'object'; /** * @var string */ public const TYPE_RESOURCE = 'resource'; /** * @var string */ public const TYPE_CLOSED_RESOURCE = 'resource (closed)'; /** * @var string */ public const TYPE_STRING = 'string'; /** * @var string */ public const TYPE_SCALAR = 'scalar'; /** * @var string */ public const TYPE_CALLABLE = 'callable'; /** * @var string */ public const TYPE_ITERABLE = 'iterable'; /** * @psalm-var array<string,bool> */ private const KNOWN_TYPES = [ 'array' => true, 'boolean' => true, 'bool' => true, 'double' => true, 'float' => true, 'integer' => true, 'int' => true, 'null' => true, 'numeric' => true, 'object' => true, 'real' => true, 'resource' => true, 'resource (closed)' => true, 'string' => true, 'scalar' => true, 'callable' => true, 'iterable' => true, ]; /** * @psalm-var 'array'|'boolean'|'bool'|'double'|'float'|'integer'|'int'|'null'|'numeric'|'object'|'real'|'resource'|'resource (closed)'|'string'|'scalar'|'callable'|'iterable' */ private readonly string $type; /** * @psalm-param 'array'|'boolean'|'bool'|'double'|'float'|'integer'|'int'|'null'|'numeric'|'object'|'real'|'resource'|'resource (closed)'|'string'|'scalar'|'callable'|'iterable' $type * * @throws UnknownTypeException */ public function __construct(string $type) { if (!isset(self::KNOWN_TYPES[$type])) { throw new UnknownTypeException($type); } $this->type = $type; } /** * Returns a string representation of the constraint. */ public function toString(): string { return sprintf( 'is of type %s', $this->type, ); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { switch ($this->type) { case 'numeric': return is_numeric($other); case 'integer': case 'int': return is_int($other); case 'double': case 'float': case 'real': return is_float($other); case 'string': return is_string($other); case 'boolean': case 'bool': return is_bool($other); case 'null': return null === $other; case 'array': return is_array($other); case 'object': return is_object($other); case 'resource': $type = gettype($other); return $type === 'resource' || $type === 'resource (closed)'; case 'resource (closed)': return gettype($other) === 'resource (closed)'; case 'scalar': return is_scalar($other); case 'callable': return is_callable($other); case 'iterable': return is_iterable($other); default: return false; } } } Constraint/Type/IsInstanceOf.php 0000644 00000003760 15107326342 0012660 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function class_exists; use function interface_exists; use function sprintf; use PHPUnit\Framework\UnknownClassOrInterfaceException; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsInstanceOf extends Constraint { /** * @psalm-var class-string */ private readonly string $name; /** * @psalm-var 'class'|'interface' */ private readonly string $type; /** * @throws UnknownClassOrInterfaceException */ public function __construct(string $name) { if (class_exists($name)) { $this->type = 'class'; } elseif (interface_exists($name)) { $this->type = 'interface'; } else { throw new UnknownClassOrInterfaceException($name); } $this->name = $name; } /** * Returns a string representation of the constraint. */ public function toString(): string { return sprintf( 'is an instance of %s %s', $this->type, $this->name, ); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return $other instanceof $this->name; } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { return $this->valueToTypeStringFragment($other) . $this->toString(true); } } Constraint/IsIdentical.php 0000644 00000006610 15107326342 0011577 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_array; use function is_object; use function is_string; use function sprintf; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Util\Exporter; use SebastianBergmann\Comparator\ComparisonFailure; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsIdentical extends Constraint { private readonly mixed $value; public function __construct(mixed $value) { $this->value = $value; } /** * Evaluates the constraint for parameter $other. * * If $returnResult is set to false (the default), an exception is thrown * in case of a failure. null is returned otherwise. * * If $returnResult is true, the result of the evaluation is returned as * a boolean value instead: true in case of success, false in case of a * failure. * * @throws ExpectationFailedException */ public function evaluate(mixed $other, string $description = '', bool $returnResult = false): ?bool { $success = $this->value === $other; if ($returnResult) { return $success; } if (!$success) { $f = null; // if both values are strings, make sure a diff is generated if (is_string($this->value) && is_string($other)) { $f = new ComparisonFailure( $this->value, $other, sprintf("'%s'", $this->value), sprintf("'%s'", $other), ); } // if both values are array, make sure a diff is generated if (is_array($this->value) && is_array($other)) { $f = new ComparisonFailure( $this->value, $other, Exporter::export($this->value, true), Exporter::export($other, true), ); } $this->fail($other, $description, $f); } return null; } /** * Returns a string representation of the constraint. */ public function toString(bool $exportObjects = false): string { if (is_object($this->value)) { return 'is identical to an object of class "' . $this->value::class . '"'; } return 'is identical to ' . Exporter::export($this->value, $exportObjects); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { if (is_object($this->value) && is_object($other)) { return 'two variables reference the same object'; } if (is_string($this->value) && is_string($other)) { return 'two strings are identical'; } if (is_array($this->value) && is_array($other)) { return 'two arrays are identical'; } return parent::failureDescription($other); } } Constraint/Operator/UnaryOperator.php 0000644 00000006653 15107326342 0014023 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function count; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ abstract class UnaryOperator extends Operator { private readonly Constraint $constraint; public function __construct(mixed $constraint) { $this->constraint = $this->checkConstraint($constraint); } /** * Returns the number of operands (constraints). */ public function arity(): int { return 1; } /** * Returns a string representation of the constraint. */ public function toString(): string { $reduced = $this->reduce(); if ($reduced !== $this) { return $reduced->toString(); } $constraint = $this->constraint->reduce(); if ($this->constraintNeedsParentheses($constraint)) { return $this->operator() . '( ' . $constraint->toString() . ' )'; } $string = $constraint->toStringInContext($this, 0); if ($string === '') { return $this->transformString($constraint->toString()); } return $string; } /** * Counts the number of constraint elements. */ public function count(): int { return count($this->constraint); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { $reduced = $this->reduce(); if ($reduced !== $this) { return $reduced->failureDescription($other); } $constraint = $this->constraint->reduce(); if ($this->constraintNeedsParentheses($constraint)) { return $this->operator() . '( ' . $constraint->failureDescription($other) . ' )'; } $string = $constraint->failureDescriptionInContext($this, 0, $other); if ($string === '') { return $this->transformString($constraint->failureDescription($other)); } return $string; } /** * Transforms string returned by the memeber constraint's toString() or * failureDescription() such that it reflects constraint's participation in * this expression. * * The method may be overwritten in a subclass to apply default * transformation in case the operand constraint does not provide its own * custom strings via toStringInContext() or failureDescriptionInContext(). */ protected function transformString(string $string): string { return $string; } /** * Provides access to $this->constraint for subclasses. */ final protected function constraint(): Constraint { return $this->constraint; } /** * Returns true if the $constraint needs to be wrapped with parentheses. */ protected function constraintNeedsParentheses(Constraint $constraint): bool { $constraint = $constraint->reduce(); return $constraint instanceof self || parent::constraintNeedsParentheses($constraint); } } Constraint/Operator/BinaryOperator.php 0000644 00000006334 15107326342 0014145 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function array_map; use function count; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ abstract class BinaryOperator extends Operator { /** * @psalm-var list<Constraint> */ private readonly array $constraints; protected function __construct(mixed ...$constraints) { $this->constraints = array_map( fn ($constraint): Constraint => $this->checkConstraint($constraint), $constraints, ); } /** * Returns the number of operands (constraints). */ final public function arity(): int { return count($this->constraints); } /** * Returns a string representation of the constraint. */ public function toString(): string { $reduced = $this->reduce(); if ($reduced !== $this) { return $reduced->toString(); } $text = ''; foreach ($this->constraints as $key => $constraint) { $constraint = $constraint->reduce(); $text .= $this->constraintToString($constraint, $key); } return $text; } /** * Counts the number of constraint elements. */ public function count(): int { $count = 0; foreach ($this->constraints as $constraint) { $count += count($constraint); } return $count; } /** * @psalm-return list<Constraint> */ final protected function constraints(): array { return $this->constraints; } /** * Returns true if the $constraint needs to be wrapped with braces. */ final protected function constraintNeedsParentheses(Constraint $constraint): bool { return $this->arity() > 1 && parent::constraintNeedsParentheses($constraint); } /** * Reduces the sub-expression starting at $this by skipping degenerate * sub-expression and returns first descendant constraint that starts * a non-reducible sub-expression. * * See Constraint::reduce() for more. */ protected function reduce(): Constraint { if ($this->arity() === 1 && $this->constraints[0] instanceof Operator) { return $this->constraints[0]->reduce(); } return parent::reduce(); } /** * Returns string representation of given operand in context of this operator. */ private function constraintToString(Constraint $constraint, int $position): string { $prefix = ''; if ($position > 0) { $prefix = (' ' . $this->operator() . ' '); } if ($this->constraintNeedsParentheses($constraint)) { return $prefix . '( ' . $constraint->toString() . ' )'; } $string = $constraint->toStringInContext($this, $position); if ($string === '') { $string = $constraint->toString(); } return $prefix . $string; } } Constraint/Operator/LogicalXor.php 0000644 00000003217 15107326342 0013245 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function array_reduce; use function array_shift; use PHPUnit\Framework\ExpectationFailedException; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class LogicalXor extends BinaryOperator { public static function fromConstraints(mixed ...$constraints): self { return new self(...$constraints); } /** * Returns the name of this operator. */ public function operator(): string { return 'xor'; } /** * Returns this operator's precedence. * * @see https://www.php.net/manual/en/language.operators.precedence.php. */ public function precedence(): int { return 23; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. * * @throws ExpectationFailedException */ public function matches(mixed $other): bool { $constraints = $this->constraints(); $initial = array_shift($constraints); if ($initial === null) { return false; } return array_reduce( $constraints, static fn (bool $matches, Constraint $constraint): bool => $matches xor $constraint->evaluate($other, '', true), $initial->evaluate($other, '', true), ); } } Constraint/Operator/Operator.php 0000644 00000002662 15107326342 0013000 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ abstract class Operator extends Constraint { /** * Returns the name of this operator. */ abstract public function operator(): string; /** * Returns this operator's precedence. * * @see https://www.php.net/manual/en/language.operators.precedence.php */ abstract public function precedence(): int; /** * Returns the number of operands. */ abstract public function arity(): int; /** * Validates $constraint argument. */ protected function checkConstraint(mixed $constraint): Constraint { if (!$constraint instanceof Constraint) { return new IsEqual($constraint); } return $constraint; } /** * Returns true if the $constraint needs to be wrapped with braces. */ protected function constraintNeedsParentheses(Constraint $constraint): bool { return $constraint instanceof self && $constraint->arity() > 1 && $this->precedence() <= $constraint->precedence(); } } Constraint/Operator/LogicalAnd.php 0000644 00000002473 15107326342 0013202 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class LogicalAnd extends BinaryOperator { public static function fromConstraints(mixed ...$constraints): self { return new self(...$constraints); } /** * Returns the name of this operator. */ public function operator(): string { return 'and'; } /** * Returns this operator's precedence. * * @see https://www.php.net/manual/en/language.operators.precedence.php */ public function precedence(): int { return 22; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { foreach ($this->constraints() as $constraint) { if (!$constraint->evaluate($other, '', true)) { return false; } } return [] !== $this->constraints(); } } Constraint/Operator/LogicalOr.php 0000644 00000002436 15107326342 0013057 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class LogicalOr extends BinaryOperator { public static function fromConstraints(mixed ...$constraints): self { return new self(...$constraints); } /** * Returns the name of this operator. */ public function operator(): string { return 'or'; } /** * Returns this operator's precedence. * * @see https://www.php.net/manual/en/language.operators.precedence.php */ public function precedence(): int { return 24; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ public function matches(mixed $other): bool { foreach ($this->constraints() as $constraint) { if ($constraint->evaluate($other, '', true)) { return true; } } return false; } } Constraint/Operator/LogicalNot.php 0000644 00000006573 15107326342 0013245 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function array_map; use function count; use function preg_match; use function preg_quote; use function preg_replace; use PHPUnit\Framework\ExpectationFailedException; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class LogicalNot extends UnaryOperator { public static function negate(string $string): string { $positives = [ 'contains ', 'exists', 'has ', 'is ', 'are ', 'matches ', 'starts with ', 'ends with ', 'reference ', 'not not ', ]; $negatives = [ 'does not contain ', 'does not exist', 'does not have ', 'is not ', 'are not ', 'does not match ', 'starts not with ', 'ends not with ', 'don\'t reference ', 'not ', ]; preg_match('/(\'[\w\W]*\')([\w\W]*)("[\w\W]*")/i', $string, $matches); $positives = array_map( static fn (string $s) => '/\\b' . preg_quote($s, '/') . '/', $positives, ); if (count($matches) > 0) { $nonInput = $matches[2]; $negatedString = preg_replace( '/' . preg_quote($nonInput, '/') . '/', preg_replace( $positives, $negatives, $nonInput, ), $string, ); } else { $negatedString = preg_replace( $positives, $negatives, $string, ); } return $negatedString; } /** * Returns the name of this operator. */ public function operator(): string { return 'not'; } /** * Returns this operator's precedence. * * @see https://www.php.net/manual/en/language.operators.precedence.php */ public function precedence(): int { return 5; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. * * @throws ExpectationFailedException */ protected function matches(mixed $other): bool { return !$this->constraint()->evaluate($other, '', true); } /** * Applies additional transformation to strings returned by toString() or * failureDescription(). */ protected function transformString(string $string): string { return self::negate($string); } /** * Reduces the sub-expression starting at $this by skipping degenerate * sub-expression and returns first descendant constraint that starts * a non-reducible sub-expression. * * See Constraint::reduce() for more. */ protected function reduce(): Constraint { $constraint = $this->constraint(); if ($constraint instanceof self) { return $constraint->constraint()->reduce(); } return parent::reduce(); } } Constraint/Traversable/TraversableContainsOnly.php 0000644 00000003734 15107326342 0016500 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use PHPUnit\Framework\ExpectationFailedException; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class TraversableContainsOnly extends Constraint { private Constraint $constraint; private readonly string $type; /** * @throws \PHPUnit\Framework\Exception */ public function __construct(string $type, bool $isNativeType = true) { if ($isNativeType) { $this->constraint = new IsType($type); } else { $this->constraint = new IsInstanceOf($type); } $this->type = $type; } /** * Evaluates the constraint for parameter $other. * * If $returnResult is set to false (the default), an exception is thrown * in case of a failure. null is returned otherwise. * * If $returnResult is true, the result of the evaluation is returned as * a boolean value instead: true in case of success, false in case of a * failure. * * @throws ExpectationFailedException */ public function evaluate(mixed $other, string $description = '', bool $returnResult = false): bool { $success = true; foreach ($other as $item) { if (!$this->constraint->evaluate($item, '', true)) { $success = false; break; } } if (!$success && !$returnResult) { $this->fail($other, $description); } return $success; } /** * Returns a string representation of the constraint. */ public function toString(): string { return 'contains only values of type "' . $this->type . '"'; } } Constraint/Traversable/TraversableContains.php 0000644 00000002616 15107326342 0015634 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_array; use function sprintf; use PHPUnit\Util\Exporter; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ abstract class TraversableContains extends Constraint { private readonly mixed $value; public function __construct(mixed $value) { $this->value = $value; } /** * Returns a string representation of the constraint. */ public function toString(bool $exportObjects = false): string { return 'contains ' . Exporter::export($this->value, $exportObjects); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { return sprintf( '%s %s', is_array($other) ? 'an array' : 'a traversable', $this->toString(true), ); } protected function value(): mixed { return $this->value; } } Constraint/Traversable/ArrayHasKey.php 0000644 00000003155 15107326342 0014045 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function array_key_exists; use function is_array; use ArrayAccess; use PHPUnit\Util\Exporter; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class ArrayHasKey extends Constraint { private readonly int|string $key; public function __construct(int|string $key) { $this->key = $key; } /** * Returns a string representation of the constraint. */ public function toString(): string { return 'has the key ' . Exporter::export($this->key); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { if (is_array($other)) { return array_key_exists($this->key, $other); } if ($other instanceof ArrayAccess) { return $other->offsetExists($this->key); } return false; } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { return 'an array ' . $this->toString(true); } } Constraint/Traversable/IsList.php 0000644 00000002471 15107326342 0013071 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function array_is_list; use function is_array; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsList extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is a list'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { if (!is_array($other)) { return false; } return array_is_list($other); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { return $this->valueToTypeStringFragment($other) . $this->toString(true); } } Constraint/Traversable/TraversableContainsIdentical.php 0000644 00000001717 15107326342 0017452 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use SplObjectStorage; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class TraversableContainsIdentical extends TraversableContains { /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { if ($other instanceof SplObjectStorage) { return $other->contains($this->value()); } foreach ($other as $element) { if ($this->value() === $element) { return true; } } return false; } } Constraint/Traversable/TraversableContainsEqual.php 0000644 00000002011 15107326342 0016611 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use SplObjectStorage; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class TraversableContainsEqual extends TraversableContains { /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { if ($other instanceof SplObjectStorage) { return $other->contains($this->value()); } foreach ($other as $element) { /* @noinspection TypeUnsafeComparisonInspection */ if ($this->value() == $element) { return true; } } return false; } } Constraint/JsonMatches.php 0000644 00000005142 15107326342 0011624 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function json_decode; use function sprintf; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Util\InvalidJsonException; use PHPUnit\Util\Json; use SebastianBergmann\Comparator\ComparisonFailure; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class JsonMatches extends Constraint { private readonly string $value; public function __construct(string $value) { $this->value = $value; } /** * Returns a string representation of the object. */ public function toString(): string { return sprintf( 'matches JSON string "%s"', $this->value, ); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. * * This method can be overridden to implement the evaluation algorithm. */ protected function matches(mixed $other): bool { [$error, $recodedOther] = Json::canonicalize($other); if ($error) { return false; } [$error, $recodedValue] = Json::canonicalize($this->value); if ($error) { return false; } return $recodedOther == $recodedValue; } /** * Throws an exception for the given compared value and test description. * * @throws ExpectationFailedException * @throws InvalidJsonException */ protected function fail(mixed $other, string $description, ComparisonFailure $comparisonFailure = null): never { if ($comparisonFailure === null) { [$error, $recodedOther] = Json::canonicalize($other); if ($error) { parent::fail($other, $description); } [$error, $recodedValue] = Json::canonicalize($this->value); if ($error) { parent::fail($other, $description); } $comparisonFailure = new ComparisonFailure( json_decode($this->value), json_decode($other), Json::prettify($recodedValue), Json::prettify($recodedOther), 'Failed asserting that two json values are equal.', ); } parent::fail($other, $description, $comparisonFailure); } } Constraint/Cardinality/Count.php 0000644 00000006254 15107326342 0012746 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function count; use function is_countable; use function iterator_count; use function sprintf; use EmptyIterator; use Generator; use Iterator; use IteratorAggregate; use PHPUnit\Framework\Exception; use PHPUnit\Framework\GeneratorNotSupportedException; use Traversable; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ class Count extends Constraint { private readonly int $expectedCount; public function __construct(int $expected) { $this->expectedCount = $expected; } public function toString(): string { return sprintf( 'count matches %d', $this->expectedCount, ); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. * * @throws Exception */ protected function matches(mixed $other): bool { return $this->expectedCount === $this->getCountOf($other); } /** * @throws Exception */ protected function getCountOf(mixed $other): ?int { if (is_countable($other)) { return count($other); } if ($other instanceof EmptyIterator) { return 0; } if ($other instanceof Traversable) { while ($other instanceof IteratorAggregate) { try { $other = $other->getIterator(); } catch (\Exception $e) { throw new Exception( $e->getMessage(), $e->getCode(), $e, ); } } $iterator = $other; if ($iterator instanceof Generator) { throw new GeneratorNotSupportedException; } if (!$iterator instanceof Iterator) { return iterator_count($iterator); } $key = $iterator->key(); $count = iterator_count($iterator); // Manually rewind $iterator to previous key, since iterator_count // moves pointer. if ($key !== null) { $iterator->rewind(); while ($iterator->valid() && $key !== $iterator->key()) { $iterator->next(); } } return $count; } return null; } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. * * @throws Exception */ protected function failureDescription(mixed $other): string { return sprintf( 'actual size %d matches expected size %d', (int) $this->getCountOf($other), $this->expectedCount, ); } } Constraint/Cardinality/LessThan.php 0000644 00000002061 15107326342 0013367 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use PHPUnit\Util\Exporter; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class LessThan extends Constraint { private readonly mixed $value; public function __construct(mixed $value) { $this->value = $value; } /** * Returns a string representation of the constraint. */ public function toString(bool $exportObjects = false): string { return 'is less than ' . Exporter::export($this->value, $exportObjects); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return $this->value > $other; } } Constraint/Cardinality/IsEmpty.php 0000644 00000003200 15107326342 0013234 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function count; use function gettype; use function sprintf; use function str_starts_with; use Countable; use EmptyIterator; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsEmpty extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is empty'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { if ($other instanceof EmptyIterator) { return true; } if ($other instanceof Countable) { return count($other) === 0; } return empty($other); } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. */ protected function failureDescription(mixed $other): string { $type = gettype($other); return sprintf( '%s %s %s', str_starts_with($type, 'a') || str_starts_with($type, 'o') ? 'an' : 'a', $type, $this->toString(true), ); } } Constraint/Cardinality/GreaterThan.php 0000644 00000002067 15107326342 0014060 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use PHPUnit\Util\Exporter; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class GreaterThan extends Constraint { private readonly mixed $value; public function __construct(mixed $value) { $this->value = $value; } /** * Returns a string representation of the constraint. */ public function toString(bool $exportObjects = false): string { return 'is greater than ' . Exporter::export($this->value, $exportObjects); } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return $this->value < $other; } } Constraint/Cardinality/SameSize.php 0000644 00000001272 15107326342 0013371 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use PHPUnit\Framework\Exception; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class SameSize extends Count { /** * @psalm-param \Countable|iterable $expected * * @throws Exception */ public function __construct($expected) { parent::__construct((int) $this->getCountOf($expected)); } } Constraint/Constraint.php 0000644 00000020267 15107326342 0011537 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function gettype; use function sprintf; use function strtolower; use Countable; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\SelfDescribing; use PHPUnit\Util\Exporter; use SebastianBergmann\Comparator\ComparisonFailure; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ abstract class Constraint implements Countable, SelfDescribing { /** * Evaluates the constraint for parameter $other. * * If $returnResult is set to false (the default), an exception is thrown * in case of a failure. null is returned otherwise. * * If $returnResult is true, the result of the evaluation is returned as * a boolean value instead: true in case of success, false in case of a * failure. * * @throws ExpectationFailedException */ public function evaluate(mixed $other, string $description = '', bool $returnResult = false): ?bool { $success = false; if ($this->matches($other)) { $success = true; } if ($returnResult) { return $success; } if (!$success) { $this->fail($other, $description); } return null; } /** * Counts the number of constraint elements. */ public function count(): int { return 1; } /** * @deprecated */ protected function exporter(): \SebastianBergmann\Exporter\Exporter { return new \SebastianBergmann\Exporter\Exporter; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. * * This method can be overridden to implement the evaluation algorithm. */ protected function matches(mixed $other): bool { return false; } /** * Throws an exception for the given compared value and test description. * * @throws ExpectationFailedException */ protected function fail(mixed $other, string $description, ComparisonFailure $comparisonFailure = null): never { $failureDescription = sprintf( 'Failed asserting that %s.', $this->failureDescription($other), ); $additionalFailureDescription = $this->additionalFailureDescription($other); if ($additionalFailureDescription) { $failureDescription .= "\n" . $additionalFailureDescription; } if (!empty($description)) { $failureDescription = $description . "\n" . $failureDescription; } throw new ExpectationFailedException( $failureDescription, $comparisonFailure, ); } /** * Return additional failure description where needed. * * The function can be overridden to provide additional failure * information like a diff */ protected function additionalFailureDescription(mixed $other): string { return ''; } /** * Returns the description of the failure. * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. * * To provide additional failure information additionalFailureDescription * can be used. */ protected function failureDescription(mixed $other): string { return Exporter::export($other, true) . ' ' . $this->toString(true); } /** * Returns a custom string representation of the constraint object when it * appears in context of an $operator expression. * * The purpose of this method is to provide meaningful descriptive string * in context of operators such as LogicalNot. Native PHPUnit constraints * are supported out of the box by LogicalNot, but externally developed * ones had no way to provide correct strings in this context. * * The method shall return empty string, when it does not handle * customization by itself. */ protected function toStringInContext(Operator $operator, mixed $role): string { return ''; } /** * Returns the description of the failure when this constraint appears in * context of an $operator expression. * * The purpose of this method is to provide meaningful failure description * in context of operators such as LogicalNot. Native PHPUnit constraints * are supported out of the box by LogicalNot, but externally developed * ones had no way to provide correct messages in this context. * * The method shall return empty string, when it does not handle * customization by itself. */ protected function failureDescriptionInContext(Operator $operator, mixed $role, mixed $other): string { $string = $this->toStringInContext($operator, $role); if ($string === '') { return ''; } return Exporter::export($other, true) . ' ' . $string; } /** * Reduces the sub-expression starting at $this by skipping degenerate * sub-expression and returns first descendant constraint that starts * a non-reducible sub-expression. * * Returns $this for terminal constraints and for operators that start * non-reducible sub-expression, or the nearest descendant of $this that * starts a non-reducible sub-expression. * * A constraint expression may be modelled as a tree with non-terminal * nodes (operators) and terminal nodes. For example: * * LogicalOr (operator, non-terminal) * + LogicalAnd (operator, non-terminal) * | + IsType('int') (terminal) * | + GreaterThan(10) (terminal) * + LogicalNot (operator, non-terminal) * + IsType('array') (terminal) * * A degenerate sub-expression is a part of the tree, that effectively does * not contribute to the evaluation of the expression it appears in. An example * of degenerate sub-expression is a BinaryOperator constructed with single * operand or nested BinaryOperators, each with single operand. An * expression involving a degenerate sub-expression is equivalent to a * reduced expression with the degenerate sub-expression removed, for example * * LogicalAnd (operator) * + LogicalOr (degenerate operator) * | + LogicalAnd (degenerate operator) * | + IsType('int') (terminal) * + GreaterThan(10) (terminal) * * is equivalent to * * LogicalAnd (operator) * + IsType('int') (terminal) * + GreaterThan(10) (terminal) * * because the subexpression * * + LogicalOr * + LogicalAnd * + - * * is degenerate. Calling reduce() on the LogicalOr object above, as well * as on LogicalAnd, shall return the IsType('int') instance. * * Other specific reductions can be implemented, for example cascade of * LogicalNot operators * * + LogicalNot * + LogicalNot * +LogicalNot * + IsTrue * * can be reduced to * * LogicalNot * + IsTrue */ protected function reduce(): self { return $this; } /** * @psalm-return non-empty-string */ protected function valueToTypeStringFragment(mixed $value): string { $type = strtolower(gettype($value)); if ($type === 'double') { $type = 'float'; } if ($type === 'resource (closed)') { $type = 'closed resource'; } return match ($type) { 'array', 'integer', 'object' => 'an ' . $type . ' ', 'boolean', 'closed resource', 'float', 'resource', 'string' => 'a ' . $type . ' ', 'null' => 'null ', default => 'a value of ' . $type . ' ', }; } } Constraint/Boolean/IsTrue.php 0000644 00000001475 15107326342 0012205 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsTrue extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is true'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return $other === true; } } Constraint/Boolean/IsFalse.php 0000644 00000001500 15107326342 0012305 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsFalse extends Constraint { /** * Returns a string representation of the constraint. */ public function toString(): string { return 'is false'; } /** * Evaluates the constraint for parameter $other. Returns true if the * constraint is met, false otherwise. */ protected function matches(mixed $other): bool { return $other === false; } } Constraint/Equality/IsEqualIgnoringCase.php 0000644 00000005554 15107326342 0015046 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_string; use function sprintf; use function str_contains; use function trim; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Util\Exporter; use SebastianBergmann\Comparator\ComparisonFailure; use SebastianBergmann\Comparator\Factory as ComparatorFactory; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsEqualIgnoringCase extends Constraint { private readonly mixed $value; public function __construct(mixed $value) { $this->value = $value; } /** * Evaluates the constraint for parameter $other. * * If $returnResult is set to false (the default), an exception is thrown * in case of a failure. null is returned otherwise. * * If $returnResult is true, the result of the evaluation is returned as * a boolean value instead: true in case of success, false in case of a * failure. * * @throws ExpectationFailedException */ public function evaluate(mixed $other, string $description = '', bool $returnResult = false): ?bool { // If $this->value and $other are identical, they are also equal. // This is the most common path and will allow us to skip // initialization of all the comparators. if ($this->value === $other) { return true; } $comparatorFactory = ComparatorFactory::getInstance(); try { $comparator = $comparatorFactory->getComparatorFor( $this->value, $other, ); $comparator->assertEquals( $this->value, $other, 0.0, false, true, ); } catch (ComparisonFailure $f) { if ($returnResult) { return false; } throw new ExpectationFailedException( trim($description . "\n" . $f->getMessage()), $f, ); } return true; } /** * Returns a string representation of the constraint. */ public function toString(bool $exportObjects = false): string { if (is_string($this->value)) { if (str_contains($this->value, "\n")) { return 'is equal to <text>'; } return sprintf( "is equal to '%s'", $this->value, ); } return sprintf( 'is equal to %s', Exporter::export($this->value, $exportObjects), ); } } Constraint/Equality/IsEqualCanonicalizing.php 0000644 00000005556 15107326342 0015430 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_string; use function sprintf; use function str_contains; use function trim; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Util\Exporter; use SebastianBergmann\Comparator\ComparisonFailure; use SebastianBergmann\Comparator\Factory as ComparatorFactory; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsEqualCanonicalizing extends Constraint { private readonly mixed $value; public function __construct(mixed $value) { $this->value = $value; } /** * Evaluates the constraint for parameter $other. * * If $returnResult is set to false (the default), an exception is thrown * in case of a failure. null is returned otherwise. * * If $returnResult is true, the result of the evaluation is returned as * a boolean value instead: true in case of success, false in case of a * failure. * * @throws ExpectationFailedException */ public function evaluate(mixed $other, string $description = '', bool $returnResult = false): ?bool { // If $this->value and $other are identical, they are also equal. // This is the most common path and will allow us to skip // initialization of all the comparators. if ($this->value === $other) { return true; } $comparatorFactory = ComparatorFactory::getInstance(); try { $comparator = $comparatorFactory->getComparatorFor( $this->value, $other, ); $comparator->assertEquals( $this->value, $other, 0.0, true, false, ); } catch (ComparisonFailure $f) { if ($returnResult) { return false; } throw new ExpectationFailedException( trim($description . "\n" . $f->getMessage()), $f, ); } return true; } /** * Returns a string representation of the constraint. */ public function toString(bool $exportObjects = false): string { if (is_string($this->value)) { if (str_contains($this->value, "\n")) { return 'is equal to <text>'; } return sprintf( "is equal to '%s'", $this->value, ); } return sprintf( 'is equal to %s', Exporter::export($this->value, $exportObjects), ); } } Constraint/Equality/IsEqual.php 0000644 00000006615 15107326342 0012554 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function is_string; use function sprintf; use function str_contains; use function trim; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Util\Exporter; use SebastianBergmann\Comparator\ComparisonFailure; use SebastianBergmann\Comparator\Factory as ComparatorFactory; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsEqual extends Constraint { private readonly mixed $value; private readonly float $delta; private readonly bool $canonicalize; private readonly bool $ignoreCase; public function __construct(mixed $value, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false) { $this->value = $value; $this->delta = $delta; $this->canonicalize = $canonicalize; $this->ignoreCase = $ignoreCase; } /** * Evaluates the constraint for parameter $other. * * If $returnResult is set to false (the default), an exception is thrown * in case of a failure. null is returned otherwise. * * If $returnResult is true, the result of the evaluation is returned as * a boolean value instead: true in case of success, false in case of a * failure. * * @throws ExpectationFailedException */ public function evaluate(mixed $other, string $description = '', bool $returnResult = false): ?bool { // If $this->value and $other are identical, they are also equal. // This is the most common path and will allow us to skip // initialization of all the comparators. if ($this->value === $other) { return true; } $comparatorFactory = ComparatorFactory::getInstance(); try { $comparator = $comparatorFactory->getComparatorFor( $this->value, $other, ); $comparator->assertEquals( $this->value, $other, $this->delta, $this->canonicalize, $this->ignoreCase, ); } catch (ComparisonFailure $f) { if ($returnResult) { return false; } throw new ExpectationFailedException( trim($description . "\n" . $f->getMessage()), $f, ); } return true; } /** * Returns a string representation of the constraint. */ public function toString(bool $exportObjects = false): string { $delta = ''; if (is_string($this->value)) { if (str_contains($this->value, "\n")) { return 'is equal to <text>'; } return sprintf( "is equal to '%s'", $this->value, ); } if ($this->delta != 0) { $delta = sprintf( ' with delta <%F>', $this->delta, ); } return sprintf( 'is equal to %s%s', Exporter::export($this->value, $exportObjects), $delta, ); } } Constraint/Equality/IsEqualWithDelta.php 0000644 00000005175 15107326342 0014362 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Constraint; use function sprintf; use function trim; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Util\Exporter; use SebastianBergmann\Comparator\ComparisonFailure; use SebastianBergmann\Comparator\Factory as ComparatorFactory; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class IsEqualWithDelta extends Constraint { private readonly mixed $value; private readonly float $delta; public function __construct(mixed $value, float $delta) { $this->value = $value; $this->delta = $delta; } /** * Evaluates the constraint for parameter $other. * * If $returnResult is set to false (the default), an exception is thrown * in case of a failure. null is returned otherwise. * * If $returnResult is true, the result of the evaluation is returned as * a boolean value instead: true in case of success, false in case of a * failure. * * @throws ExpectationFailedException */ public function evaluate(mixed $other, string $description = '', bool $returnResult = false): ?bool { // If $this->value and $other are identical, they are also equal. // This is the most common path and will allow us to skip // initialization of all the comparators. if ($this->value === $other) { return true; } $comparatorFactory = ComparatorFactory::getInstance(); try { $comparator = $comparatorFactory->getComparatorFor( $this->value, $other, ); $comparator->assertEquals( $this->value, $other, $this->delta, ); } catch (ComparisonFailure $f) { if ($returnResult) { return false; } throw new ExpectationFailedException( trim($description . "\n" . $f->getMessage()), $f, ); } return true; } /** * Returns a string representation of the constraint. */ public function toString(bool $exportObjects = false): string { return sprintf( 'is equal to %s with delta <%F>', Exporter::export($this->value, $exportObjects), $this->delta, ); } } TestSuiteIterator.php 0000644 00000003367 15107326342 0010734 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function assert; use function count; use RecursiveIterator; /** * @template-implements RecursiveIterator<int, Test> * * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class TestSuiteIterator implements RecursiveIterator { private int $position = 0; /** * @psalm-var list<Test> */ private readonly array $tests; public function __construct(TestSuite $testSuite) { $this->tests = $testSuite->tests(); } public function rewind(): void { $this->position = 0; } public function valid(): bool { return $this->position < count($this->tests); } public function key(): int { return $this->position; } public function current(): Test { return $this->tests[$this->position]; } public function next(): void { $this->position++; } /** * @throws NoChildTestSuiteException */ public function getChildren(): self { if (!$this->hasChildren()) { throw new NoChildTestSuiteException( 'The current item is not a TestSuite instance and therefore does not have any children.', ); } $current = $this->current(); assert($current instanceof TestSuite); return new self($current); } public function hasChildren(): bool { return $this->valid() && $this->current() instanceof TestSuite; } } TestSize/Medium.php 0000644 00000001366 15107326342 0010260 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestSize; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Medium extends Known { /** * @psalm-assert-if-true Medium $this */ public function isMedium(): bool { return true; } public function isGreaterThan(TestSize $other): bool { return $other->isSmall(); } public function asString(): string { return 'medium'; } } TestSize/Known.php 0000644 00000001204 15107326342 0010123 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestSize; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ abstract class Known extends TestSize { /** * @psalm-assert-if-true Known $this */ public function isKnown(): bool { return true; } abstract public function isGreaterThan(self $other): bool; } TestSize/TestSize.php 0000644 00000002665 15107326342 0010615 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestSize; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ abstract class TestSize { public static function unknown(): self { return new Unknown; } public static function small(): self { return new Small; } public static function medium(): self { return new Medium; } public static function large(): self { return new Large; } /** * @psalm-assert-if-true Known $this */ public function isKnown(): bool { return false; } /** * @psalm-assert-if-true Unknown $this */ public function isUnknown(): bool { return false; } /** * @psalm-assert-if-true Small $this */ public function isSmall(): bool { return false; } /** * @psalm-assert-if-true Medium $this */ public function isMedium(): bool { return false; } /** * @psalm-assert-if-true Large $this */ public function isLarge(): bool { return false; } abstract public function asString(): string; } TestSize/Unknown.php 0000644 00000001225 15107326342 0010471 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestSize; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Unknown extends TestSize { /** * @psalm-assert-if-true Unknown $this */ public function isUnknown(): bool { return true; } public function asString(): string { return 'unknown'; } } TestSize/Large.php 0000644 00000001363 15107326342 0010067 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestSize; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Large extends Known { /** * @psalm-assert-if-true Large $this */ public function isLarge(): bool { return true; } public function isGreaterThan(TestSize $other): bool { return !$other->isLarge(); } public function asString(): string { return 'large'; } } TestSize/Small.php 0000644 00000001346 15107326342 0010106 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestSize; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Small extends Known { /** * @psalm-assert-if-true Small $this */ public function isSmall(): bool { return true; } public function isGreaterThan(TestSize $other): bool { return false; } public function asString(): string { return 'small'; } } TestBuilder.php 0000644 00000023433 15107326342 0007513 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function assert; use PHPUnit\Metadata\Api\DataProvider; use PHPUnit\Metadata\Api\Groups; use PHPUnit\Metadata\BackupGlobals; use PHPUnit\Metadata\BackupStaticProperties; use PHPUnit\Metadata\ExcludeGlobalVariableFromBackup; use PHPUnit\Metadata\ExcludeStaticPropertyFromBackup; use PHPUnit\Metadata\Parser\Registry as MetadataRegistry; use PHPUnit\Metadata\PreserveGlobalState; use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry; use ReflectionClass; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class TestBuilder { /** * @psalm-param non-empty-string $methodName * * @throws InvalidDataProviderException */ public function build(ReflectionClass $theClass, string $methodName): Test { $className = $theClass->getName(); $data = (new DataProvider)->providedData( $className, $methodName, ); if ($data !== null) { return $this->buildDataProviderTestSuite( $methodName, $className, $data, $this->shouldTestMethodBeRunInSeparateProcess($className, $methodName), $this->shouldGlobalStateBePreserved($className, $methodName), $this->shouldAllTestMethodsOfTestClassBeRunInSingleSeparateProcess($className), $this->backupSettings($className, $methodName), ); } $test = new $className($methodName); assert($test instanceof TestCase); $this->configureTestCase( $test, $this->shouldTestMethodBeRunInSeparateProcess($className, $methodName), $this->shouldGlobalStateBePreserved($className, $methodName), $this->shouldAllTestMethodsOfTestClassBeRunInSingleSeparateProcess($className), $this->backupSettings($className, $methodName), ); return $test; } /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName * @psalm-param array{backupGlobals: ?bool, backupGlobalsExcludeList: list<string>, backupStaticProperties: ?bool, backupStaticPropertiesExcludeList: array<string,list<string>>} $backupSettings */ private function buildDataProviderTestSuite(string $methodName, string $className, array $data, bool $runTestInSeparateProcess, ?bool $preserveGlobalState, bool $runClassInSeparateProcess, array $backupSettings): DataProviderTestSuite { $dataProviderTestSuite = DataProviderTestSuite::empty( $className . '::' . $methodName, ); $groups = (new Groups)->groups($className, $methodName); foreach ($data as $_dataName => $_data) { $_test = new $className($methodName); assert($_test instanceof TestCase); $_test->setData($_dataName, $_data); $this->configureTestCase( $_test, $runTestInSeparateProcess, $preserveGlobalState, $runClassInSeparateProcess, $backupSettings, ); $dataProviderTestSuite->addTest($_test, $groups); } return $dataProviderTestSuite; } /** * @psalm-param array{backupGlobals: ?bool, backupGlobalsExcludeList: list<string>, backupStaticProperties: ?bool, backupStaticPropertiesExcludeList: array<string,list<string>>} $backupSettings */ private function configureTestCase(TestCase $test, bool $runTestInSeparateProcess, ?bool $preserveGlobalState, bool $runClassInSeparateProcess, array $backupSettings): void { if ($runTestInSeparateProcess) { $test->setRunTestInSeparateProcess(true); } if ($runClassInSeparateProcess) { $test->setRunClassInSeparateProcess(true); } if ($preserveGlobalState !== null) { $test->setPreserveGlobalState($preserveGlobalState); } if ($backupSettings['backupGlobals'] !== null) { $test->setBackupGlobals($backupSettings['backupGlobals']); } else { $test->setBackupGlobals(ConfigurationRegistry::get()->backupGlobals()); } $test->setBackupGlobalsExcludeList($backupSettings['backupGlobalsExcludeList']); if ($backupSettings['backupStaticProperties'] !== null) { $test->setBackupStaticProperties($backupSettings['backupStaticProperties']); } else { $test->setBackupStaticProperties(ConfigurationRegistry::get()->backupStaticProperties()); } $test->setBackupStaticPropertiesExcludeList($backupSettings['backupStaticPropertiesExcludeList']); } /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName * * @psalm-return array{backupGlobals: ?bool, backupGlobalsExcludeList: list<string>, backupStaticProperties: ?bool, backupStaticPropertiesExcludeList: array<string,list<string>>} */ private function backupSettings(string $className, string $methodName): array { $metadataForClass = MetadataRegistry::parser()->forClass($className); $metadataForMethod = MetadataRegistry::parser()->forMethod($className, $methodName); $metadataForClassAndMethod = MetadataRegistry::parser()->forClassAndMethod($className, $methodName); $backupGlobals = null; $backupGlobalsExcludeList = []; if ($metadataForMethod->isBackupGlobals()->isNotEmpty()) { $metadata = $metadataForMethod->isBackupGlobals()->asArray()[0]; assert($metadata instanceof BackupGlobals); if ($metadata->enabled()) { $backupGlobals = true; } } elseif ($metadataForClass->isBackupGlobals()->isNotEmpty()) { $metadata = $metadataForClass->isBackupGlobals()->asArray()[0]; assert($metadata instanceof BackupGlobals); if ($metadata->enabled()) { $backupGlobals = true; } } foreach ($metadataForClassAndMethod->isExcludeGlobalVariableFromBackup() as $metadata) { assert($metadata instanceof ExcludeGlobalVariableFromBackup); $backupGlobalsExcludeList[] = $metadata->globalVariableName(); } $backupStaticProperties = null; $backupStaticPropertiesExcludeList = []; if ($metadataForMethod->isBackupStaticProperties()->isNotEmpty()) { $metadata = $metadataForMethod->isBackupStaticProperties()->asArray()[0]; assert($metadata instanceof BackupStaticProperties); if ($metadata->enabled()) { $backupStaticProperties = true; } } elseif ($metadataForClass->isBackupStaticProperties()->isNotEmpty()) { $metadata = $metadataForClass->isBackupStaticProperties()->asArray()[0]; assert($metadata instanceof BackupStaticProperties); if ($metadata->enabled()) { $backupStaticProperties = true; } } foreach ($metadataForClassAndMethod->isExcludeStaticPropertyFromBackup() as $metadata) { assert($metadata instanceof ExcludeStaticPropertyFromBackup); if (!isset($backupStaticPropertiesExcludeList[$metadata->className()])) { $backupStaticPropertiesExcludeList[$metadata->className()] = []; } $backupStaticPropertiesExcludeList[$metadata->className()][] = $metadata->propertyName(); } return [ 'backupGlobals' => $backupGlobals, 'backupGlobalsExcludeList' => $backupGlobalsExcludeList, 'backupStaticProperties' => $backupStaticProperties, 'backupStaticPropertiesExcludeList' => $backupStaticPropertiesExcludeList, ]; } /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ private function shouldGlobalStateBePreserved(string $className, string $methodName): ?bool { $metadataForMethod = MetadataRegistry::parser()->forMethod($className, $methodName); if ($metadataForMethod->isPreserveGlobalState()->isNotEmpty()) { $metadata = $metadataForMethod->isPreserveGlobalState()->asArray()[0]; assert($metadata instanceof PreserveGlobalState); return $metadata->enabled(); } $metadataForClass = MetadataRegistry::parser()->forClass($className); if ($metadataForClass->isPreserveGlobalState()->isNotEmpty()) { $metadata = $metadataForClass->isPreserveGlobalState()->asArray()[0]; assert($metadata instanceof PreserveGlobalState); return $metadata->enabled(); } return null; } /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ private function shouldTestMethodBeRunInSeparateProcess(string $className, string $methodName): bool { if (MetadataRegistry::parser()->forClass($className)->isRunTestsInSeparateProcesses()->isNotEmpty()) { return true; } if (MetadataRegistry::parser()->forMethod($className, $methodName)->isRunInSeparateProcess()->isNotEmpty()) { return true; } return false; } /** * @psalm-param class-string $className */ private function shouldAllTestMethodsOfTestClassBeRunInSingleSeparateProcess(string $className): bool { return MetadataRegistry::parser()->forClass($className)->isRunClassInSeparateProcess()->isNotEmpty(); } } MockObject/ConfigurableMethod.php 0000644 00000002235 15107326342 0013043 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use SebastianBergmann\Type\Type; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ConfigurableMethod { /** * @psalm-var non-empty-string */ private readonly string $name; private readonly Type $returnType; /** * @psalm-param non-empty-string $name */ public function __construct(string $name, Type $returnType) { $this->name = $name; $this->returnType = $returnType; } /** * @psalm-return non-empty-string */ public function name(): string { return $this->name; } public function mayReturn(mixed $value): bool { return $this->returnType->isAssignable(Type::fromValue($value, false)); } public function returnTypeDeclaration(): string { return $this->returnType->asString(); } } MockObject/Exception/BadMethodCallException.php 0000644 00000000743 15107326342 0015544 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class BadMethodCallException extends \BadMethodCallException implements Exception { } MockObject/Exception/MethodNameAlreadyConfiguredException.php 0000644 00000001146 15107326342 0020450 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MethodNameAlreadyConfiguredException extends \PHPUnit\Framework\Exception implements Exception { public function __construct() { parent::__construct('Method name is already configured'); } } MockObject/Exception/MatcherAlreadyRegisteredException.php 0000644 00000001341 15107326342 0020017 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MatcherAlreadyRegisteredException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $id) { parent::__construct( sprintf( 'Matcher with id <%s> is already registered', $id, ), ); } } MockObject/Exception/IncompatibleReturnValueException.php 0000644 00000001642 15107326342 0017723 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function get_debug_type; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class IncompatibleReturnValueException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(ConfigurableMethod $method, mixed $value) { parent::__construct( sprintf( 'Method %s may not return value of type %s, its declared return type is "%s"', $method->name(), get_debug_type($value), $method->returnTypeDeclaration(), ), ); } } MockObject/Exception/MethodCannotBeConfiguredException.php 0000644 00000001503 15107326342 0017754 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MethodCannotBeConfiguredException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $method) { parent::__construct( sprintf( 'Trying to configure method "%s" which cannot be configured because it does not exist, has not been specified, is final, or is static', $method, ), ); } } MockObject/Exception/Exception.php 0000644 00000000701 15107326342 0013172 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use Throwable; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface Exception extends Throwable { } MockObject/Exception/MethodNameNotConfiguredException.php 0000644 00000001136 15107326342 0017626 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MethodNameNotConfiguredException extends \PHPUnit\Framework\Exception implements Exception { public function __construct() { parent::__construct('Method name is not configured'); } } MockObject/Exception/RuntimeException.php 0000644 00000000727 15107326342 0014546 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class RuntimeException extends \RuntimeException implements Exception { } MockObject/Exception/MethodParametersAlreadyConfiguredException.php 0000644 00000001157 15107326342 0021675 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MethodParametersAlreadyConfiguredException extends \PHPUnit\Framework\Exception implements Exception { public function __construct() { parent::__construct('Method parameters already configured'); } } MockObject/Exception/NeverReturningMethodException.php 0000644 00000001644 15107326342 0017240 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function sprintf; use RuntimeException; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class NeverReturningMethodException extends RuntimeException implements Exception { /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ public function __construct(string $className, string $methodName) { parent::__construct( sprintf( 'Method %s::%s() is declared to never return', $className, $methodName, ), ); } } MockObject/Exception/CannotUseOnlyMethodsException.php 0000644 00000001477 15107326342 0017213 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class CannotUseOnlyMethodsException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $type, string $methodName) { parent::__construct( sprintf( 'Trying to configure method "%s" with onlyMethods(), but it does not exist in class "%s"', $methodName, $type, ), ); } } MockObject/Exception/ReturnValueNotConfiguredException.php 0000644 00000001525 15107326342 0020063 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ReturnValueNotConfiguredException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(Invocation $invocation) { parent::__construct( sprintf( 'No return value is configured for %s::%s() and return value generation is disabled', $invocation->className(), $invocation->methodName(), ), ); } } MockObject/Exception/MatchBuilderNotFoundException.php 0000644 00000001351 15107326342 0017135 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MatchBuilderNotFoundException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $id) { parent::__construct( sprintf( 'No builder found for match builder identification <%s>', $id, ), ); } } MockObject/Exception/CannotUseAddMethodsException.php 0000644 00000001554 15107326342 0016756 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class CannotUseAddMethodsException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $type, string $methodName) { parent::__construct( sprintf( 'Trying to configure method "%s" with addMethods(), but it exists in class "%s". Use onlyMethods() for methods that exist in the class', $methodName, $type, ), ); } } MockObject/Exception/ReflectionException.php 0000644 00000000760 15107326342 0015212 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use RuntimeException; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ReflectionException extends RuntimeException implements Exception { } MockObject/MockBuilder.php 0000644 00000030621 15107326342 0011502 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function array_merge; use function assert; use function trait_exists; use PHPUnit\Framework\InvalidArgumentException; use PHPUnit\Framework\MockObject\Generator\ClassAlreadyExistsException; use PHPUnit\Framework\MockObject\Generator\ClassIsEnumerationException; use PHPUnit\Framework\MockObject\Generator\ClassIsFinalException; use PHPUnit\Framework\MockObject\Generator\ClassIsReadonlyException; use PHPUnit\Framework\MockObject\Generator\DuplicateMethodException; use PHPUnit\Framework\MockObject\Generator\Generator; use PHPUnit\Framework\MockObject\Generator\InvalidMethodNameException; use PHPUnit\Framework\MockObject\Generator\OriginalConstructorInvocationRequiredException; use PHPUnit\Framework\MockObject\Generator\ReflectionException; use PHPUnit\Framework\MockObject\Generator\RuntimeException; use PHPUnit\Framework\MockObject\Generator\UnknownTypeException; use PHPUnit\Framework\TestCase; use ReflectionClass; /** * @psalm-template MockedType * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class MockBuilder { private readonly TestCase $testCase; /** * @psalm-var class-string|trait-string */ private readonly string $type; /** * @psalm-var list<non-empty-string> */ private array $methods = []; private bool $emptyMethodsArray = false; /** * @psalm-var ?class-string */ private ?string $mockClassName = null; private array $constructorArgs = []; private bool $originalConstructor = true; private bool $originalClone = true; private bool $autoload = true; private bool $cloneArguments = false; private bool $callOriginalMethods = false; private ?object $proxyTarget = null; private bool $allowMockingUnknownTypes = true; private bool $returnValueGeneration = true; private readonly Generator $generator; /** * @psalm-param class-string|trait-string $type */ public function __construct(TestCase $testCase, string $type) { $this->testCase = $testCase; $this->type = $type; $this->generator = new Generator; } /** * Creates a mock object using a fluent interface. * * @throws ClassAlreadyExistsException * @throws ClassIsEnumerationException * @throws ClassIsFinalException * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws InvalidArgumentException * @throws InvalidMethodNameException * @throws OriginalConstructorInvocationRequiredException * @throws ReflectionException * @throws RuntimeException * @throws UnknownTypeException * * @psalm-return MockObject&MockedType */ public function getMock(): MockObject { $object = $this->generator->testDouble( $this->type, true, !$this->emptyMethodsArray ? $this->methods : null, $this->constructorArgs, $this->mockClassName ?? '', $this->originalConstructor, $this->originalClone, $this->autoload, $this->cloneArguments, $this->callOriginalMethods, $this->proxyTarget, $this->allowMockingUnknownTypes, $this->returnValueGeneration, ); assert($object instanceof $this->type); assert($object instanceof MockObject); $this->testCase->registerMockObject($object); return $object; } /** * Creates a mock object for an abstract class using a fluent interface. * * @psalm-return MockObject&MockedType * * @throws \PHPUnit\Framework\Exception * @throws ReflectionException * @throws RuntimeException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5305 */ public function getMockForAbstractClass(): MockObject { $object = $this->generator->mockObjectForAbstractClass( $this->type, $this->constructorArgs, $this->mockClassName ?? '', $this->originalConstructor, $this->originalClone, $this->autoload, $this->methods, $this->cloneArguments, ); assert($object instanceof MockObject); $this->testCase->registerMockObject($object); return $object; } /** * Creates a mock object for a trait using a fluent interface. * * @psalm-return MockObject&MockedType * * @throws \PHPUnit\Framework\Exception * @throws ReflectionException * @throws RuntimeException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5306 */ public function getMockForTrait(): MockObject { assert(trait_exists($this->type)); $object = $this->generator->mockObjectForTrait( $this->type, $this->constructorArgs, $this->mockClassName ?? '', $this->originalConstructor, $this->originalClone, $this->autoload, $this->methods, $this->cloneArguments, ); assert($object instanceof MockObject); $this->testCase->registerMockObject($object); return $object; } /** * Specifies the subset of methods to mock, requiring each to exist in the class. * * @psalm-param list<non-empty-string> $methods * * @throws CannotUseOnlyMethodsException * @throws ReflectionException * * @return $this */ public function onlyMethods(array $methods): self { if (empty($methods)) { $this->emptyMethodsArray = true; return $this; } try { $reflector = new ReflectionClass($this->type); // @codeCoverageIgnoreStart } catch (\ReflectionException $e) { throw new ReflectionException( $e->getMessage(), $e->getCode(), $e, ); // @codeCoverageIgnoreEnd } foreach ($methods as $method) { if (!$reflector->hasMethod($method)) { throw new CannotUseOnlyMethodsException($this->type, $method); } } $this->methods = array_merge($this->methods, $methods); return $this; } /** * Specifies methods that don't exist in the class which you want to mock. * * @psalm-param list<non-empty-string> $methods * * @throws CannotUseAddMethodsException * @throws ReflectionException * @throws RuntimeException * * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5320 */ public function addMethods(array $methods): self { if (empty($methods)) { $this->emptyMethodsArray = true; return $this; } try { $reflector = new ReflectionClass($this->type); // @codeCoverageIgnoreStart } catch (\ReflectionException $e) { throw new ReflectionException( $e->getMessage(), $e->getCode(), $e, ); // @codeCoverageIgnoreEnd } foreach ($methods as $method) { if ($reflector->hasMethod($method)) { throw new CannotUseAddMethodsException($this->type, $method); } } $this->methods = array_merge($this->methods, $methods); return $this; } /** * Specifies the arguments for the constructor. * * @return $this */ public function setConstructorArgs(array $arguments): self { $this->constructorArgs = $arguments; return $this; } /** * Specifies the name for the mock class. * * @psalm-param class-string $name * * @return $this */ public function setMockClassName(string $name): self { $this->mockClassName = $name; return $this; } /** * Disables the invocation of the original constructor. * * @return $this */ public function disableOriginalConstructor(): self { $this->originalConstructor = false; return $this; } /** * Enables the invocation of the original constructor. * * @return $this */ public function enableOriginalConstructor(): self { $this->originalConstructor = true; return $this; } /** * Disables the invocation of the original clone constructor. * * @return $this */ public function disableOriginalClone(): self { $this->originalClone = false; return $this; } /** * Enables the invocation of the original clone constructor. * * @return $this */ public function enableOriginalClone(): self { $this->originalClone = true; return $this; } /** * Disables the use of class autoloading while creating the mock object. * * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5309 */ public function disableAutoload(): self { $this->autoload = false; return $this; } /** * Enables the use of class autoloading while creating the mock object. * * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5309 */ public function enableAutoload(): self { $this->autoload = true; return $this; } /** * Disables the cloning of arguments passed to mocked methods. * * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5315 */ public function disableArgumentCloning(): self { $this->cloneArguments = false; return $this; } /** * Enables the cloning of arguments passed to mocked methods. * * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5315 */ public function enableArgumentCloning(): self { $this->cloneArguments = true; return $this; } /** * Enables the invocation of the original methods. * * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5307 */ public function enableProxyingToOriginalMethods(): self { $this->callOriginalMethods = true; return $this; } /** * Disables the invocation of the original methods. * * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5307 */ public function disableProxyingToOriginalMethods(): self { $this->callOriginalMethods = false; $this->proxyTarget = null; return $this; } /** * Sets the proxy target. * * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5307 */ public function setProxyTarget(object $object): self { $this->proxyTarget = $object; return $this; } /** * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5308 */ public function allowMockingUnknownTypes(): self { $this->allowMockingUnknownTypes = true; return $this; } /** * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5308 */ public function disallowMockingUnknownTypes(): self { $this->allowMockingUnknownTypes = false; return $this; } /** * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5421 */ public function enableAutoReturnValueGeneration(): self { $this->returnValueGeneration = true; return $this; } /** * @return $this * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5421 */ public function disableAutoReturnValueGeneration(): self { $this->returnValueGeneration = false; return $this; } } MockObject/Generator/MockTrait.php 0000644 00000002151 15107326342 0013122 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function class_exists; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5243 */ final class MockTrait implements MockType { private readonly string $classCode; /** * @psalm-var class-string */ private readonly string $mockName; /** * @psalm-param class-string $mockName */ public function __construct(string $classCode, string $mockName) { $this->classCode = $classCode; $this->mockName = $mockName; } /** * @psalm-return class-string */ public function generate(): string { if (!class_exists($this->mockName, false)) { eval($this->classCode); } return $this->mockName; } } MockObject/Generator/MockClass.php 0000644 00000003276 15107326342 0013115 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function call_user_func; use function class_exists; use PHPUnit\Framework\MockObject\ConfigurableMethod; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MockClass implements MockType { private readonly string $classCode; /** * @psalm-var class-string */ private readonly string $mockName; /** * @psalm-var list<ConfigurableMethod> */ private readonly array $configurableMethods; /** * @psalm-param class-string $mockName * @psalm-param list<ConfigurableMethod> $configurableMethods */ public function __construct(string $classCode, string $mockName, array $configurableMethods) { $this->classCode = $classCode; $this->mockName = $mockName; $this->configurableMethods = $configurableMethods; } /** * @psalm-return class-string */ public function generate(): string { if (!class_exists($this->mockName, false)) { eval($this->classCode); call_user_func( [ $this->mockName, '__phpunit_initConfigurableMethods', ], ...$this->configurableMethods, ); } return $this->mockName; } public function classCode(): string { return $this->classCode; } } MockObject/Generator/MockMethodSet.php 0000644 00000002110 15107326342 0013726 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function array_key_exists; use function array_values; use function strtolower; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MockMethodSet { /** * @psalm-var array<string,MockMethod> */ private array $methods = []; public function addMethods(MockMethod ...$methods): void { foreach ($methods as $method) { $this->methods[strtolower($method->methodName())] = $method; } } /** * @psalm-return list<MockMethod> */ public function asArray(): array { return array_values($this->methods); } public function hasMethod(string $methodName): bool { return array_key_exists(strtolower($methodName), $this->methods); } } MockObject/Generator/MockMethod.php 0000644 00000024050 15107326342 0013261 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function explode; use function implode; use function is_object; use function is_string; use function preg_match; use function preg_replace; use function sprintf; use function strlen; use function strpos; use function substr; use function substr_count; use function trim; use function var_export; use ReflectionMethod; use ReflectionParameter; use SebastianBergmann\Type\ReflectionMapper; use SebastianBergmann\Type\Type; use SebastianBergmann\Type\UnknownType; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MockMethod { use TemplateLoader; /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-var non-empty-string */ private readonly string $methodName; private readonly bool $cloneArguments; private readonly string $modifier; private readonly string $argumentsForDeclaration; private readonly string $argumentsForCall; private readonly Type $returnType; private readonly string $reference; private readonly bool $callOriginalMethod; private readonly bool $static; private readonly ?string $deprecation; /** * @throws ReflectionException * @throws RuntimeException */ public static function fromReflection(ReflectionMethod $method, bool $callOriginalMethod, bool $cloneArguments): self { if ($method->isPrivate()) { $modifier = 'private'; } elseif ($method->isProtected()) { $modifier = 'protected'; } else { $modifier = 'public'; } if ($method->isStatic()) { $modifier .= ' static'; } if ($method->returnsReference()) { $reference = '&'; } else { $reference = ''; } $docComment = $method->getDocComment(); if (is_string($docComment) && preg_match('#\*[ \t]*+@deprecated[ \t]*+(.*?)\r?+\n[ \t]*+\*(?:[ \t]*+@|/$)#s', $docComment, $deprecation)) { $deprecation = trim(preg_replace('#[ \t]*\r?\n[ \t]*+\*[ \t]*+#', ' ', $deprecation[1])); } else { $deprecation = null; } return new self( $method->getDeclaringClass()->getName(), $method->getName(), $cloneArguments, $modifier, self::methodParametersForDeclaration($method), self::methodParametersForCall($method), (new ReflectionMapper)->fromReturnType($method), $reference, $callOriginalMethod, $method->isStatic(), $deprecation, ); } /** * @param class-string $className * @param non-empty-string $methodName */ public static function fromName(string $className, string $methodName, bool $cloneArguments): self { return new self( $className, $methodName, $cloneArguments, 'public', '', '', new UnknownType, '', false, false, null, ); } /** * @param class-string $className * @param non-empty-string $methodName */ private function __construct(string $className, string $methodName, bool $cloneArguments, string $modifier, string $argumentsForDeclaration, string $argumentsForCall, Type $returnType, string $reference, bool $callOriginalMethod, bool $static, ?string $deprecation) { $this->className = $className; $this->methodName = $methodName; $this->cloneArguments = $cloneArguments; $this->modifier = $modifier; $this->argumentsForDeclaration = $argumentsForDeclaration; $this->argumentsForCall = $argumentsForCall; $this->returnType = $returnType; $this->reference = $reference; $this->callOriginalMethod = $callOriginalMethod; $this->static = $static; $this->deprecation = $deprecation; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } /** * @throws RuntimeException */ public function generateCode(): string { if ($this->static) { $templateFile = 'doubled_static_method.tpl'; } else { $templateFile = sprintf( '%s_method.tpl', $this->callOriginalMethod ? 'proxied' : 'doubled', ); } $deprecation = $this->deprecation; $returnResult = ''; if (!$this->returnType->isNever() && !$this->returnType->isVoid()) { $returnResult = <<<'EOT' return $__phpunit_result; EOT; } if (null !== $this->deprecation) { $deprecation = "The {$this->className}::{$this->methodName} method is deprecated ({$this->deprecation})."; $deprecationTemplate = $this->loadTemplate('deprecation.tpl'); $deprecationTemplate->setVar( [ 'deprecation' => var_export($deprecation, true), ], ); $deprecation = $deprecationTemplate->render(); } $template = $this->loadTemplate($templateFile); $template->setVar( [ 'arguments_decl' => $this->argumentsForDeclaration, 'arguments_call' => $this->argumentsForCall, 'return_declaration' => !empty($this->returnType->asString()) ? (': ' . $this->returnType->asString()) : '', 'return_type' => $this->returnType->asString(), 'arguments_count' => !empty($this->argumentsForCall) ? substr_count($this->argumentsForCall, ',') + 1 : 0, 'class_name' => $this->className, 'method_name' => $this->methodName, 'modifier' => $this->modifier, 'reference' => $this->reference, 'clone_arguments' => $this->cloneArguments ? 'true' : 'false', 'deprecation' => $deprecation, 'return_result' => $returnResult, ], ); return $template->render(); } public function returnType(): Type { return $this->returnType; } /** * Returns the parameters of a function or method. * * @throws RuntimeException */ private static function methodParametersForDeclaration(ReflectionMethod $method): string { $parameters = []; $types = (new ReflectionMapper)->fromParameterTypes($method); foreach ($method->getParameters() as $i => $parameter) { $name = '$' . $parameter->getName(); /* Note: PHP extensions may use empty names for reference arguments * or "..." for methods taking a variable number of arguments. */ if ($name === '$' || $name === '$...') { $name = '$arg' . $i; } $default = ''; $reference = ''; $typeDeclaration = ''; if (!$types[$i]->type()->isUnknown()) { $typeDeclaration = $types[$i]->type()->asString() . ' '; } if ($parameter->isPassedByReference()) { $reference = '&'; } if ($parameter->isVariadic()) { $name = '...' . $name; } elseif ($parameter->isDefaultValueAvailable()) { $default = ' = ' . self::exportDefaultValue($parameter); } elseif ($parameter->isOptional()) { $default = ' = null'; } $parameters[] = $typeDeclaration . $reference . $name . $default; } return implode(', ', $parameters); } /** * Returns the parameters of a function or method. * * @throws ReflectionException */ private static function methodParametersForCall(ReflectionMethod $method): string { $parameters = []; foreach ($method->getParameters() as $i => $parameter) { $name = '$' . $parameter->getName(); /* Note: PHP extensions may use empty names for reference arguments * or "..." for methods taking a variable number of arguments. */ if ($name === '$' || $name === '$...') { $name = '$arg' . $i; } if ($parameter->isVariadic()) { continue; } if ($parameter->isPassedByReference()) { $parameters[] = '&' . $name; } else { $parameters[] = $name; } } return implode(', ', $parameters); } /** * @throws ReflectionException */ private static function exportDefaultValue(ReflectionParameter $parameter): string { try { $defaultValue = $parameter->getDefaultValue(); if (!is_object($defaultValue)) { return var_export($defaultValue, true); } $parameterAsString = $parameter->__toString(); return explode( ' = ', substr( substr( $parameterAsString, strpos($parameterAsString, '<optional> ') + strlen('<optional> '), ), 0, -2, ), )[1]; // @codeCoverageIgnoreStart } catch (\ReflectionException $e) { throw new ReflectionException( $e->getMessage(), $e->getCode(), $e, ); } // @codeCoverageIgnoreEnd } } MockObject/Generator/MockType.php 0000644 00000001002 15107326342 0012752 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface MockType { /** * @psalm-return class-string */ public function generate(): string; } MockObject/Generator/Exception/ClassAlreadyExistsException.php 0000644 00000001342 15107326342 0020612 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ClassAlreadyExistsException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $className) { parent::__construct( sprintf( 'Class "%s" already exists', $className, ), ); } } MockObject/Generator/Exception/SoapExtensionNotAvailableException.php 0000644 00000001246 15107326342 0022127 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class SoapExtensionNotAvailableException extends \PHPUnit\Framework\Exception implements Exception { public function __construct() { parent::__construct( 'The SOAP extension is required to generate a test double from WSDL', ); } } MockObject/Generator/Exception/Exception.php 0000644 00000001001 15107326342 0015112 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use PHPUnit\Framework\MockObject\Exception as BaseException; /** * @internal This interface is not covered by the backward compatibility promise for PHPUnit */ interface Exception extends BaseException { } MockObject/Generator/Exception/UnknownClassException.php 0000644 00000001334 15107326342 0017471 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class UnknownClassException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $className) { parent::__construct( sprintf( 'Class "%s" does not exist', $className, ), ); } } MockObject/Generator/Exception/ClassIsEnumerationException.php 0000644 00000001373 15107326342 0020617 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ClassIsEnumerationException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $className) { parent::__construct( sprintf( 'Class "%s" is an enumeration and cannot be doubled', $className, ), ); } } MockObject/Generator/Exception/RuntimeException.php 0000644 00000000754 15107326342 0016474 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class RuntimeException extends \PHPUnit\Framework\Exception implements Exception { } MockObject/Generator/Exception/DuplicateMethodException.php 0000644 00000002015 15107326342 0020114 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function array_diff_assoc; use function array_unique; use function implode; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class DuplicateMethodException extends \PHPUnit\Framework\Exception implements Exception { /** * @psalm-param list<string> $methods */ public function __construct(array $methods) { parent::__construct( sprintf( 'Cannot double using a method list that contains duplicates: "%s" (duplicate: "%s")', implode(', ', $methods), implode(', ', array_unique(array_diff_assoc($methods, array_unique($methods)))), ), ); } } MockObject/Generator/Exception/ClassIsFinalException.php 0000644 00000001367 15107326342 0017365 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ClassIsFinalException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $className) { parent::__construct( sprintf( 'Class "%s" is declared "final" and cannot be doubled', $className, ), ); } } MockObject/Generator/Exception/OriginalConstructorInvocationRequiredException.php 0000644 00000001240 15107326342 0024605 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class OriginalConstructorInvocationRequiredException extends \PHPUnit\Framework\Exception implements Exception { public function __construct() { parent::__construct('Proxying to original methods requires invoking the original constructor'); } } MockObject/Generator/Exception/ClassIsReadonlyException.php 0000644 00000001375 15107326342 0020110 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ClassIsReadonlyException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $className) { parent::__construct( sprintf( 'Class "%s" is declared "readonly" and cannot be doubled', $className, ), ); } } MockObject/Generator/Exception/ReflectionException.php 0000644 00000000757 15107326342 0017146 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ReflectionException extends \PHPUnit\Framework\Exception implements Exception { } MockObject/Generator/Exception/InvalidMethodNameException.php 0000644 00000001355 15107326342 0020377 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class InvalidMethodNameException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $method) { parent::__construct( sprintf( 'Cannot double method with invalid name "%s"', $method, ), ); } } MockObject/Generator/Exception/UnknownTypeException.php 0000644 00000001336 15107326342 0017347 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class UnknownTypeException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $type) { parent::__construct( sprintf( 'Class or interface "%s" does not exist', $type, ), ); } } MockObject/Generator/Exception/UnknownTraitException.php 0000644 00000001447 15107326342 0017514 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5243 */ final class UnknownTraitException extends \PHPUnit\Framework\Exception implements Exception { public function __construct(string $traitName) { parent::__construct( sprintf( 'Trait "%s" does not exist', $traitName, ), ); } } MockObject/Generator/Generator.php 0000644 00000103161 15107326342 0013156 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use const PHP_EOL; use const PREG_OFFSET_CAPTURE; use const WSDL_CACHE_NONE; use function array_merge; use function array_pop; use function array_unique; use function assert; use function class_exists; use function count; use function explode; use function extension_loaded; use function implode; use function in_array; use function interface_exists; use function is_array; use function is_object; use function md5; use function method_exists; use function mt_rand; use function preg_match; use function preg_match_all; use function range; use function serialize; use function sort; use function sprintf; use function str_contains; use function str_replace; use function strlen; use function strpos; use function substr; use function trait_exists; use Exception; use Iterator; use IteratorAggregate; use PHPUnit\Framework\InvalidArgumentException; use PHPUnit\Framework\MockObject\ConfigurableMethod; use PHPUnit\Framework\MockObject\DoubledCloneMethod; use PHPUnit\Framework\MockObject\Method; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\MockObjectInternal; use PHPUnit\Framework\MockObject\ProxiedCloneMethod; use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\StubApi; use PHPUnit\Framework\MockObject\StubInternal; use ReflectionClass; use ReflectionMethod; use SoapClient; use SoapFault; use Throwable; use Traversable; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class Generator { use TemplateLoader; /** * @var array */ private const EXCLUDED_METHOD_NAMES = [ '__CLASS__' => true, '__DIR__' => true, '__FILE__' => true, '__FUNCTION__' => true, '__LINE__' => true, '__METHOD__' => true, '__NAMESPACE__' => true, '__TRAIT__' => true, '__clone' => true, '__halt_compiler' => true, ]; /** * @psalm-var array<non-empty-string, MockClass> */ private static array $cache = []; /** * Returns a test double for the specified class. * * @throws ClassAlreadyExistsException * @throws ClassIsEnumerationException * @throws ClassIsFinalException * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws InvalidMethodNameException * @throws OriginalConstructorInvocationRequiredException * @throws ReflectionException * @throws RuntimeException * @throws UnknownTypeException */ public function testDouble(string $type, bool $mockObject, ?array $methods = [], array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = true, bool $callOriginalMethods = false, object $proxyTarget = null, bool $allowMockingUnknownTypes = true, bool $returnValueGeneration = true): MockObject|Stub { if ($type === Traversable::class) { $type = Iterator::class; } if (!$allowMockingUnknownTypes) { $this->ensureKnownType($type, $callAutoload); } $this->ensureValidMethods($methods); $this->ensureMockedClassDoesNotAlreadyExist($mockClassName); if (!$callOriginalConstructor && $callOriginalMethods) { throw new OriginalConstructorInvocationRequiredException; } $mock = $this->generate( $type, $mockObject, $methods, $mockClassName, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, ); $object = $this->getObject( $mock, $type, $callOriginalConstructor, $arguments, $callOriginalMethods, $proxyTarget, $returnValueGeneration, ); assert($object instanceof $type); if ($mockObject) { assert($object instanceof MockObject); } else { assert($object instanceof Stub); } return $object; } /** * @psalm-param list<class-string> $interfaces * * @throws RuntimeException * @throws UnknownTypeException */ public function testDoubleForInterfaceIntersection(array $interfaces, bool $mockObject, bool $callAutoload = true): MockObject|Stub { if (count($interfaces) < 2) { throw new RuntimeException('At least two interfaces must be specified'); } foreach ($interfaces as $interface) { if (!interface_exists($interface, $callAutoload)) { throw new UnknownTypeException($interface); } } sort($interfaces); $methods = []; foreach ($interfaces as $interface) { $methods = array_merge($methods, $this->namesOfMethodsIn($interface)); } if (count(array_unique($methods)) < count($methods)) { throw new RuntimeException('Interfaces must not declare the same method'); } $unqualifiedNames = []; foreach ($interfaces as $interface) { $parts = explode('\\', $interface); $unqualifiedNames[] = array_pop($parts); } sort($unqualifiedNames); do { $intersectionName = sprintf( 'Intersection_%s_%s', implode('_', $unqualifiedNames), substr(md5((string) mt_rand()), 0, 8), ); } while (interface_exists($intersectionName, false)); $template = $this->loadTemplate('intersection.tpl'); $template->setVar( [ 'intersection' => $intersectionName, 'interfaces' => implode(', ', $interfaces), ], ); eval($template->render()); return $this->testDouble($intersectionName, $mockObject); } /** * Returns a mock object for the specified abstract class with all abstract * methods of the class mocked. * * Concrete methods to mock can be specified with the $mockedMethods parameter. * * @throws ClassAlreadyExistsException * @throws ClassIsEnumerationException * @throws ClassIsFinalException * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws InvalidArgumentException * @throws InvalidMethodNameException * @throws OriginalConstructorInvocationRequiredException * @throws ReflectionException * @throws RuntimeException * @throws UnknownClassException * @throws UnknownTypeException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5241 */ public function mockObjectForAbstractClass(string $originalClassName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = null, bool $cloneArguments = true): MockObject { if (class_exists($originalClassName, $callAutoload) || interface_exists($originalClassName, $callAutoload)) { $reflector = $this->reflectClass($originalClassName); $methods = $mockedMethods; foreach ($reflector->getMethods() as $method) { if ($method->isAbstract() && !in_array($method->getName(), $methods ?? [], true)) { $methods[] = $method->getName(); } } if (empty($methods)) { $methods = null; } $mockObject = $this->testDouble( $originalClassName, true, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, ); assert($mockObject instanceof $originalClassName); assert($mockObject instanceof MockObject); return $mockObject; } throw new UnknownClassException($originalClassName); } /** * Returns a mock object for the specified trait with all abstract methods * of the trait mocked. Concrete methods to mock can be specified with the * `$mockedMethods` parameter. * * @psalm-param trait-string $traitName * * @throws ClassAlreadyExistsException * @throws ClassIsEnumerationException * @throws ClassIsFinalException * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws InvalidArgumentException * @throws InvalidMethodNameException * @throws OriginalConstructorInvocationRequiredException * @throws ReflectionException * @throws RuntimeException * @throws UnknownClassException * @throws UnknownTraitException * @throws UnknownTypeException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5243 */ public function mockObjectForTrait(string $traitName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = null, bool $cloneArguments = true): MockObject { if (!trait_exists($traitName, $callAutoload)) { throw new UnknownTraitException($traitName); } $className = $this->generateClassName( $traitName, '', 'Trait_', ); $classTemplate = $this->loadTemplate('trait_class.tpl'); $classTemplate->setVar( [ 'prologue' => 'abstract ', 'class_name' => $className['className'], 'trait_name' => $traitName, ], ); $mockTrait = new MockTrait($classTemplate->render(), $className['className']); $mockTrait->generate(); return $this->mockObjectForAbstractClass($className['className'], $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $mockedMethods, $cloneArguments); } /** * Returns an object for the specified trait. * * @psalm-param trait-string $traitName * * @throws ReflectionException * @throws RuntimeException * @throws UnknownTraitException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5244 */ public function objectForTrait(string $traitName, string $traitClassName = '', bool $callAutoload = true, bool $callOriginalConstructor = false, array $arguments = []): object { if (!trait_exists($traitName, $callAutoload)) { throw new UnknownTraitException($traitName); } $className = $this->generateClassName( $traitName, $traitClassName, 'Trait_', ); $classTemplate = $this->loadTemplate('trait_class.tpl'); $classTemplate->setVar( [ 'prologue' => '', 'class_name' => $className['className'], 'trait_name' => $traitName, ], ); return $this->getObject( new MockTrait( $classTemplate->render(), $className['className'], ), '', $callOriginalConstructor, $arguments, ); } /** * @throws ClassIsEnumerationException * @throws ClassIsFinalException * @throws ClassIsReadonlyException * @throws ReflectionException * @throws RuntimeException * * @todo This method is only public because it is used to test generated code in PHPT tests * * @see https://github.com/sebastianbergmann/phpunit/issues/5476 */ public function generate(string $type, bool $mockObject, array $methods = null, string $mockClassName = '', bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = true, bool $callOriginalMethods = false): MockClass { if ($mockClassName !== '') { return $this->generateCodeForTestDoubleClass( $type, $mockObject, $methods, $mockClassName, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, ); } $key = md5( $type . ($mockObject ? 'MockObject' : 'TestStub') . serialize($methods) . serialize($callOriginalClone) . serialize($cloneArguments) . serialize($callOriginalMethods), ); if (!isset(self::$cache[$key])) { self::$cache[$key] = $this->generateCodeForTestDoubleClass( $type, $mockObject, $methods, $mockClassName, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, ); } return self::$cache[$key]; } /** * @throws RuntimeException * @throws SoapExtensionNotAvailableException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5242 */ public function generateClassFromWsdl(string $wsdlFile, string $className, array $methods = [], array $options = []): string { if (!extension_loaded('soap')) { throw new SoapExtensionNotAvailableException; } $options['cache_wsdl'] = WSDL_CACHE_NONE; try { $client = new SoapClient($wsdlFile, $options); $_methods = array_unique($client->__getFunctions()); unset($client); } catch (SoapFault $e) { throw new RuntimeException( $e->getMessage(), $e->getCode(), $e, ); } sort($_methods); $methodTemplate = $this->loadTemplate('wsdl_method.tpl'); $methodsBuffer = ''; foreach ($_methods as $method) { preg_match_all('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\(/', $method, $matches, PREG_OFFSET_CAPTURE); $lastFunction = array_pop($matches[0]); $nameStart = $lastFunction[1]; $nameEnd = $nameStart + strlen($lastFunction[0]) - 1; $name = str_replace('(', '', $lastFunction[0]); if (empty($methods) || in_array($name, $methods, true)) { $arguments = explode( ',', str_replace(')', '', substr($method, $nameEnd + 1)), ); foreach (range(0, count($arguments) - 1) as $i) { $parameterStart = strpos($arguments[$i], '$'); if (!$parameterStart) { continue; } $arguments[$i] = substr($arguments[$i], $parameterStart); } $methodTemplate->setVar( [ 'method_name' => $name, 'arguments' => implode(', ', $arguments), ], ); $methodsBuffer .= $methodTemplate->render(); } } $optionsBuffer = '['; foreach ($options as $key => $value) { $optionsBuffer .= $key . ' => ' . $value; } $optionsBuffer .= ']'; $classTemplate = $this->loadTemplate('wsdl_class.tpl'); $namespace = ''; if (str_contains($className, '\\')) { $parts = explode('\\', $className); $className = array_pop($parts); $namespace = 'namespace ' . implode('\\', $parts) . ';' . "\n\n"; } $classTemplate->setVar( [ 'namespace' => $namespace, 'class_name' => $className, 'wsdl' => $wsdlFile, 'options' => $optionsBuffer, 'methods' => $methodsBuffer, ], ); return $classTemplate->render(); } /** * @throws ReflectionException * * @psalm-return list<MockMethod> */ public function mockClassMethods(string $className, bool $callOriginalMethods, bool $cloneArguments): array { $class = $this->reflectClass($className); $methods = []; foreach ($class->getMethods() as $method) { if (($method->isPublic() || $method->isAbstract()) && $this->canMethodBeDoubled($method)) { $methods[] = MockMethod::fromReflection($method, $callOriginalMethods, $cloneArguments); } } return $methods; } /** * @psalm-param class-string $interfaceName * * @throws ReflectionException * * @psalm-return list<ReflectionMethod> */ private function userDefinedInterfaceMethods(string $interfaceName): array { $interface = $this->reflectClass($interfaceName); $methods = []; foreach ($interface->getMethods() as $method) { if (!$method->isUserDefined()) { continue; } $methods[] = $method; } return $methods; } /** * @throws ReflectionException * @throws RuntimeException */ private function getObject(MockType $mockClass, string $type = '', bool $callOriginalConstructor = false, array $arguments = [], bool $callOriginalMethods = false, object $proxyTarget = null, bool $returnValueGeneration = true): object { $className = $mockClass->generate(); $object = $this->instantiate($className, $callOriginalConstructor, $arguments); if ($callOriginalMethods) { $this->instantiateProxyTarget($proxyTarget, $object, $type, $arguments); } if ($object instanceof StubInternal) { $object->__phpunit_setReturnValueGeneration($returnValueGeneration); } return $object; } /** * @throws ClassIsEnumerationException * @throws ClassIsFinalException * @throws ClassIsReadonlyException * @throws ReflectionException * @throws RuntimeException */ private function generateCodeForTestDoubleClass(string $type, bool $mockObject, ?array $explicitMethods, string $mockClassName, bool $callOriginalClone, bool $callAutoload, bool $cloneArguments, bool $callOriginalMethods): MockClass { $classTemplate = $this->loadTemplate('test_double_class.tpl'); $additionalInterfaces = []; $doubledCloneMethod = false; $proxiedCloneMethod = false; $isClass = false; $isInterface = false; $class = null; $mockMethods = new MockMethodSet; $testDoubleClassPrefix = $mockObject ? 'MockObject_' : 'TestStub_'; $_mockClassName = $this->generateClassName( $type, $mockClassName, $testDoubleClassPrefix, ); if (class_exists($_mockClassName['fullClassName'], $callAutoload)) { $isClass = true; } elseif (interface_exists($_mockClassName['fullClassName'], $callAutoload)) { $isInterface = true; } if (!$isClass && !$isInterface) { $prologue = 'class ' . $_mockClassName['originalClassName'] . "\n{\n}\n\n"; if (!empty($_mockClassName['namespaceName'])) { $prologue = 'namespace ' . $_mockClassName['namespaceName'] . " {\n\n" . $prologue . "}\n\n" . "namespace {\n\n"; $epilogue = "\n\n}"; } $doubledCloneMethod = true; } else { $class = $this->reflectClass($_mockClassName['fullClassName']); if ($class->isEnum()) { throw new ClassIsEnumerationException($_mockClassName['fullClassName']); } if ($class->isFinal()) { throw new ClassIsFinalException($_mockClassName['fullClassName']); } if (method_exists($class, 'isReadOnly') && $class->isReadOnly()) { throw new ClassIsReadonlyException($_mockClassName['fullClassName']); } // @see https://github.com/sebastianbergmann/phpunit/issues/2995 if ($isInterface && $class->implementsInterface(Throwable::class)) { $actualClassName = Exception::class; $additionalInterfaces[] = $class->getName(); $isInterface = false; $class = $this->reflectClass($actualClassName); foreach ($this->userDefinedInterfaceMethods($_mockClassName['fullClassName']) as $method) { $methodName = $method->getName(); if ($class->hasMethod($methodName)) { $classMethod = $class->getMethod($methodName); if (!$this->canMethodBeDoubled($classMethod)) { continue; } } $mockMethods->addMethods( MockMethod::fromReflection($method, $callOriginalMethods, $cloneArguments), ); } $_mockClassName = $this->generateClassName( $actualClassName, $_mockClassName['className'], $testDoubleClassPrefix, ); } // @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/103 if ($isInterface && $class->implementsInterface(Traversable::class) && !$class->implementsInterface(Iterator::class) && !$class->implementsInterface(IteratorAggregate::class)) { $additionalInterfaces[] = Iterator::class; $mockMethods->addMethods( ...$this->mockClassMethods(Iterator::class, $callOriginalMethods, $cloneArguments), ); } if ($class->hasMethod('__clone')) { $cloneMethod = $class->getMethod('__clone'); if (!$cloneMethod->isFinal()) { if ($callOriginalClone && !$isInterface) { $proxiedCloneMethod = true; } else { $doubledCloneMethod = true; } } } else { $doubledCloneMethod = true; } } if ($isClass && $explicitMethods === []) { $mockMethods->addMethods( ...$this->mockClassMethods($_mockClassName['fullClassName'], $callOriginalMethods, $cloneArguments), ); } if ($isInterface && ($explicitMethods === [] || $explicitMethods === null)) { $mockMethods->addMethods( ...$this->interfaceMethods($_mockClassName['fullClassName'], $cloneArguments), ); } if (is_array($explicitMethods)) { foreach ($explicitMethods as $methodName) { if ($class !== null && $class->hasMethod($methodName)) { $method = $class->getMethod($methodName); if ($this->canMethodBeDoubled($method)) { $mockMethods->addMethods( MockMethod::fromReflection($method, $callOriginalMethods, $cloneArguments), ); } } else { $mockMethods->addMethods( MockMethod::fromName( $_mockClassName['fullClassName'], $methodName, $cloneArguments, ), ); } } } $mockedMethods = ''; $configurable = []; foreach ($mockMethods->asArray() as $mockMethod) { $mockedMethods .= $mockMethod->generateCode(); $configurable[] = new ConfigurableMethod($mockMethod->methodName(), $mockMethod->returnType()); } /** @psalm-var trait-string[] $traits */ $traits = [StubApi::class]; if ($mockObject) { $traits[] = MockObjectApi::class; } if (!$mockMethods->hasMethod('method') && (!isset($class) || !$class->hasMethod('method'))) { $traits[] = Method::class; } if ($doubledCloneMethod) { $traits[] = DoubledCloneMethod::class; } if ($proxiedCloneMethod) { $traits[] = ProxiedCloneMethod::class; } $useStatements = ''; foreach ($traits as $trait) { $useStatements .= sprintf( ' use %s;' . PHP_EOL, $trait, ); } unset($traits); $classTemplate->setVar( [ 'prologue' => $prologue ?? '', 'epilogue' => $epilogue ?? '', 'class_declaration' => $this->generateTestDoubleClassDeclaration( $mockObject, $_mockClassName, $isInterface, $additionalInterfaces, ), 'use_statements' => $useStatements, 'mock_class_name' => $_mockClassName['className'], 'mocked_methods' => $mockedMethods, ], ); return new MockClass( $classTemplate->render(), $_mockClassName['className'], $configurable, ); } private function generateClassName(string $type, string $className, string $prefix): array { if ($type[0] === '\\') { $type = substr($type, 1); } $classNameParts = explode('\\', $type); if (count($classNameParts) > 1) { $type = array_pop($classNameParts); $namespaceName = implode('\\', $classNameParts); $fullClassName = $namespaceName . '\\' . $type; } else { $namespaceName = ''; $fullClassName = $type; } if ($className === '') { do { $className = $prefix . $type . '_' . substr(md5((string) mt_rand()), 0, 8); } while (class_exists($className, false)); } return [ 'className' => $className, 'originalClassName' => $type, 'fullClassName' => $fullClassName, 'namespaceName' => $namespaceName, ]; } private function generateTestDoubleClassDeclaration(bool $mockObject, array $mockClassName, bool $isInterface, array $additionalInterfaces = []): string { if ($mockObject) { $additionalInterfaces[] = MockObjectInternal::class; } else { $additionalInterfaces[] = StubInternal::class; } $buffer = 'class '; $interfaces = implode(', ', $additionalInterfaces); if ($isInterface) { $buffer .= sprintf( '%s implements %s', $mockClassName['className'], $interfaces, ); if (!in_array($mockClassName['originalClassName'], $additionalInterfaces, true)) { $buffer .= ', '; if (!empty($mockClassName['namespaceName'])) { $buffer .= $mockClassName['namespaceName'] . '\\'; } $buffer .= $mockClassName['originalClassName']; } } else { $buffer .= sprintf( '%s extends %s%s implements %s', $mockClassName['className'], !empty($mockClassName['namespaceName']) ? $mockClassName['namespaceName'] . '\\' : '', $mockClassName['originalClassName'], $interfaces, ); } return $buffer; } private function canMethodBeDoubled(ReflectionMethod $method): bool { if ($method->isConstructor()) { return false; } if ($method->isDestructor()) { return false; } if ($method->isFinal()) { return false; } if ($method->isPrivate()) { return false; } return !$this->isMethodNameExcluded($method->getName()); } private function isMethodNameExcluded(string $name): bool { return isset(self::EXCLUDED_METHOD_NAMES[$name]); } /** * @throws UnknownTypeException */ private function ensureKnownType(string $type, bool $callAutoload): void { if (!class_exists($type, $callAutoload) && !interface_exists($type, $callAutoload)) { throw new UnknownTypeException($type); } } /** * @throws DuplicateMethodException * @throws InvalidMethodNameException */ private function ensureValidMethods(?array $methods): void { if ($methods === null) { return; } foreach ($methods as $method) { if (!preg_match('~[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*~', (string) $method)) { throw new InvalidMethodNameException((string) $method); } } if ($methods !== array_unique($methods)) { throw new DuplicateMethodException($methods); } } /** * @throws ClassAlreadyExistsException * @throws ReflectionException */ private function ensureMockedClassDoesNotAlreadyExist(string $mockClassName): void { if ($mockClassName !== '' && class_exists($mockClassName, false)) { $reflector = $this->reflectClass($mockClassName); if (!$reflector->implementsInterface(MockObject::class)) { throw new ClassAlreadyExistsException($mockClassName); } } } /** * @psalm-param class-string $className * * @throws ReflectionException */ private function instantiate(string $className, bool $callOriginalConstructor, array $arguments): object { if ($callOriginalConstructor) { if (count($arguments) === 0) { return new $className; } try { return (new ReflectionClass($className))->newInstanceArgs($arguments); // @codeCoverageIgnoreStart } catch (\ReflectionException $e) { throw new ReflectionException( $e->getMessage(), $e->getCode(), $e, ); } // @codeCoverageIgnoreEnd } try { return (new ReflectionClass($className))->newInstanceWithoutConstructor(); // @codeCoverageIgnoreStart } catch (\ReflectionException $e) { throw new ReflectionException( $e->getMessage(), $e->getCode(), $e, ); // @codeCoverageIgnoreEnd } } /** * @psalm-param class-string $type * * @throws ReflectionException */ private function instantiateProxyTarget(?object $proxyTarget, object $object, string $type, array $arguments): void { if (!is_object($proxyTarget)) { assert(class_exists($type)); if (count($arguments) === 0) { $proxyTarget = new $type; } else { $class = new ReflectionClass($type); try { $proxyTarget = $class->newInstanceArgs($arguments); // @codeCoverageIgnoreStart } catch (\ReflectionException $e) { throw new ReflectionException( $e->getMessage(), $e->getCode(), $e, ); } // @codeCoverageIgnoreEnd } } $object->__phpunit_setOriginalObject($proxyTarget); } /** * @psalm-param class-string $className * * @throws ReflectionException */ private function reflectClass(string $className): ReflectionClass { try { $class = new ReflectionClass($className); // @codeCoverageIgnoreStart } catch (\ReflectionException $e) { throw new ReflectionException( $e->getMessage(), $e->getCode(), $e, ); } // @codeCoverageIgnoreEnd return $class; } /** * @psalm-param class-string $classOrInterfaceName * * @psalm-return list<string> * * @throws ReflectionException */ private function namesOfMethodsIn(string $classOrInterfaceName): array { $class = $this->reflectClass($classOrInterfaceName); $methods = []; foreach ($class->getMethods() as $method) { if ($method->isPublic() || $method->isAbstract()) { $methods[] = $method->getName(); } } return $methods; } /** * @psalm-param class-string $interfaceName * * @psalm-return list<MockMethod> * * @throws ReflectionException */ private function interfaceMethods(string $interfaceName, bool $cloneArguments): array { $class = $this->reflectClass($interfaceName); $methods = []; foreach ($class->getMethods() as $method) { $methods[] = MockMethod::fromReflection($method, false, $cloneArguments); } return $methods; } } MockObject/Generator/TemplateLoader.php 0000644 00000001646 15107326342 0014137 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Generator; use SebastianBergmann\Template\Template; /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit */ trait TemplateLoader { /** * @psalm-var array<string,Template> */ private static array $templates = []; /** * @psalm-suppress MissingThrowsDocblock */ private function loadTemplate(string $template): Template { $filename = __DIR__ . '/templates/' . $template; if (!isset(self::$templates[$filename])) { self::$templates[$filename] = new Template($filename); } return self::$templates[$filename]; } } MockObject/Generator/templates/doubled_static_method.tpl 0000644 00000000356 15107326342 0017565 0 ustar 00 {modifier} function {reference}{method_name}({arguments_decl}){return_declaration} { throw new \PHPUnit\Framework\MockObject\BadMethodCallException('Static method "{method_name}" cannot be invoked on mock object'); } MockObject/Generator/templates/doubled_method.tpl 0000644 00000001462 15107326342 0016215 0 ustar 00 {modifier} function {reference}{method_name}({arguments_decl}){return_declaration} {{deprecation} $__phpunit_arguments = [{arguments_call}]; $__phpunit_count = func_num_args(); if ($__phpunit_count > {arguments_count}) { $__phpunit_arguments_tmp = func_get_args(); for ($__phpunit_i = {arguments_count}; $__phpunit_i < $__phpunit_count; $__phpunit_i++) { $__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i]; } } $__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke( new \PHPUnit\Framework\MockObject\Invocation( '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments} ) );{return_result} } MockObject/Generator/templates/proxied_method.tpl 0000644 00000001624 15107326342 0016251 0 ustar 00 {modifier} function {reference}{method_name}({arguments_decl}){return_declaration} { $__phpunit_arguments = [{arguments_call}]; $__phpunit_count = func_num_args(); if ($__phpunit_count > {arguments_count}) { $__phpunit_arguments_tmp = func_get_args(); for ($__phpunit_i = {arguments_count}; $__phpunit_i < $__phpunit_count; $__phpunit_i++) { $__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i]; } } $this->__phpunit_getInvocationHandler()->invoke( new \PHPUnit\Framework\MockObject\Invocation( '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments}, true ) ); $__phpunit_result = call_user_func_array([$this->__phpunit_originalObject, "{method_name}"], $__phpunit_arguments);{return_result} } MockObject/Generator/templates/test_double_class.tpl 0000644 00000000146 15107326342 0016733 0 ustar 00 declare(strict_types=1); {prologue}{class_declaration} { {use_statements}{mocked_methods}}{epilogue} MockObject/Generator/templates/deprecation.tpl 0000644 00000000073 15107326342 0015531 0 ustar 00 @trigger_error({deprecation}, E_USER_DEPRECATED); MockObject/Generator/templates/trait_class.tpl 0000644 00000000121 15107326342 0015536 0 ustar 00 declare(strict_types=1); {prologue}class {class_name} { use {trait_name}; } MockObject/Generator/templates/wsdl_method.tpl 0000644 00000000074 15107326342 0015546 0 ustar 00 public function {method_name}({arguments}) { } MockObject/Generator/templates/intersection.tpl 0000644 00000000114 15107326342 0015736 0 ustar 00 declare(strict_types=1); interface {intersection} extends {interfaces} { } MockObject/Generator/templates/wsdl_class.tpl 0000644 00000000315 15107326342 0015371 0 ustar 00 declare(strict_types=1); {namespace}class {class_name} extends \SoapClient { public function __construct($wsdl, array $options) { parent::__construct('{wsdl}', $options); } {methods}} MockObject/Runtime/InvocationHandler.php 0000644 00000007446 15107326342 0014345 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function strtolower; use Exception; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; use PHPUnit\Framework\MockObject\Rule\InvocationOrder; use Throwable; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class InvocationHandler { /** * @psalm-var list<Matcher> */ private array $matchers = []; /** * @psalm-var array<string,Matcher> */ private array $matcherMap = []; /** * @psalm-var list<ConfigurableMethod> */ private readonly array $configurableMethods; private readonly bool $returnValueGeneration; /** * @psalm-param list<ConfigurableMethod> $configurableMethods */ public function __construct(array $configurableMethods, bool $returnValueGeneration) { $this->configurableMethods = $configurableMethods; $this->returnValueGeneration = $returnValueGeneration; } public function hasMatchers(): bool { foreach ($this->matchers as $matcher) { if ($matcher->hasMatchers()) { return true; } } return false; } /** * Looks up the match builder with identification $id and returns it. */ public function lookupMatcher(string $id): ?Matcher { return $this->matcherMap[$id] ?? null; } /** * Registers a matcher with the identification $id. The matcher can later be * looked up using lookupMatcher() to figure out if it has been invoked. * * @throws MatcherAlreadyRegisteredException */ public function registerMatcher(string $id, Matcher $matcher): void { if (isset($this->matcherMap[$id])) { throw new MatcherAlreadyRegisteredException($id); } $this->matcherMap[$id] = $matcher; } public function expects(InvocationOrder $rule): InvocationMocker { $matcher = new Matcher($rule); $this->addMatcher($matcher); return new InvocationMocker( $this, $matcher, ...$this->configurableMethods, ); } /** * @throws \PHPUnit\Framework\MockObject\Exception * @throws Exception */ public function invoke(Invocation $invocation): mixed { $exception = null; $hasReturnValue = false; $returnValue = null; foreach ($this->matchers as $match) { try { if ($match->matches($invocation)) { $value = $match->invoked($invocation); if (!$hasReturnValue) { $returnValue = $value; $hasReturnValue = true; } } } catch (Exception $e) { $exception = $e; } } if ($exception !== null) { throw $exception; } if ($hasReturnValue) { return $returnValue; } if (!$this->returnValueGeneration) { if (strtolower($invocation->methodName()) === '__tostring') { return ''; } throw new ReturnValueNotConfiguredException($invocation); } return $invocation->generateReturnValue(); } /** * @throws Throwable */ public function verify(): void { foreach ($this->matchers as $matcher) { $matcher->verify(); } } private function addMatcher(Matcher $matcher): void { $this->matchers[] = $matcher; } } MockObject/Runtime/Api/MockObjectApi.php 0000644 00000003136 15107326342 0014111 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use PHPUnit\Framework\MockObject\Builder\InvocationMocker as InvocationMockerBuilder; use PHPUnit\Framework\MockObject\Rule\InvocationOrder; /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit */ trait MockObjectApi { private object $__phpunit_originalObject; /** @noinspection MagicMethodsValidityInspection */ public function __phpunit_hasMatchers(): bool { return $this->__phpunit_getInvocationHandler()->hasMatchers(); } /** @noinspection MagicMethodsValidityInspection */ public function __phpunit_setOriginalObject(object $originalObject): void { $this->__phpunit_originalObject = $originalObject; } /** @noinspection MagicMethodsValidityInspection */ public function __phpunit_verify(bool $unsetInvocationMocker = true): void { $this->__phpunit_getInvocationHandler()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_unsetInvocationMocker(); } } abstract public function __phpunit_getInvocationHandler(): InvocationHandler; abstract public function __phpunit_unsetInvocationMocker(): void; public function expects(InvocationOrder $matcher): InvocationMockerBuilder { return $this->__phpunit_getInvocationHandler()->expects($matcher); } } MockObject/Runtime/Api/Method.php 0000644 00000001455 15107326342 0012661 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function call_user_func_array; use function func_get_args; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; use PHPUnit\Framework\MockObject\Rule\AnyInvokedCount; /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit */ trait Method { public function method(): InvocationMocker { $expects = $this->expects(new AnyInvokedCount); return call_user_func_array( [$expects, 'method'], func_get_args(), ); } } MockObject/Runtime/Api/DoubledCloneMethod.php 0000644 00000001057 15107326342 0015137 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit */ trait DoubledCloneMethod { public function __clone(): void { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationHandler(); } } MockObject/Runtime/Api/StubApi.php 0000644 00000003363 15107326342 0013010 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit */ trait StubApi { /** * @psalm-var list<ConfigurableMethod> */ private static array $__phpunit_configurableMethods; private bool $__phpunit_returnValueGeneration = true; private ?InvocationHandler $__phpunit_invocationMocker = null; /** @noinspection MagicMethodsValidityInspection */ public static function __phpunit_initConfigurableMethods(ConfigurableMethod ...$configurableMethods): void { static::$__phpunit_configurableMethods = $configurableMethods; } /** @noinspection MagicMethodsValidityInspection */ public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration): void { $this->__phpunit_returnValueGeneration = $returnValueGeneration; } /** @noinspection MagicMethodsValidityInspection */ public function __phpunit_getInvocationHandler(): InvocationHandler { if ($this->__phpunit_invocationMocker === null) { $this->__phpunit_invocationMocker = new InvocationHandler( static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration, ); } return $this->__phpunit_invocationMocker; } /** @noinspection MagicMethodsValidityInspection */ public function __phpunit_unsetInvocationMocker(): void { $this->__phpunit_invocationMocker = null; } } MockObject/Runtime/Api/ProxiedCloneMethod.php 0000644 00000001113 15107326342 0015164 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit */ trait ProxiedCloneMethod { public function __clone(): void { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationHandler(); parent::__clone(); } } MockObject/Runtime/Matcher.php 0000644 00000014361 15107326342 0012313 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function sprintf; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Rule\AnyInvokedCount; use PHPUnit\Framework\MockObject\Rule\AnyParameters; use PHPUnit\Framework\MockObject\Rule\InvocationOrder; use PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount; use PHPUnit\Framework\MockObject\Rule\InvokedCount; use PHPUnit\Framework\MockObject\Rule\MethodName; use PHPUnit\Framework\MockObject\Rule\ParametersRule; use PHPUnit\Framework\MockObject\Stub\Stub; use PHPUnit\Util\ThrowableToStringMapper; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class Matcher { private readonly InvocationOrder $invocationRule; private ?string $afterMatchBuilderId = null; private ?MethodName $methodNameRule = null; private ?ParametersRule $parametersRule = null; private ?Stub $stub = null; public function __construct(InvocationOrder $rule) { $this->invocationRule = $rule; } public function hasMatchers(): bool { return !$this->invocationRule instanceof AnyInvokedCount; } public function hasMethodNameRule(): bool { return $this->methodNameRule !== null; } public function methodNameRule(): MethodName { return $this->methodNameRule; } public function setMethodNameRule(MethodName $rule): void { $this->methodNameRule = $rule; } public function hasParametersRule(): bool { return $this->parametersRule !== null; } public function setParametersRule(ParametersRule $rule): void { $this->parametersRule = $rule; } public function setStub(Stub $stub): void { $this->stub = $stub; } public function setAfterMatchBuilderId(string $id): void { $this->afterMatchBuilderId = $id; } /** * @throws Exception * @throws ExpectationFailedException * @throws MatchBuilderNotFoundException * @throws MethodNameNotConfiguredException * @throws RuntimeException */ public function invoked(Invocation $invocation): mixed { if ($this->methodNameRule === null) { throw new MethodNameNotConfiguredException; } if ($this->afterMatchBuilderId !== null) { $matcher = $invocation->object() ->__phpunit_getInvocationHandler() ->lookupMatcher($this->afterMatchBuilderId); if (!$matcher) { throw new MatchBuilderNotFoundException($this->afterMatchBuilderId); } } $this->invocationRule->invoked($invocation); try { $this->parametersRule?->apply($invocation); } catch (ExpectationFailedException $e) { throw new ExpectationFailedException( sprintf( "Expectation failed for %s when %s\n%s", $this->methodNameRule->toString(), $this->invocationRule->toString(), $e->getMessage(), ), $e->getComparisonFailure(), ); } if ($this->stub) { return $this->stub->invoke($invocation); } return $invocation->generateReturnValue(); } /** * @throws ExpectationFailedException * @throws MatchBuilderNotFoundException * @throws MethodNameNotConfiguredException * @throws RuntimeException */ public function matches(Invocation $invocation): bool { if ($this->afterMatchBuilderId !== null) { $matcher = $invocation->object() ->__phpunit_getInvocationHandler() ->lookupMatcher($this->afterMatchBuilderId); if (!$matcher) { throw new MatchBuilderNotFoundException($this->afterMatchBuilderId); } if (!$matcher->invocationRule->hasBeenInvoked()) { return false; } } if ($this->methodNameRule === null) { throw new MethodNameNotConfiguredException; } if (!$this->invocationRule->matches($invocation)) { return false; } try { if (!$this->methodNameRule->matches($invocation)) { return false; } } catch (ExpectationFailedException $e) { throw new ExpectationFailedException( sprintf( "Expectation failed for %s when %s\n%s", $this->methodNameRule->toString(), $this->invocationRule->toString(), $e->getMessage(), ), $e->getComparisonFailure(), ); } return true; } /** * @throws ExpectationFailedException * @throws MethodNameNotConfiguredException */ public function verify(): void { if ($this->methodNameRule === null) { throw new MethodNameNotConfiguredException; } try { $this->invocationRule->verify(); if ($this->parametersRule === null) { $this->parametersRule = new AnyParameters; } $invocationIsAny = $this->invocationRule instanceof AnyInvokedCount; $invocationIsNever = $this->invocationRule instanceof InvokedCount && $this->invocationRule->isNever(); $invocationIsAtMost = $this->invocationRule instanceof InvokedAtMostCount; if (!$invocationIsAny && !$invocationIsNever && !$invocationIsAtMost) { $this->parametersRule->verify(); } } catch (ExpectationFailedException $e) { throw new ExpectationFailedException( sprintf( "Expectation failed for %s when %s.\n%s", $this->methodNameRule->toString(), $this->invocationRule->toString(), ThrowableToStringMapper::map($e), ), ); } } } MockObject/Runtime/Invocation.php 0000644 00000007426 15107326342 0013045 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function array_map; use function implode; use function is_object; use function sprintf; use function str_starts_with; use function strtolower; use function substr; use PHPUnit\Framework\SelfDescribing; use PHPUnit\Util\Cloner; use SebastianBergmann\Exporter\Exporter; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class Invocation implements SelfDescribing { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-var non-empty-string */ private readonly string $methodName; private readonly array $parameters; private readonly string $returnType; private readonly bool $isReturnTypeNullable; private readonly bool $proxiedCall; private readonly MockObjectInternal|StubInternal $object; /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ public function __construct(string $className, string $methodName, array $parameters, string $returnType, MockObjectInternal|StubInternal $object, bool $cloneObjects = false, bool $proxiedCall = false) { $this->className = $className; $this->methodName = $methodName; $this->object = $object; $this->proxiedCall = $proxiedCall; if (strtolower($methodName) === '__tostring') { $returnType = 'string'; } if (str_starts_with($returnType, '?')) { $returnType = substr($returnType, 1); $this->isReturnTypeNullable = true; } else { $this->isReturnTypeNullable = false; } $this->returnType = $returnType; if (!$cloneObjects) { $this->parameters = $parameters; return; } foreach ($parameters as $key => $value) { if (is_object($value)) { $parameters[$key] = Cloner::clone($value); } } $this->parameters = $parameters; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } public function parameters(): array { return $this->parameters; } /** * @throws Exception */ public function generateReturnValue(): mixed { if ($this->returnType === 'never') { throw new NeverReturningMethodException( $this->className, $this->methodName, ); } if ($this->isReturnTypeNullable || $this->proxiedCall) { return null; } return (new ReturnValueGenerator)->generate( $this->className, $this->methodName, $this->object::class, $this->returnType, ); } public function toString(): string { $exporter = new Exporter; return sprintf( '%s::%s(%s)%s', $this->className, $this->methodName, implode( ', ', array_map( [$exporter, 'shortenedExport'], $this->parameters, ), ), $this->returnType ? sprintf(': %s', $this->returnType) : '', ); } public function object(): MockObjectInternal|StubInternal { return $this->object; } } MockObject/Runtime/Interface/StubInternal.php 0000644 00000001407 15107326342 0015237 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * @internal This interface is not covered by the backward compatibility promise for PHPUnit */ interface StubInternal extends Stub { public static function __phpunit_initConfigurableMethods(ConfigurableMethod ...$configurableMethods): void; public function __phpunit_getInvocationHandler(): InvocationHandler; public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration): void; public function __phpunit_unsetInvocationMocker(): void; } MockObject/Runtime/Interface/MockObjectInternal.php 0000644 00000001241 15107326342 0016336 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * @internal This interface is not covered by the backward compatibility promise for PHPUnit */ interface MockObjectInternal extends MockObject, StubInternal { public function __phpunit_hasMatchers(): bool; public function __phpunit_setOriginalObject(object $originalObject): void; public function __phpunit_verify(bool $unsetInvocationMocker = true): void; } MockObject/Runtime/Interface/MockObject.php 0000644 00000001263 15107326342 0014645 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; use PHPUnit\Framework\MockObject\Rule\InvocationOrder; /** * @method InvocationMocker method($constraint) * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ interface MockObject extends Stub { public function expects(InvocationOrder $invocationRule): InvocationMocker; } MockObject/Runtime/Interface/Stub.php 0000644 00000001033 15107326342 0013535 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use PHPUnit\Framework\MockObject\Builder\InvocationStubber; /** * @method InvocationStubber method($constraint) * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ interface Stub { } MockObject/Runtime/ReturnValueGenerator.php 0000644 00000016031 15107326342 0015047 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function array_keys; use function array_map; use function explode; use function in_array; use function interface_exists; use function sprintf; use function str_contains; use function str_ends_with; use function str_starts_with; use function substr; use PHPUnit\Framework\MockObject\Generator\Generator; use ReflectionClass; use stdClass; use Throwable; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ReturnValueGenerator { /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName * @psalm-param class-string $stubClassName * * @throws Exception */ public function generate(string $className, string $methodName, string $stubClassName, string $returnType): mixed { $intersection = false; $union = false; if (str_contains($returnType, '|')) { $types = explode('|', $returnType); $union = true; foreach (array_keys($types) as $key) { if (str_starts_with($types[$key], '(') && str_ends_with($types[$key], ')')) { $types[$key] = substr($types[$key], 1, -1); } } } elseif (str_contains($returnType, '&')) { $types = explode('&', $returnType); $intersection = true; } else { $types = [$returnType]; } $types = array_map('strtolower', $types); if (!$intersection) { if (in_array('', $types, true) || in_array('null', $types, true) || in_array('mixed', $types, true) || in_array('void', $types, true)) { return null; } if (in_array('true', $types, true)) { return true; } if (in_array('false', $types, true) || in_array('bool', $types, true)) { return false; } if (in_array('float', $types, true)) { return 0.0; } if (in_array('int', $types, true)) { return 0; } if (in_array('string', $types, true)) { return ''; } if (in_array('array', $types, true)) { return []; } if (in_array('static', $types, true)) { return $this->newInstanceOf($stubClassName, $className, $methodName); } if (in_array('object', $types, true)) { return new stdClass; } if (in_array('callable', $types, true) || in_array('closure', $types, true)) { return static function (): void { }; } if (in_array('traversable', $types, true) || in_array('generator', $types, true) || in_array('iterable', $types, true)) { $generator = static function (): \Generator { yield from []; }; return $generator(); } if (!$union) { return $this->testDoubleFor($returnType, $className, $methodName); } } if ($union) { foreach ($types as $type) { if (str_contains($type, '&')) { $_types = explode('&', $type); if ($this->onlyInterfaces($_types)) { return $this->testDoubleForIntersectionOfInterfaces($_types, $className, $methodName); } } } } if ($intersection && $this->onlyInterfaces($types)) { return $this->testDoubleForIntersectionOfInterfaces($types, $className, $methodName); } $reason = ''; if ($union) { $reason = ' because the declared return type is a union'; } elseif ($intersection) { $reason = ' because the declared return type is an intersection'; } throw new RuntimeException( sprintf( 'Return value for %s::%s() cannot be generated%s, please configure a return value for this method', $className, $methodName, $reason, ), ); } /** * @psalm-param non-empty-list<string> $types */ private function onlyInterfaces(array $types): bool { foreach ($types as $type) { if (!interface_exists($type)) { return false; } } return true; } /** * @psalm-param class-string $stubClassName * @psalm-param class-string $className * @psalm-param non-empty-string $methodName * * @throws RuntimeException */ private function newInstanceOf(string $stubClassName, string $className, string $methodName): MockObject { try { return (new ReflectionClass($stubClassName))->newInstanceWithoutConstructor(); } catch (Throwable $t) { throw new RuntimeException( sprintf( 'Return value for %s::%s() cannot be generated: %s', $className, $methodName, $t->getMessage(), ), ); } } /** * @psalm-param class-string $type * @psalm-param class-string $className * @psalm-param non-empty-string $methodName * * @throws RuntimeException */ private function testDoubleFor(string $type, string $className, string $methodName): Stub { try { return (new Generator)->testDouble($type, false, [], [], '', false); } catch (Throwable $t) { throw new RuntimeException( sprintf( 'Return value for %s::%s() cannot be generated: %s', $className, $methodName, $t->getMessage(), ), ); } } /** * @psalm-param non-empty-list<string> $types * @psalm-param class-string $className * @psalm-param non-empty-string $methodName * * @throws RuntimeException */ private function testDoubleForIntersectionOfInterfaces(array $types, string $className, string $methodName): Stub { try { return (new Generator)->testDoubleForInterfaceIntersection($types, false); } catch (Throwable $t) { throw new RuntimeException( sprintf( 'Return value for %s::%s() cannot be generated: %s', $className, $methodName, $t->getMessage(), ), ); } } } MockObject/Runtime/Stub/ReturnArgument.php 0000644 00000001421 15107326342 0014620 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ReturnArgument implements Stub { private readonly int $argumentIndex; public function __construct(int $argumentIndex) { $this->argumentIndex = $argumentIndex; } public function invoke(Invocation $invocation): mixed { return $invocation->parameters()[$this->argumentIndex] ?? null; } } MockObject/Runtime/Stub/ReturnValueMap.php 0000644 00000002206 15107326342 0014552 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use function array_pop; use function count; use function is_array; use PHPUnit\Framework\MockObject\Invocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ReturnValueMap implements Stub { private readonly array $valueMap; public function __construct(array $valueMap) { $this->valueMap = $valueMap; } public function invoke(Invocation $invocation): mixed { $parameterCount = count($invocation->parameters()); foreach ($this->valueMap as $map) { if (!is_array($map) || $parameterCount !== (count($map) - 1)) { continue; } $return = array_pop($map); if ($invocation->parameters() === $map) { return $return; } } return null; } } MockObject/Runtime/Stub/ReturnSelf.php 0000644 00000001265 15107326342 0013735 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\MockObject\RuntimeException; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ReturnSelf implements Stub { /** * @throws RuntimeException */ public function invoke(Invocation $invocation): object { return $invocation->object(); } } MockObject/Runtime/Stub/ReturnReference.php 0000644 00000001330 15107326342 0014733 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ReturnReference implements Stub { private mixed $reference; public function __construct(mixed &$reference) { $this->reference = &$reference; } public function invoke(Invocation $invocation): mixed { return $this->reference; } } MockObject/Runtime/Stub/Exception.php 0000644 00000001430 15107326342 0013574 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; use Throwable; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class Exception implements Stub { private readonly Throwable $exception; public function __construct(Throwable $exception) { $this->exception = $exception; } /** * @throws Throwable */ public function invoke(Invocation $invocation): never { throw $this->exception; } } MockObject/Runtime/Stub/ReturnCallback.php 0000644 00000001506 15107326342 0014536 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use function call_user_func_array; use PHPUnit\Framework\MockObject\Invocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ReturnCallback implements Stub { /** * @var callable */ private $callback; public function __construct(callable $callback) { $this->callback = $callback; } public function invoke(Invocation $invocation): mixed { return call_user_func_array($this->callback, $invocation->parameters()); } } MockObject/Runtime/Stub/ConsecutiveCalls.php 0000644 00000001547 15107326342 0015115 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use function array_shift; use PHPUnit\Framework\MockObject\Invocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ConsecutiveCalls implements Stub { private array $stack; public function __construct(array $stack) { $this->stack = $stack; } public function invoke(Invocation $invocation): mixed { $value = array_shift($this->stack); if ($value instanceof Stub) { $value = $value->invoke($invocation); } return $value; } } MockObject/Runtime/Stub/Stub.php 0000644 00000001170 15107326342 0012554 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface Stub { /** * Fakes the processing of the invocation $invocation by returning a * specific value. */ public function invoke(Invocation $invocation): mixed; } MockObject/Runtime/Stub/ReturnStub.php 0000644 00000001306 15107326342 0013755 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ReturnStub implements Stub { private readonly mixed $value; public function __construct(mixed $value) { $this->value = $value; } public function invoke(Invocation $invocation): mixed { return $this->value; } } MockObject/Runtime/MethodNameConstraint.php 0000644 00000001712 15107326342 0015012 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use function sprintf; use function strtolower; use PHPUnit\Framework\Constraint\Constraint; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MethodNameConstraint extends Constraint { private readonly string $methodName; public function __construct(string $methodName) { $this->methodName = $methodName; } public function toString(): string { return sprintf( 'is "%s"', $this->methodName, ); } protected function matches(mixed $other): bool { return strtolower($this->methodName) === strtolower((string) $other); } } MockObject/Runtime/Builder/Identity.php 0000644 00000001130 15107326342 0014075 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface Identity { /** * Sets the identification of the expectation to $id. * * @note The identifier is unique per mock object. */ public function id(string $id): self; } MockObject/Runtime/Builder/InvocationStubber.php 0000644 00000002203 15107326342 0015746 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; use PHPUnit\Framework\MockObject\Stub\Stub; use Throwable; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ interface InvocationStubber { public function will(Stub $stub): Identity; public function willReturn(mixed $value, mixed ...$nextValues): self; public function willReturnReference(mixed &$reference): self; /** * @psalm-param array<int, array<int, mixed>> $valueMap */ public function willReturnMap(array $valueMap): self; public function willReturnArgument(int $argumentIndex): self; public function willReturnCallback(callable $callback): self; public function willReturnSelf(): self; public function willReturnOnConsecutiveCalls(mixed ...$values): self; public function willThrowException(Throwable $exception): self; } MockObject/Runtime/Builder/ParametersMatch.php 0000644 00000002777 15107326342 0015406 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface ParametersMatch extends Stub { /** * Defines the expectation which must occur before the current is valid. */ public function after(string $id): Stub; /** * Sets the parameters to match for, each parameter to this function will * be part of match. To perform specific matches or constraints create a * new PHPUnit\Framework\Constraint\Constraint and use it for the parameter. * If the parameter value is not a constraint it will use the * PHPUnit\Framework\Constraint\IsEqual for the value. * * Some examples: * <code> * // match first parameter with value 2 * $b->with(2); * // match first parameter with value 'smock' and second identical to 42 * $b->with('smock', new PHPUnit\Framework\Constraint\IsEqual(42)); * </code> */ public function with(mixed ...$arguments): self; /** * Sets a rule which allows any kind of parameters. * * Some examples: * <code> * // match any number of parameters * $b->withAnyParameters(); * </code> */ public function withAnyParameters(): self; } MockObject/Runtime/Builder/InvocationMocker.php 0000644 00000017332 15107326342 0015571 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; use function array_flip; use function array_key_exists; use function array_map; use function array_merge; use function count; use function is_string; use function strtolower; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\InvalidArgumentException; use PHPUnit\Framework\MockObject\ConfigurableMethod; use PHPUnit\Framework\MockObject\IncompatibleReturnValueException; use PHPUnit\Framework\MockObject\InvocationHandler; use PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\MockObject\MatcherAlreadyRegisteredException; use PHPUnit\Framework\MockObject\MethodCannotBeConfiguredException; use PHPUnit\Framework\MockObject\MethodNameAlreadyConfiguredException; use PHPUnit\Framework\MockObject\MethodNameNotConfiguredException; use PHPUnit\Framework\MockObject\MethodParametersAlreadyConfiguredException; use PHPUnit\Framework\MockObject\Rule; use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls; use PHPUnit\Framework\MockObject\Stub\Exception; use PHPUnit\Framework\MockObject\Stub\ReturnArgument; use PHPUnit\Framework\MockObject\Stub\ReturnCallback; use PHPUnit\Framework\MockObject\Stub\ReturnReference; use PHPUnit\Framework\MockObject\Stub\ReturnSelf; use PHPUnit\Framework\MockObject\Stub\ReturnStub; use PHPUnit\Framework\MockObject\Stub\ReturnValueMap; use PHPUnit\Framework\MockObject\Stub\Stub; use Throwable; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ final class InvocationMocker implements InvocationStubber, MethodNameMatch { private readonly InvocationHandler $invocationHandler; private readonly Matcher $matcher; /** * @psalm-var list<ConfigurableMethod> */ private readonly array $configurableMethods; /** * @psalm-var ?array<string, int> */ private ?array $configurableMethodNames = null; public function __construct(InvocationHandler $handler, Matcher $matcher, ConfigurableMethod ...$configurableMethods) { $this->invocationHandler = $handler; $this->matcher = $matcher; $this->configurableMethods = $configurableMethods; } /** * @throws MatcherAlreadyRegisteredException * * @return $this */ public function id(string $id): self { $this->invocationHandler->registerMatcher($id, $this->matcher); return $this; } /** * @return $this */ public function will(Stub $stub): Identity { $this->matcher->setStub($stub); return $this; } /** * @throws IncompatibleReturnValueException */ public function willReturn(mixed $value, mixed ...$nextValues): self { if (count($nextValues) === 0) { $this->ensureTypeOfReturnValues([$value]); $stub = $value instanceof Stub ? $value : new ReturnStub($value); return $this->will($stub); } $values = array_merge([$value], $nextValues); $this->ensureTypeOfReturnValues($values); $stub = new ConsecutiveCalls($values); return $this->will($stub); } public function willReturnReference(mixed &$reference): self { $stub = new ReturnReference($reference); return $this->will($stub); } public function willReturnMap(array $valueMap): self { $stub = new ReturnValueMap($valueMap); return $this->will($stub); } public function willReturnArgument(int $argumentIndex): self { $stub = new ReturnArgument($argumentIndex); return $this->will($stub); } public function willReturnCallback(callable $callback): self { $stub = new ReturnCallback($callback); return $this->will($stub); } public function willReturnSelf(): self { $stub = new ReturnSelf; return $this->will($stub); } public function willReturnOnConsecutiveCalls(mixed ...$values): self { $stub = new ConsecutiveCalls($values); return $this->will($stub); } public function willThrowException(Throwable $exception): self { $stub = new Exception($exception); return $this->will($stub); } /** * @return $this */ public function after(string $id): self { $this->matcher->setAfterMatchBuilderId($id); return $this; } /** * @throws \PHPUnit\Framework\Exception * @throws MethodNameNotConfiguredException * @throws MethodParametersAlreadyConfiguredException * * @return $this */ public function with(mixed ...$arguments): self { $this->ensureParametersCanBeConfigured(); $this->matcher->setParametersRule(new Rule\Parameters($arguments)); return $this; } /** * @throws MethodNameNotConfiguredException * @throws MethodParametersAlreadyConfiguredException * * @return $this */ public function withAnyParameters(): self { $this->ensureParametersCanBeConfigured(); $this->matcher->setParametersRule(new Rule\AnyParameters); return $this; } /** * @throws InvalidArgumentException * @throws MethodCannotBeConfiguredException * @throws MethodNameAlreadyConfiguredException * * @return $this */ public function method(Constraint|string $constraint): self { if ($this->matcher->hasMethodNameRule()) { throw new MethodNameAlreadyConfiguredException; } if (is_string($constraint)) { $this->configurableMethodNames ??= array_flip( array_map( static fn (ConfigurableMethod $configurable) => strtolower($configurable->name()), $this->configurableMethods, ), ); if (!array_key_exists(strtolower($constraint), $this->configurableMethodNames)) { throw new MethodCannotBeConfiguredException($constraint); } } $this->matcher->setMethodNameRule(new Rule\MethodName($constraint)); return $this; } /** * @throws MethodNameNotConfiguredException * @throws MethodParametersAlreadyConfiguredException */ private function ensureParametersCanBeConfigured(): void { if (!$this->matcher->hasMethodNameRule()) { throw new MethodNameNotConfiguredException; } if ($this->matcher->hasParametersRule()) { throw new MethodParametersAlreadyConfiguredException; } } private function configuredMethod(): ?ConfigurableMethod { $configuredMethod = null; foreach ($this->configurableMethods as $configurableMethod) { if ($this->matcher->methodNameRule()->matchesName($configurableMethod->name())) { if ($configuredMethod !== null) { return null; } $configuredMethod = $configurableMethod; } } return $configuredMethod; } /** * @throws IncompatibleReturnValueException */ private function ensureTypeOfReturnValues(array $values): void { $configuredMethod = $this->configuredMethod(); if ($configuredMethod === null) { return; } foreach ($values as $value) { if (!$configuredMethod->mayReturn($value)) { throw new IncompatibleReturnValueException( $configuredMethod, $value, ); } } } } MockObject/Runtime/Builder/MethodNameMatch.php 0000644 00000001272 15107326342 0015311 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; use PHPUnit\Framework\Constraint\Constraint; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface MethodNameMatch extends ParametersMatch { /** * Adds a new method name match and returns the parameter match object for * further matching possibilities. */ public function method(Constraint|string $constraint): self; } MockObject/Runtime/Builder/Stub.php 0000644 00000001303 15107326342 0013223 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; use PHPUnit\Framework\MockObject\Stub\Stub as BaseStub; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface Stub extends Identity { /** * Stubs the matching method with the stub object $stub. Any invocations of * the matched method will now be handled by the stub instead. */ public function will(BaseStub $stub): Identity; } MockObject/Runtime/Rule/ParametersRule.php 0000644 00000001353 15107326342 0014567 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Rule; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ interface ParametersRule { /** * @throws ExpectationFailedException if the invocation violates the rule */ public function apply(BaseInvocation $invocation): void; public function verify(): void; } MockObject/Runtime/Rule/InvokedCount.php 0000644 00000005106 15107326342 0014244 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Rule; use function sprintf; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class InvokedCount extends InvocationOrder { private readonly int $expectedCount; public function __construct(int $expectedCount) { $this->expectedCount = $expectedCount; } public function isNever(): bool { return $this->expectedCount === 0; } public function toString(): string { return sprintf( 'invoked %d time%s', $this->expectedCount, $this->expectedCount !== 1 ? 's' : '', ); } public function matches(BaseInvocation $invocation): bool { return true; } /** * Verifies that the current expectation is valid. If everything is OK the * code should just return, if not it must throw an exception. * * @throws ExpectationFailedException */ public function verify(): void { $actualCount = $this->numberOfInvocations(); if ($actualCount !== $this->expectedCount) { throw new ExpectationFailedException( sprintf( 'Method was expected to be called %d time%s, actually called %d time%s.', $this->expectedCount, $this->expectedCount !== 1 ? 's' : '', $actualCount, $actualCount !== 1 ? 's' : '', ), ); } } /** * @throws ExpectationFailedException */ protected function invokedDo(BaseInvocation $invocation): void { $count = $this->numberOfInvocations(); if ($count > $this->expectedCount) { $message = $invocation->toString() . ' '; $message .= match ($this->expectedCount) { 0 => 'was not expected to be called.', 1 => 'was not expected to be called more than once.', default => sprintf( 'was not expected to be called more than %d times.', $this->expectedCount, ), }; throw new ExpectationFailedException($message); } } } MockObject/Runtime/Rule/MethodName.php 0000644 00000003006 15107326342 0013652 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Rule; use function is_string; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\InvalidArgumentException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; use PHPUnit\Framework\MockObject\MethodNameConstraint; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class MethodName { private readonly Constraint $constraint; /** * @throws InvalidArgumentException */ public function __construct(Constraint|string $constraint) { if (is_string($constraint)) { $constraint = new MethodNameConstraint($constraint); } $this->constraint = $constraint; } public function toString(): string { return 'method name ' . $this->constraint->toString(); } /** * @throws \PHPUnit\Framework\ExpectationFailedException */ public function matches(BaseInvocation $invocation): bool { return $this->matchesName($invocation->methodName()); } /** * @throws \PHPUnit\Framework\ExpectationFailedException */ public function matchesName(string $methodName): bool { return (bool) $this->constraint->evaluate($methodName, '', true); } } MockObject/Runtime/Rule/InvokedAtLeastOnce.php 0000644 00000002330 15107326342 0015312 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Rule; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class InvokedAtLeastOnce extends InvocationOrder { public function toString(): string { return 'invoked at least once'; } /** * Verifies that the current expectation is valid. If everything is OK the * code should just return, if not it must throw an exception. * * @throws ExpectationFailedException */ public function verify(): void { $count = $this->numberOfInvocations(); if ($count < 1) { throw new ExpectationFailedException( 'Expected invocation at least once but it never occurred.', ); } } public function matches(BaseInvocation $invocation): bool { return true; } } MockObject/Runtime/Rule/InvokedAtLeastCount.php 0000644 00000003543 15107326342 0015525 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Rule; use function sprintf; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class InvokedAtLeastCount extends InvocationOrder { private readonly int $requiredInvocations; public function __construct(int $requiredInvocations) { $this->requiredInvocations = $requiredInvocations; } public function toString(): string { return sprintf( 'invoked at least %d time%s', $this->requiredInvocations, $this->requiredInvocations !== 1 ? 's' : '', ); } /** * Verifies that the current expectation is valid. If everything is OK the * code should just return, if not it must throw an exception. * * @throws ExpectationFailedException */ public function verify(): void { $actualInvocations = $this->numberOfInvocations(); if ($actualInvocations < $this->requiredInvocations) { throw new ExpectationFailedException( sprintf( 'Expected invocation at least %d time%s but it occurred %d time%s.', $this->requiredInvocations, $this->requiredInvocations !== 1 ? 's' : '', $actualInvocations, $actualInvocations !== 1 ? 's' : '', ), ); } } public function matches(BaseInvocation $invocation): bool { return true; } } MockObject/Runtime/Rule/InvocationOrder.php 0000644 00000002327 15107326342 0014743 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Rule; use function count; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; use PHPUnit\Framework\SelfDescribing; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ abstract class InvocationOrder implements SelfDescribing { /** * @psalm-var list<BaseInvocation> */ private array $invocations = []; public function numberOfInvocations(): int { return count($this->invocations); } public function hasBeenInvoked(): bool { return count($this->invocations) > 0; } final public function invoked(BaseInvocation $invocation): void { $this->invocations[] = $invocation; $this->invokedDo($invocation); } abstract public function matches(BaseInvocation $invocation): bool; abstract public function verify(): void; protected function invokedDo(BaseInvocation $invocation): void { } } MockObject/Runtime/Rule/InvokedAtMostCount.php 0000644 00000003527 15107326342 0015401 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Rule; use function sprintf; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class InvokedAtMostCount extends InvocationOrder { private readonly int $allowedInvocations; public function __construct(int $allowedInvocations) { $this->allowedInvocations = $allowedInvocations; } public function toString(): string { return sprintf( 'invoked at most %d time%s', $this->allowedInvocations, $this->allowedInvocations !== 1 ? 's' : '', ); } /** * Verifies that the current expectation is valid. If everything is OK the * code should just return, if not it must throw an exception. * * @throws ExpectationFailedException */ public function verify(): void { $actualInvocations = $this->numberOfInvocations(); if ($actualInvocations > $this->allowedInvocations) { throw new ExpectationFailedException( sprintf( 'Expected invocation at most %d time%s but it occurred %d time%s.', $this->allowedInvocations, $this->allowedInvocations !== 1 ? 's' : '', $actualInvocations, $actualInvocations !== 1 ? 's' : '', ), ); } } public function matches(BaseInvocation $invocation): bool { return true; } } MockObject/Runtime/Rule/AnyInvokedCount.php 0000644 00000001364 15107326342 0014716 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Rule; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class AnyInvokedCount extends InvocationOrder { public function toString(): string { return 'invoked zero or more times'; } public function verify(): void { } public function matches(BaseInvocation $invocation): bool { return true; } } MockObject/Runtime/Rule/AnyParameters.php 0000644 00000001174 15107326342 0014410 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Rule; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class AnyParameters implements ParametersRule { public function apply(BaseInvocation $invocation): void { } public function verify(): void { } } MockObject/Runtime/Rule/Parameters.php 0000644 00000010044 15107326342 0013734 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Rule; use function count; use function sprintf; use Exception; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\IsAnything; use PHPUnit\Framework\Constraint\IsEqual; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class Parameters implements ParametersRule { /** * @psalm-var list<Constraint> */ private array $parameters = []; private ?BaseInvocation $invocation = null; private null|bool|ExpectationFailedException $parameterVerificationResult; /** * @throws \PHPUnit\Framework\Exception */ public function __construct(array $parameters) { foreach ($parameters as $parameter) { if (!($parameter instanceof Constraint)) { $parameter = new IsEqual( $parameter, ); } $this->parameters[] = $parameter; } } /** * @throws Exception */ public function apply(BaseInvocation $invocation): void { $this->invocation = $invocation; $this->parameterVerificationResult = null; try { $this->parameterVerificationResult = $this->doVerify(); } catch (ExpectationFailedException $e) { $this->parameterVerificationResult = $e; throw $this->parameterVerificationResult; } } /** * Checks if the invocation $invocation matches the current rules. If it * does the rule will get the invoked() method called which should check * if an expectation is met. * * @throws ExpectationFailedException */ public function verify(): void { $this->doVerify(); } /** * @throws ExpectationFailedException */ private function doVerify(): bool { if (isset($this->parameterVerificationResult)) { return $this->guardAgainstDuplicateEvaluationOfParameterConstraints(); } if ($this->invocation === null) { throw new ExpectationFailedException('Mocked method does not exist.'); } if (count($this->invocation->parameters()) < count($this->parameters)) { $message = 'Parameter count for invocation %s is too low.'; // The user called `->with($this->anything())`, but may have meant // `->withAnyParameters()`. // // @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/199 if (count($this->parameters) === 1 && $this->parameters[0]::class === IsAnything::class) { $message .= "\nTo allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead."; } throw new ExpectationFailedException( sprintf($message, $this->invocation->toString()), ); } foreach ($this->parameters as $i => $parameter) { $parameter->evaluate( $this->invocation->parameters()[$i], sprintf( 'Parameter %s for invocation %s does not match expected ' . 'value.', $i, $this->invocation->toString(), ), ); } return true; } /** * @throws ExpectationFailedException */ private function guardAgainstDuplicateEvaluationOfParameterConstraints(): bool { if ($this->parameterVerificationResult instanceof ExpectationFailedException) { throw $this->parameterVerificationResult; } return (bool) $this->parameterVerificationResult; } } Assert.php 0000644 00000205623 15107326342 0006531 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function class_exists; use function count; use function file_get_contents; use function interface_exists; use function is_bool; use ArrayAccess; use Countable; use Generator; use PHPUnit\Event; use PHPUnit\Framework\Constraint\ArrayHasKey; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\Count; use PHPUnit\Framework\Constraint\DirectoryExists; use PHPUnit\Framework\Constraint\FileExists; use PHPUnit\Framework\Constraint\GreaterThan; use PHPUnit\Framework\Constraint\IsAnything; use PHPUnit\Framework\Constraint\IsEmpty; use PHPUnit\Framework\Constraint\IsEqual; use PHPUnit\Framework\Constraint\IsEqualCanonicalizing; use PHPUnit\Framework\Constraint\IsEqualIgnoringCase; use PHPUnit\Framework\Constraint\IsEqualWithDelta; use PHPUnit\Framework\Constraint\IsFalse; use PHPUnit\Framework\Constraint\IsFinite; use PHPUnit\Framework\Constraint\IsIdentical; use PHPUnit\Framework\Constraint\IsInfinite; use PHPUnit\Framework\Constraint\IsInstanceOf; use PHPUnit\Framework\Constraint\IsJson; use PHPUnit\Framework\Constraint\IsList; use PHPUnit\Framework\Constraint\IsNan; use PHPUnit\Framework\Constraint\IsNull; use PHPUnit\Framework\Constraint\IsReadable; use PHPUnit\Framework\Constraint\IsTrue; use PHPUnit\Framework\Constraint\IsType; use PHPUnit\Framework\Constraint\IsWritable; use PHPUnit\Framework\Constraint\JsonMatches; use PHPUnit\Framework\Constraint\LessThan; use PHPUnit\Framework\Constraint\LogicalAnd; use PHPUnit\Framework\Constraint\LogicalNot; use PHPUnit\Framework\Constraint\LogicalOr; use PHPUnit\Framework\Constraint\LogicalXor; use PHPUnit\Framework\Constraint\ObjectEquals; use PHPUnit\Framework\Constraint\ObjectHasProperty; use PHPUnit\Framework\Constraint\RegularExpression; use PHPUnit\Framework\Constraint\SameSize; use PHPUnit\Framework\Constraint\StringContains; use PHPUnit\Framework\Constraint\StringEndsWith; use PHPUnit\Framework\Constraint\StringEqualsStringIgnoringLineEndings; use PHPUnit\Framework\Constraint\StringMatchesFormatDescription; use PHPUnit\Framework\Constraint\StringStartsWith; use PHPUnit\Framework\Constraint\TraversableContainsEqual; use PHPUnit\Framework\Constraint\TraversableContainsIdentical; use PHPUnit\Framework\Constraint\TraversableContainsOnly; use PHPUnit\Util\Xml\Loader as XmlLoader; use PHPUnit\Util\Xml\XmlException; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ abstract class Assert { private static int $count = 0; /** * Asserts that an array has a specified key. * * @throws Exception * @throws ExpectationFailedException */ final public static function assertArrayHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void { $constraint = new ArrayHasKey($key); static::assertThat($array, $constraint, $message); } /** * Asserts that an array does not have a specified key. * * @throws Exception * @throws ExpectationFailedException */ final public static function assertArrayNotHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void { $constraint = new LogicalNot( new ArrayHasKey($key), ); static::assertThat($array, $constraint, $message); } /** * @throws ExpectationFailedException */ final public static function assertIsList(mixed $array, string $message = ''): void { static::assertThat( $array, new IsList, $message, ); } /** * Asserts that a haystack contains a needle. * * @throws Exception * @throws ExpectationFailedException */ final public static function assertContains(mixed $needle, iterable $haystack, string $message = ''): void { $constraint = new TraversableContainsIdentical($needle); static::assertThat($haystack, $constraint, $message); } /** * @throws ExpectationFailedException */ final public static function assertContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void { $constraint = new TraversableContainsEqual($needle); static::assertThat($haystack, $constraint, $message); } /** * Asserts that a haystack does not contain a needle. * * @throws Exception * @throws ExpectationFailedException */ final public static function assertNotContains(mixed $needle, iterable $haystack, string $message = ''): void { $constraint = new LogicalNot( new TraversableContainsIdentical($needle), ); static::assertThat($haystack, $constraint, $message); } /** * @throws ExpectationFailedException */ final public static function assertNotContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void { $constraint = new LogicalNot(new TraversableContainsEqual($needle)); static::assertThat($haystack, $constraint, $message); } /** * Asserts that a haystack contains only values of a given type. * * @throws Exception * @throws ExpectationFailedException */ final public static function assertContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void { if ($isNativeType === null) { $isNativeType = self::isNativeType($type); } static::assertThat( $haystack, new TraversableContainsOnly( $type, $isNativeType, ), $message, ); } /** * Asserts that a haystack contains only instances of a given class name. * * @throws Exception * @throws ExpectationFailedException */ final public static function assertContainsOnlyInstancesOf(string $className, iterable $haystack, string $message = ''): void { static::assertThat( $haystack, new TraversableContainsOnly( $className, false, ), $message, ); } /** * Asserts that a haystack does not contain only values of a given type. * * @throws Exception * @throws ExpectationFailedException */ final public static function assertNotContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void { if ($isNativeType === null) { $isNativeType = self::isNativeType($type); } static::assertThat( $haystack, new LogicalNot( new TraversableContainsOnly( $type, $isNativeType, ), ), $message, ); } /** * Asserts the number of elements of an array, Countable or Traversable. * * @throws Exception * @throws ExpectationFailedException * @throws GeneratorNotSupportedException */ final public static function assertCount(int $expectedCount, Countable|iterable $haystack, string $message = ''): void { if ($haystack instanceof Generator) { throw GeneratorNotSupportedException::fromParameterName('$haystack'); } static::assertThat( $haystack, new Count($expectedCount), $message, ); } /** * Asserts the number of elements of an array, Countable or Traversable. * * @throws Exception * @throws ExpectationFailedException * @throws GeneratorNotSupportedException */ final public static function assertNotCount(int $expectedCount, Countable|iterable $haystack, string $message = ''): void { if ($haystack instanceof Generator) { throw GeneratorNotSupportedException::fromParameterName('$haystack'); } $constraint = new LogicalNot( new Count($expectedCount), ); static::assertThat($haystack, $constraint, $message); } /** * Asserts that two variables are equal. * * @throws ExpectationFailedException */ final public static function assertEquals(mixed $expected, mixed $actual, string $message = ''): void { $constraint = new IsEqual($expected); static::assertThat($actual, $constraint, $message); } /** * Asserts that two variables are equal (canonicalizing). * * @throws ExpectationFailedException */ final public static function assertEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void { $constraint = new IsEqualCanonicalizing($expected); static::assertThat($actual, $constraint, $message); } /** * Asserts that two variables are equal (ignoring case). * * @throws ExpectationFailedException */ final public static function assertEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void { $constraint = new IsEqualIgnoringCase($expected); static::assertThat($actual, $constraint, $message); } /** * Asserts that two variables are equal (with delta). * * @throws ExpectationFailedException */ final public static function assertEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void { $constraint = new IsEqualWithDelta( $expected, $delta, ); static::assertThat($actual, $constraint, $message); } /** * Asserts that two variables are not equal. * * @throws ExpectationFailedException */ final public static function assertNotEquals(mixed $expected, mixed $actual, string $message = ''): void { $constraint = new LogicalNot( new IsEqual($expected), ); static::assertThat($actual, $constraint, $message); } /** * Asserts that two variables are not equal (canonicalizing). * * @throws ExpectationFailedException */ final public static function assertNotEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void { $constraint = new LogicalNot( new IsEqualCanonicalizing($expected), ); static::assertThat($actual, $constraint, $message); } /** * Asserts that two variables are not equal (ignoring case). * * @throws ExpectationFailedException */ final public static function assertNotEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void { $constraint = new LogicalNot( new IsEqualIgnoringCase($expected), ); static::assertThat($actual, $constraint, $message); } /** * Asserts that two variables are not equal (with delta). * * @throws ExpectationFailedException */ final public static function assertNotEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void { $constraint = new LogicalNot( new IsEqualWithDelta( $expected, $delta, ), ); static::assertThat($actual, $constraint, $message); } /** * @throws ExpectationFailedException */ final public static function assertObjectEquals(object $expected, object $actual, string $method = 'equals', string $message = ''): void { static::assertThat( $actual, static::objectEquals($expected, $method), $message, ); } /** * Asserts that a variable is empty. * * @throws ExpectationFailedException * @throws GeneratorNotSupportedException * * @psalm-assert empty $actual */ final public static function assertEmpty(mixed $actual, string $message = ''): void { if ($actual instanceof Generator) { throw GeneratorNotSupportedException::fromParameterName('$actual'); } static::assertThat($actual, static::isEmpty(), $message); } /** * Asserts that a variable is not empty. * * @throws ExpectationFailedException * @throws GeneratorNotSupportedException * * @psalm-assert !empty $actual */ final public static function assertNotEmpty(mixed $actual, string $message = ''): void { if ($actual instanceof Generator) { throw GeneratorNotSupportedException::fromParameterName('$actual'); } static::assertThat($actual, static::logicalNot(static::isEmpty()), $message); } /** * Asserts that a value is greater than another value. * * @throws ExpectationFailedException */ final public static function assertGreaterThan(mixed $expected, mixed $actual, string $message = ''): void { static::assertThat($actual, static::greaterThan($expected), $message); } /** * Asserts that a value is greater than or equal to another value. * * @throws ExpectationFailedException */ final public static function assertGreaterThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void { static::assertThat( $actual, static::greaterThanOrEqual($expected), $message, ); } /** * Asserts that a value is smaller than another value. * * @throws ExpectationFailedException */ final public static function assertLessThan(mixed $expected, mixed $actual, string $message = ''): void { static::assertThat($actual, static::lessThan($expected), $message); } /** * Asserts that a value is smaller than or equal to another value. * * @throws ExpectationFailedException */ final public static function assertLessThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void { static::assertThat($actual, static::lessThanOrEqual($expected), $message); } /** * Asserts that the contents of one file is equal to the contents of another * file. * * @throws ExpectationFailedException */ final public static function assertFileEquals(string $expected, string $actual, string $message = ''): void { static::assertFileExists($expected, $message); static::assertFileExists($actual, $message); $constraint = new IsEqual(file_get_contents($expected)); static::assertThat(file_get_contents($actual), $constraint, $message); } /** * Asserts that the contents of one file is equal to the contents of another * file (canonicalizing). * * @throws ExpectationFailedException */ final public static function assertFileEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void { static::assertFileExists($expected, $message); static::assertFileExists($actual, $message); $constraint = new IsEqualCanonicalizing( file_get_contents($expected), ); static::assertThat(file_get_contents($actual), $constraint, $message); } /** * Asserts that the contents of one file is equal to the contents of another * file (ignoring case). * * @throws ExpectationFailedException */ final public static function assertFileEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void { static::assertFileExists($expected, $message); static::assertFileExists($actual, $message); $constraint = new IsEqualIgnoringCase(file_get_contents($expected)); static::assertThat(file_get_contents($actual), $constraint, $message); } /** * Asserts that the contents of one file is not equal to the contents of * another file. * * @throws ExpectationFailedException */ final public static function assertFileNotEquals(string $expected, string $actual, string $message = ''): void { static::assertFileExists($expected, $message); static::assertFileExists($actual, $message); $constraint = new LogicalNot( new IsEqual(file_get_contents($expected)), ); static::assertThat(file_get_contents($actual), $constraint, $message); } /** * Asserts that the contents of one file is not equal to the contents of another * file (canonicalizing). * * @throws ExpectationFailedException */ final public static function assertFileNotEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void { static::assertFileExists($expected, $message); static::assertFileExists($actual, $message); $constraint = new LogicalNot( new IsEqualCanonicalizing(file_get_contents($expected)), ); static::assertThat(file_get_contents($actual), $constraint, $message); } /** * Asserts that the contents of one file is not equal to the contents of another * file (ignoring case). * * @throws ExpectationFailedException */ final public static function assertFileNotEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void { static::assertFileExists($expected, $message); static::assertFileExists($actual, $message); $constraint = new LogicalNot( new IsEqualIgnoringCase(file_get_contents($expected)), ); static::assertThat(file_get_contents($actual), $constraint, $message); } /** * Asserts that the contents of a string is equal * to the contents of a file. * * @throws ExpectationFailedException */ final public static function assertStringEqualsFile(string $expectedFile, string $actualString, string $message = ''): void { static::assertFileExists($expectedFile, $message); $constraint = new IsEqual(file_get_contents($expectedFile)); static::assertThat($actualString, $constraint, $message); } /** * Asserts that the contents of a string is equal * to the contents of a file (canonicalizing). * * @throws ExpectationFailedException */ final public static function assertStringEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void { static::assertFileExists($expectedFile, $message); $constraint = new IsEqualCanonicalizing(file_get_contents($expectedFile)); static::assertThat($actualString, $constraint, $message); } /** * Asserts that the contents of a string is equal * to the contents of a file (ignoring case). * * @throws ExpectationFailedException */ final public static function assertStringEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void { static::assertFileExists($expectedFile, $message); $constraint = new IsEqualIgnoringCase(file_get_contents($expectedFile)); static::assertThat($actualString, $constraint, $message); } /** * Asserts that the contents of a string is not equal * to the contents of a file. * * @throws ExpectationFailedException */ final public static function assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = ''): void { static::assertFileExists($expectedFile, $message); $constraint = new LogicalNot( new IsEqual(file_get_contents($expectedFile)), ); static::assertThat($actualString, $constraint, $message); } /** * Asserts that the contents of a string is not equal * to the contents of a file (canonicalizing). * * @throws ExpectationFailedException */ final public static function assertStringNotEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void { static::assertFileExists($expectedFile, $message); $constraint = new LogicalNot( new IsEqualCanonicalizing(file_get_contents($expectedFile)), ); static::assertThat($actualString, $constraint, $message); } /** * Asserts that the contents of a string is not equal * to the contents of a file (ignoring case). * * @throws ExpectationFailedException */ final public static function assertStringNotEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void { static::assertFileExists($expectedFile, $message); $constraint = new LogicalNot( new IsEqualIgnoringCase(file_get_contents($expectedFile)), ); static::assertThat($actualString, $constraint, $message); } /** * Asserts that a file/dir is readable. * * @throws ExpectationFailedException */ final public static function assertIsReadable(string $filename, string $message = ''): void { static::assertThat($filename, new IsReadable, $message); } /** * Asserts that a file/dir exists and is not readable. * * @throws ExpectationFailedException */ final public static function assertIsNotReadable(string $filename, string $message = ''): void { static::assertThat($filename, new LogicalNot(new IsReadable), $message); } /** * Asserts that a file/dir exists and is writable. * * @throws ExpectationFailedException */ final public static function assertIsWritable(string $filename, string $message = ''): void { static::assertThat($filename, new IsWritable, $message); } /** * Asserts that a file/dir exists and is not writable. * * @throws ExpectationFailedException */ final public static function assertIsNotWritable(string $filename, string $message = ''): void { static::assertThat($filename, new LogicalNot(new IsWritable), $message); } /** * Asserts that a directory exists. * * @throws ExpectationFailedException */ final public static function assertDirectoryExists(string $directory, string $message = ''): void { static::assertThat($directory, new DirectoryExists, $message); } /** * Asserts that a directory does not exist. * * @throws ExpectationFailedException */ final public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void { static::assertThat($directory, new LogicalNot(new DirectoryExists), $message); } /** * Asserts that a directory exists and is readable. * * @throws ExpectationFailedException */ final public static function assertDirectoryIsReadable(string $directory, string $message = ''): void { self::assertDirectoryExists($directory, $message); self::assertIsReadable($directory, $message); } /** * Asserts that a directory exists and is not readable. * * @throws ExpectationFailedException */ final public static function assertDirectoryIsNotReadable(string $directory, string $message = ''): void { self::assertDirectoryExists($directory, $message); self::assertIsNotReadable($directory, $message); } /** * Asserts that a directory exists and is writable. * * @throws ExpectationFailedException */ final public static function assertDirectoryIsWritable(string $directory, string $message = ''): void { self::assertDirectoryExists($directory, $message); self::assertIsWritable($directory, $message); } /** * Asserts that a directory exists and is not writable. * * @throws ExpectationFailedException */ final public static function assertDirectoryIsNotWritable(string $directory, string $message = ''): void { self::assertDirectoryExists($directory, $message); self::assertIsNotWritable($directory, $message); } /** * Asserts that a file exists. * * @throws ExpectationFailedException */ final public static function assertFileExists(string $filename, string $message = ''): void { static::assertThat($filename, new FileExists, $message); } /** * Asserts that a file does not exist. * * @throws ExpectationFailedException */ final public static function assertFileDoesNotExist(string $filename, string $message = ''): void { static::assertThat($filename, new LogicalNot(new FileExists), $message); } /** * Asserts that a file exists and is readable. * * @throws ExpectationFailedException */ final public static function assertFileIsReadable(string $file, string $message = ''): void { self::assertFileExists($file, $message); self::assertIsReadable($file, $message); } /** * Asserts that a file exists and is not readable. * * @throws ExpectationFailedException */ final public static function assertFileIsNotReadable(string $file, string $message = ''): void { self::assertFileExists($file, $message); self::assertIsNotReadable($file, $message); } /** * Asserts that a file exists and is writable. * * @throws ExpectationFailedException */ final public static function assertFileIsWritable(string $file, string $message = ''): void { self::assertFileExists($file, $message); self::assertIsWritable($file, $message); } /** * Asserts that a file exists and is not writable. * * @throws ExpectationFailedException */ final public static function assertFileIsNotWritable(string $file, string $message = ''): void { self::assertFileExists($file, $message); self::assertIsNotWritable($file, $message); } /** * Asserts that a condition is true. * * @throws ExpectationFailedException * * @psalm-assert true $condition */ final public static function assertTrue(mixed $condition, string $message = ''): void { static::assertThat($condition, static::isTrue(), $message); } /** * Asserts that a condition is not true. * * @throws ExpectationFailedException * * @psalm-assert !true $condition */ final public static function assertNotTrue(mixed $condition, string $message = ''): void { static::assertThat($condition, static::logicalNot(static::isTrue()), $message); } /** * Asserts that a condition is false. * * @throws ExpectationFailedException * * @psalm-assert false $condition */ final public static function assertFalse(mixed $condition, string $message = ''): void { static::assertThat($condition, static::isFalse(), $message); } /** * Asserts that a condition is not false. * * @throws ExpectationFailedException * * @psalm-assert !false $condition */ final public static function assertNotFalse(mixed $condition, string $message = ''): void { static::assertThat($condition, static::logicalNot(static::isFalse()), $message); } /** * Asserts that a variable is null. * * @throws ExpectationFailedException * * @psalm-assert null $actual */ final public static function assertNull(mixed $actual, string $message = ''): void { static::assertThat($actual, static::isNull(), $message); } /** * Asserts that a variable is not null. * * @throws ExpectationFailedException * * @psalm-assert !null $actual */ final public static function assertNotNull(mixed $actual, string $message = ''): void { static::assertThat($actual, static::logicalNot(static::isNull()), $message); } /** * Asserts that a variable is finite. * * @throws ExpectationFailedException */ final public static function assertFinite(mixed $actual, string $message = ''): void { static::assertThat($actual, static::isFinite(), $message); } /** * Asserts that a variable is infinite. * * @throws ExpectationFailedException */ final public static function assertInfinite(mixed $actual, string $message = ''): void { static::assertThat($actual, static::isInfinite(), $message); } /** * Asserts that a variable is nan. * * @throws ExpectationFailedException */ final public static function assertNan(mixed $actual, string $message = ''): void { static::assertThat($actual, static::isNan(), $message); } /** * Asserts that an object has a specified property. * * @throws ExpectationFailedException */ final public static function assertObjectHasProperty(string $propertyName, object $object, string $message = ''): void { static::assertThat( $object, new ObjectHasProperty($propertyName), $message, ); } /** * Asserts that an object does not have a specified property. * * @throws ExpectationFailedException */ final public static function assertObjectNotHasProperty(string $propertyName, object $object, string $message = ''): void { static::assertThat( $object, new LogicalNot( new ObjectHasProperty($propertyName), ), $message, ); } /** * Asserts that two variables have the same type and value. * Used on objects, it asserts that two variables reference * the same object. * * @throws ExpectationFailedException * * @psalm-template ExpectedType * * @psalm-param ExpectedType $expected * * @psalm-assert =ExpectedType $actual */ final public static function assertSame(mixed $expected, mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsIdentical($expected), $message, ); } /** * Asserts that two variables do not have the same type and value. * Used on objects, it asserts that two variables do not reference * the same object. * * @throws ExpectationFailedException */ final public static function assertNotSame(mixed $expected, mixed $actual, string $message = ''): void { if (is_bool($expected) && is_bool($actual)) { static::assertNotEquals($expected, $actual, $message); } static::assertThat( $actual, new LogicalNot( new IsIdentical($expected), ), $message, ); } /** * Asserts that a variable is of a given type. * * @throws Exception * @throws ExpectationFailedException * @throws UnknownClassOrInterfaceException * * @psalm-template ExpectedType of object * * @psalm-param class-string<ExpectedType> $expected * * @psalm-assert =ExpectedType $actual */ final public static function assertInstanceOf(string $expected, mixed $actual, string $message = ''): void { if (!class_exists($expected) && !interface_exists($expected)) { throw new UnknownClassOrInterfaceException($expected); } static::assertThat( $actual, new IsInstanceOf($expected), $message, ); } /** * Asserts that a variable is not of a given type. * * @throws Exception * @throws ExpectationFailedException * * @psalm-template ExpectedType of object * * @psalm-param class-string<ExpectedType> $expected * * @psalm-assert !ExpectedType $actual */ final public static function assertNotInstanceOf(string $expected, mixed $actual, string $message = ''): void { if (!class_exists($expected) && !interface_exists($expected)) { throw new UnknownClassOrInterfaceException($expected); } static::assertThat( $actual, new LogicalNot( new IsInstanceOf($expected), ), $message, ); } /** * Asserts that a variable is of type array. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert array $actual */ final public static function assertIsArray(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_ARRAY), $message, ); } /** * Asserts that a variable is of type bool. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert bool $actual */ final public static function assertIsBool(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_BOOL), $message, ); } /** * Asserts that a variable is of type float. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert float $actual */ final public static function assertIsFloat(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_FLOAT), $message, ); } /** * Asserts that a variable is of type int. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert int $actual */ final public static function assertIsInt(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_INT), $message, ); } /** * Asserts that a variable is of type numeric. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert numeric $actual */ final public static function assertIsNumeric(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_NUMERIC), $message, ); } /** * Asserts that a variable is of type object. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert object $actual */ final public static function assertIsObject(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_OBJECT), $message, ); } /** * Asserts that a variable is of type resource. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert resource $actual */ final public static function assertIsResource(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_RESOURCE), $message, ); } /** * Asserts that a variable is of type resource and is closed. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert resource $actual */ final public static function assertIsClosedResource(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_CLOSED_RESOURCE), $message, ); } /** * Asserts that a variable is of type string. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert string $actual */ final public static function assertIsString(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_STRING), $message, ); } /** * Asserts that a variable is of type scalar. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert scalar $actual */ final public static function assertIsScalar(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_SCALAR), $message, ); } /** * Asserts that a variable is of type callable. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert callable $actual */ final public static function assertIsCallable(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_CALLABLE), $message, ); } /** * Asserts that a variable is of type iterable. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert iterable $actual */ final public static function assertIsIterable(mixed $actual, string $message = ''): void { static::assertThat( $actual, new IsType(IsType::TYPE_ITERABLE), $message, ); } /** * Asserts that a variable is not of type array. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !array $actual */ final public static function assertIsNotArray(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_ARRAY)), $message, ); } /** * Asserts that a variable is not of type bool. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !bool $actual */ final public static function assertIsNotBool(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_BOOL)), $message, ); } /** * Asserts that a variable is not of type float. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !float $actual */ final public static function assertIsNotFloat(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_FLOAT)), $message, ); } /** * Asserts that a variable is not of type int. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !int $actual */ final public static function assertIsNotInt(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_INT)), $message, ); } /** * Asserts that a variable is not of type numeric. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !numeric $actual */ final public static function assertIsNotNumeric(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_NUMERIC)), $message, ); } /** * Asserts that a variable is not of type object. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !object $actual */ final public static function assertIsNotObject(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_OBJECT)), $message, ); } /** * Asserts that a variable is not of type resource. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !resource $actual */ final public static function assertIsNotResource(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_RESOURCE)), $message, ); } /** * Asserts that a variable is not of type resource. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !resource $actual */ final public static function assertIsNotClosedResource(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_CLOSED_RESOURCE)), $message, ); } /** * Asserts that a variable is not of type string. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !string $actual */ final public static function assertIsNotString(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_STRING)), $message, ); } /** * Asserts that a variable is not of type scalar. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !scalar $actual */ final public static function assertIsNotScalar(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_SCALAR)), $message, ); } /** * Asserts that a variable is not of type callable. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !callable $actual */ final public static function assertIsNotCallable(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_CALLABLE)), $message, ); } /** * Asserts that a variable is not of type iterable. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !iterable $actual */ final public static function assertIsNotIterable(mixed $actual, string $message = ''): void { static::assertThat( $actual, new LogicalNot(new IsType(IsType::TYPE_ITERABLE)), $message, ); } /** * Asserts that a string matches a given regular expression. * * @throws ExpectationFailedException */ final public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void { static::assertThat($string, new RegularExpression($pattern), $message); } /** * Asserts that a string does not match a given regular expression. * * @throws ExpectationFailedException */ final public static function assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = ''): void { static::assertThat( $string, new LogicalNot( new RegularExpression($pattern), ), $message, ); } /** * Assert that the size of two arrays (or `Countable` or `Traversable` objects) * is the same. * * @throws Exception * @throws ExpectationFailedException * @throws GeneratorNotSupportedException */ final public static function assertSameSize(Countable|iterable $expected, Countable|iterable $actual, string $message = ''): void { if ($expected instanceof Generator) { throw GeneratorNotSupportedException::fromParameterName('$expected'); } if ($actual instanceof Generator) { throw GeneratorNotSupportedException::fromParameterName('$actual'); } static::assertThat( $actual, new SameSize($expected), $message, ); } /** * Assert that the size of two arrays (or `Countable` or `Traversable` objects) * is not the same. * * @throws Exception * @throws ExpectationFailedException * @throws GeneratorNotSupportedException */ final public static function assertNotSameSize(Countable|iterable $expected, Countable|iterable $actual, string $message = ''): void { if ($expected instanceof Generator) { throw GeneratorNotSupportedException::fromParameterName('$expected'); } if ($actual instanceof Generator) { throw GeneratorNotSupportedException::fromParameterName('$actual'); } static::assertThat( $actual, new LogicalNot( new SameSize($expected), ), $message, ); } /** * @throws ExpectationFailedException */ final public static function assertStringContainsStringIgnoringLineEndings(string $needle, string $haystack, string $message = ''): void { static::assertThat($haystack, new StringContains($needle, false, true), $message); } /** * Asserts that two strings are equal except for line endings. * * @throws ExpectationFailedException */ final public static function assertStringEqualsStringIgnoringLineEndings(string $expected, string $actual, string $message = ''): void { static::assertThat($actual, new StringEqualsStringIgnoringLineEndings($expected), $message); } /** * Asserts that a string matches a given format string. * * @throws ExpectationFailedException */ final public static function assertFileMatchesFormat(string $format, string $actualFile, string $message = ''): void { static::assertFileExists($actualFile, $message); static::assertThat( file_get_contents($actualFile), new StringMatchesFormatDescription($format), $message, ); } /** * Asserts that a string matches a given format string. * * @throws ExpectationFailedException */ final public static function assertFileMatchesFormatFile(string $formatFile, string $actualFile, string $message = ''): void { static::assertFileExists($formatFile, $message); static::assertFileExists($actualFile, $message); static::assertThat( file_get_contents($actualFile), new StringMatchesFormatDescription(file_get_contents($formatFile)), $message, ); } /** * Asserts that a string matches a given format string. * * @throws ExpectationFailedException */ final public static function assertStringMatchesFormat(string $format, string $string, string $message = ''): void { static::assertThat($string, new StringMatchesFormatDescription($format), $message); } /** * Asserts that a string does not match a given format string. * * @throws ExpectationFailedException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5472 */ final public static function assertStringNotMatchesFormat(string $format, string $string, string $message = ''): void { static::assertThat( $string, new LogicalNot( new StringMatchesFormatDescription($format), ), $message, ); } /** * Asserts that a string matches a given format file. * * @throws ExpectationFailedException */ final public static function assertStringMatchesFormatFile(string $formatFile, string $string, string $message = ''): void { static::assertFileExists($formatFile, $message); static::assertThat( $string, new StringMatchesFormatDescription( file_get_contents($formatFile), ), $message, ); } /** * Asserts that a string does not match a given format string. * * @throws ExpectationFailedException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5472 */ final public static function assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = ''): void { static::assertFileExists($formatFile, $message); static::assertThat( $string, new LogicalNot( new StringMatchesFormatDescription( file_get_contents($formatFile), ), ), $message, ); } /** * Asserts that a string starts with a given prefix. * * @psalm-param non-empty-string $prefix * * @throws ExpectationFailedException * @throws InvalidArgumentException */ final public static function assertStringStartsWith(string $prefix, string $string, string $message = ''): void { static::assertThat($string, new StringStartsWith($prefix), $message); } /** * Asserts that a string starts not with a given prefix. * * @psalm-param non-empty-string $prefix * * @throws ExpectationFailedException * @throws InvalidArgumentException */ final public static function assertStringStartsNotWith(string $prefix, string $string, string $message = ''): void { static::assertThat( $string, new LogicalNot( new StringStartsWith($prefix), ), $message, ); } /** * @throws ExpectationFailedException */ final public static function assertStringContainsString(string $needle, string $haystack, string $message = ''): void { $constraint = new StringContains($needle); static::assertThat($haystack, $constraint, $message); } /** * @throws ExpectationFailedException */ final public static function assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void { $constraint = new StringContains($needle, true); static::assertThat($haystack, $constraint, $message); } /** * @throws ExpectationFailedException */ final public static function assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void { $constraint = new LogicalNot(new StringContains($needle)); static::assertThat($haystack, $constraint, $message); } /** * @throws ExpectationFailedException */ final public static function assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void { $constraint = new LogicalNot(new StringContains($needle, true)); static::assertThat($haystack, $constraint, $message); } /** * Asserts that a string ends with a given suffix. * * @psalm-param non-empty-string $suffix * * @throws ExpectationFailedException * @throws InvalidArgumentException */ final public static function assertStringEndsWith(string $suffix, string $string, string $message = ''): void { static::assertThat($string, new StringEndsWith($suffix), $message); } /** * Asserts that a string ends not with a given suffix. * * @psalm-param non-empty-string $suffix * * @throws ExpectationFailedException * @throws InvalidArgumentException */ final public static function assertStringEndsNotWith(string $suffix, string $string, string $message = ''): void { static::assertThat( $string, new LogicalNot( new StringEndsWith($suffix), ), $message, ); } /** * Asserts that two XML files are equal. * * @throws Exception * @throws ExpectationFailedException * @throws XmlException */ final public static function assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void { $expected = (new XmlLoader)->loadFile($expectedFile); $actual = (new XmlLoader)->loadFile($actualFile); static::assertEquals($expected, $actual, $message); } /** * Asserts that two XML files are not equal. * * @throws \PHPUnit\Util\Exception * @throws ExpectationFailedException */ final public static function assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void { $expected = (new XmlLoader)->loadFile($expectedFile); $actual = (new XmlLoader)->loadFile($actualFile); static::assertNotEquals($expected, $actual, $message); } /** * Asserts that two XML documents are equal. * * @throws ExpectationFailedException * @throws XmlException */ final public static function assertXmlStringEqualsXmlFile(string $expectedFile, string $actualXml, string $message = ''): void { $expected = (new XmlLoader)->loadFile($expectedFile); $actual = (new XmlLoader)->load($actualXml); static::assertEquals($expected, $actual, $message); } /** * Asserts that two XML documents are not equal. * * @throws ExpectationFailedException * @throws XmlException */ final public static function assertXmlStringNotEqualsXmlFile(string $expectedFile, string $actualXml, string $message = ''): void { $expected = (new XmlLoader)->loadFile($expectedFile); $actual = (new XmlLoader)->load($actualXml); static::assertNotEquals($expected, $actual, $message); } /** * Asserts that two XML documents are equal. * * @throws ExpectationFailedException * @throws XmlException */ final public static function assertXmlStringEqualsXmlString(string $expectedXml, string $actualXml, string $message = ''): void { $expected = (new XmlLoader)->load($expectedXml); $actual = (new XmlLoader)->load($actualXml); static::assertEquals($expected, $actual, $message); } /** * Asserts that two XML documents are not equal. * * @throws ExpectationFailedException * @throws XmlException */ final public static function assertXmlStringNotEqualsXmlString(string $expectedXml, string $actualXml, string $message = ''): void { $expected = (new XmlLoader)->load($expectedXml); $actual = (new XmlLoader)->load($actualXml); static::assertNotEquals($expected, $actual, $message); } /** * Evaluates a PHPUnit\Framework\Constraint matcher object. * * @throws ExpectationFailedException */ final public static function assertThat(mixed $value, Constraint $constraint, string $message = ''): void { self::$count += count($constraint); $hasFailed = true; try { $constraint->evaluate($value, $message); $hasFailed = false; } finally { if ($hasFailed) { Event\Facade::emitter()->testAssertionFailed( $value, $constraint, $message, ); } else { Event\Facade::emitter()->testAssertionSucceeded( $value, $constraint, $message, ); } } } /** * Asserts that a string is a valid JSON string. * * @throws ExpectationFailedException */ final public static function assertJson(string $actual, string $message = ''): void { static::assertThat($actual, static::isJson(), $message); } /** * Asserts that two given JSON encoded objects or arrays are equal. * * @throws ExpectationFailedException */ final public static function assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void { static::assertJson($expectedJson, $message); static::assertJson($actualJson, $message); static::assertThat($actualJson, new JsonMatches($expectedJson), $message); } /** * Asserts that two given JSON encoded objects or arrays are not equal. * * @throws ExpectationFailedException */ final public static function assertJsonStringNotEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void { static::assertJson($expectedJson, $message); static::assertJson($actualJson, $message); static::assertThat( $actualJson, new LogicalNot( new JsonMatches($expectedJson), ), $message, ); } /** * Asserts that the generated JSON encoded object and the content of the given file are equal. * * @throws ExpectationFailedException */ final public static function assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void { static::assertFileExists($expectedFile, $message); $expectedJson = file_get_contents($expectedFile); static::assertJson($expectedJson, $message); static::assertJson($actualJson, $message); static::assertThat($actualJson, new JsonMatches($expectedJson), $message); } /** * Asserts that the generated JSON encoded object and the content of the given file are not equal. * * @throws ExpectationFailedException */ final public static function assertJsonStringNotEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void { static::assertFileExists($expectedFile, $message); $expectedJson = file_get_contents($expectedFile); static::assertJson($expectedJson, $message); static::assertJson($actualJson, $message); static::assertThat( $actualJson, new LogicalNot( new JsonMatches($expectedJson), ), $message, ); } /** * Asserts that two JSON files are equal. * * @throws ExpectationFailedException */ final public static function assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void { static::assertFileExists($expectedFile, $message); static::assertFileExists($actualFile, $message); $actualJson = file_get_contents($actualFile); $expectedJson = file_get_contents($expectedFile); static::assertJson($expectedJson, $message); static::assertJson($actualJson, $message); $constraintExpected = new JsonMatches( $expectedJson, ); $constraintActual = new JsonMatches($actualJson); static::assertThat($expectedJson, $constraintActual, $message); static::assertThat($actualJson, $constraintExpected, $message); } /** * Asserts that two JSON files are not equal. * * @throws ExpectationFailedException */ final public static function assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void { static::assertFileExists($expectedFile, $message); static::assertFileExists($actualFile, $message); $actualJson = file_get_contents($actualFile); $expectedJson = file_get_contents($expectedFile); static::assertJson($expectedJson, $message); static::assertJson($actualJson, $message); $constraintExpected = new JsonMatches( $expectedJson, ); $constraintActual = new JsonMatches($actualJson); static::assertThat($expectedJson, new LogicalNot($constraintActual), $message); static::assertThat($actualJson, new LogicalNot($constraintExpected), $message); } /** * @throws Exception */ final public static function logicalAnd(mixed ...$constraints): LogicalAnd { return LogicalAnd::fromConstraints(...$constraints); } final public static function logicalOr(mixed ...$constraints): LogicalOr { return LogicalOr::fromConstraints(...$constraints); } final public static function logicalNot(Constraint $constraint): LogicalNot { return new LogicalNot($constraint); } final public static function logicalXor(mixed ...$constraints): LogicalXor { return LogicalXor::fromConstraints(...$constraints); } final public static function anything(): IsAnything { return new IsAnything; } final public static function isTrue(): IsTrue { return new IsTrue; } /** * @psalm-template CallbackInput of mixed * * @psalm-param callable(CallbackInput $callback): bool $callback * * @psalm-return Callback<CallbackInput> */ final public static function callback(callable $callback): Callback { return new Callback($callback); } final public static function isFalse(): IsFalse { return new IsFalse; } final public static function isJson(): IsJson { return new IsJson; } final public static function isNull(): IsNull { return new IsNull; } final public static function isFinite(): IsFinite { return new IsFinite; } final public static function isInfinite(): IsInfinite { return new IsInfinite; } final public static function isNan(): IsNan { return new IsNan; } final public static function containsEqual(mixed $value): TraversableContainsEqual { return new TraversableContainsEqual($value); } final public static function containsIdentical(mixed $value): TraversableContainsIdentical { return new TraversableContainsIdentical($value); } /** * @throws Exception */ final public static function containsOnly(string $type): TraversableContainsOnly { return new TraversableContainsOnly($type); } /** * @throws Exception */ final public static function containsOnlyInstancesOf(string $className): TraversableContainsOnly { return new TraversableContainsOnly($className, false); } final public static function arrayHasKey(int|string $key): ArrayHasKey { return new ArrayHasKey($key); } final public static function isList(): IsList { return new IsList; } final public static function equalTo(mixed $value): IsEqual { return new IsEqual($value, 0.0, false, false); } final public static function equalToCanonicalizing(mixed $value): IsEqualCanonicalizing { return new IsEqualCanonicalizing($value); } final public static function equalToIgnoringCase(mixed $value): IsEqualIgnoringCase { return new IsEqualIgnoringCase($value); } final public static function equalToWithDelta(mixed $value, float $delta): IsEqualWithDelta { return new IsEqualWithDelta($value, $delta); } final public static function isEmpty(): IsEmpty { return new IsEmpty; } final public static function isWritable(): IsWritable { return new IsWritable; } final public static function isReadable(): IsReadable { return new IsReadable; } final public static function directoryExists(): DirectoryExists { return new DirectoryExists; } final public static function fileExists(): FileExists { return new FileExists; } final public static function greaterThan(mixed $value): GreaterThan { return new GreaterThan($value); } final public static function greaterThanOrEqual(mixed $value): LogicalOr { return static::logicalOr( new IsEqual($value), new GreaterThan($value), ); } final public static function identicalTo(mixed $value): IsIdentical { return new IsIdentical($value); } /** * @throws UnknownClassOrInterfaceException */ final public static function isInstanceOf(string $className): IsInstanceOf { return new IsInstanceOf($className); } /** * @psalm-param 'array'|'boolean'|'bool'|'double'|'float'|'integer'|'int'|'null'|'numeric'|'object'|'real'|'resource'|'resource (closed)'|'string'|'scalar'|'callable'|'iterable' $type * * @throws Exception */ final public static function isType(string $type): IsType { return new IsType($type); } final public static function lessThan(mixed $value): LessThan { return new LessThan($value); } final public static function lessThanOrEqual(mixed $value): LogicalOr { return static::logicalOr( new IsEqual($value), new LessThan($value), ); } final public static function matchesRegularExpression(string $pattern): RegularExpression { return new RegularExpression($pattern); } final public static function matches(string $string): StringMatchesFormatDescription { return new StringMatchesFormatDescription($string); } /** * @psalm-param non-empty-string $prefix * * @throws InvalidArgumentException */ final public static function stringStartsWith(string $prefix): StringStartsWith { return new StringStartsWith($prefix); } final public static function stringContains(string $string, bool $case = true): StringContains { return new StringContains($string, $case); } /** * @psalm-param non-empty-string $suffix * * @throws InvalidArgumentException */ final public static function stringEndsWith(string $suffix): StringEndsWith { return new StringEndsWith($suffix); } final public static function stringEqualsStringIgnoringLineEndings(string $string): StringEqualsStringIgnoringLineEndings { return new StringEqualsStringIgnoringLineEndings($string); } final public static function countOf(int $count): Count { return new Count($count); } final public static function objectEquals(object $object, string $method = 'equals'): ObjectEquals { return new ObjectEquals($object, $method); } /** * Fails a test with the given message. * * @throws AssertionFailedError */ final public static function fail(string $message = ''): never { self::$count++; throw new AssertionFailedError($message); } /** * Mark the test as incomplete. * * @throws IncompleteTestError */ final public static function markTestIncomplete(string $message = ''): never { throw new IncompleteTestError($message); } /** * Mark the test as skipped. * * @throws SkippedWithMessageException */ final public static function markTestSkipped(string $message = ''): never { throw new SkippedWithMessageException($message); } /** * Return the current assertion count. */ final public static function getCount(): int { return self::$count; } /** * Reset the assertion counter. */ final public static function resetCount(): void { self::$count = 0; } private static function isNativeType(string $type): bool { return match ($type) { 'numeric', 'integer', 'int', 'iterable', 'float', 'string', 'boolean', 'bool', 'null', 'array', 'object', 'resource', 'scalar' => true, default => false, }; } } Exception/Incomplete/IncompleteTest.php 0000644 00000000673 15107326342 0014262 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use Throwable; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface IncompleteTest extends Throwable { } Exception/Incomplete/IncompleteTestError.php 0000644 00000000727 15107326342 0015274 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class IncompleteTestError extends AssertionFailedError implements IncompleteTest { } Exception/AssertionFailedError.php 0000644 00000001152 15107326342 0013303 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ class AssertionFailedError extends Exception implements SelfDescribing { /** * Wrapper for getMessage() which is declared as final. */ public function toString(): string { return $this->getMessage(); } } Exception/ObjectEquals/ComparisonMethodDoesNotAcceptParameterTypeException.php 0000644 00000001475 15107326342 0024057 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ComparisonMethodDoesNotAcceptParameterTypeException extends Exception { public function __construct(string $className, string $methodName, string $type) { parent::__construct( sprintf( '%s is not an accepted argument type for comparison method %s::%s().', $type, $className, $methodName, ), ); } } Exception/ObjectEquals/ComparisonMethodDoesNotDeclareBoolReturnTypeException.php 0000644 00000001424 15107326342 0024364 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ComparisonMethodDoesNotDeclareBoolReturnTypeException extends Exception { public function __construct(string $className, string $methodName) { parent::__construct( sprintf( 'Comparison method %s::%s() does not declare bool return type.', $className, $methodName, ), ); } } Exception/ObjectEquals/ActualValueIsNotAnObjectException.php 0000644 00000001103 15107326342 0020242 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ActualValueIsNotAnObjectException extends Exception { public function __construct() { parent::__construct( 'Actual value is not an object', ); } } Exception/ObjectEquals/ComparisonMethodDoesNotDeclareParameterTypeException.php 0000644 00000001434 15107326342 0024212 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ComparisonMethodDoesNotDeclareParameterTypeException extends Exception { public function __construct(string $className, string $methodName) { parent::__construct( sprintf( 'Parameter of comparison method %s::%s() does not have a declared type.', $className, $methodName, ), ); } } Exception/ObjectEquals/ComparisonMethodDoesNotExistException.php 0000644 00000001361 15107326342 0021243 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ComparisonMethodDoesNotExistException extends Exception { public function __construct(string $className, string $methodName) { parent::__construct( sprintf( 'Comparison method %s::%s() does not exist.', $className, $methodName, ), ); } } Exception/ObjectEquals/ComparisonMethodDoesNotDeclareExactlyOneParameterException.php 0000644 00000001436 15107326342 0025346 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ComparisonMethodDoesNotDeclareExactlyOneParameterException extends Exception { public function __construct(string $className, string $methodName) { parent::__construct( sprintf( 'Comparison method %s::%s() does not declare exactly one parameter.', $className, $methodName, ), ); } } Exception/ProcessIsolationException.php 0000644 00000000670 15107326342 0014400 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ProcessIsolationException extends Exception { } Exception/Skipped/SkippedTestSuiteError.php 0000644 00000000726 15107326342 0015105 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class SkippedTestSuiteError extends AssertionFailedError implements SkippedTest { } Exception/Skipped/SkippedTest.php 0000644 00000000670 15107326342 0013057 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use Throwable; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface SkippedTest extends Throwable { } Exception/Skipped/SkippedWithMessageException.php 0000644 00000000734 15107326342 0016240 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class SkippedWithMessageException extends AssertionFailedError implements SkippedTest { } Exception/CodeCoverageException.php 0000644 00000000656 15107326342 0013432 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ class CodeCoverageException extends Exception { } Exception/ExpectationFailedException.php 0000644 00000002237 15107326342 0014471 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use Exception; use SebastianBergmann\Comparator\ComparisonFailure; /** * Exception for expectations which failed their check. * * The exception contains the error message and optionally a * SebastianBergmann\Comparator\ComparisonFailure which is used to * generate diff output of the failed expectations. * * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ExpectationFailedException extends AssertionFailedError { protected ?ComparisonFailure $comparisonFailure = null; public function __construct(string $message, ComparisonFailure $comparisonFailure = null, Exception $previous = null) { $this->comparisonFailure = $comparisonFailure; parent::__construct($message, 0, $previous); } public function getComparisonFailure(): ?ComparisonFailure { return $this->comparisonFailure; } } Exception/InvalidDependencyException.php 0000644 00000000733 15107326342 0014465 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class InvalidDependencyException extends AssertionFailedError implements SkippedTest { } Exception/Exception.php 0000644 00000004203 15107326342 0011153 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function array_keys; use function get_object_vars; use RuntimeException; use Throwable; /** * Base class for all PHPUnit Framework exceptions. * * Ensures that exceptions thrown during a test run do not leave stray * references behind. * * Every Exception contains a stack trace. Each stack frame contains the 'args' * of the called function. The function arguments can contain references to * instantiated objects. The references prevent the objects from being * destructed (until test results are eventually printed), so memory cannot be * freed up. * * With enabled process isolation, test results are serialized in the child * process and unserialized in the parent process. The stack trace of Exceptions * may contain objects that cannot be serialized or unserialized (e.g., PDO * connections). Unserializing user-space objects from the child process into * the parent would break the intended encapsulation of process isolation. * * @see http://fabien.potencier.org/article/9/php-serialization-stack-traces-and-exceptions * * @internal This class is not covered by the backward compatibility promise for PHPUnit */ class Exception extends RuntimeException implements \PHPUnit\Exception { protected array $serializableTrace; public function __construct(string $message = '', int $code = 0, Throwable $previous = null) { parent::__construct($message, $code, $previous); $this->serializableTrace = $this->getTrace(); foreach (array_keys($this->serializableTrace) as $key) { unset($this->serializableTrace[$key]['args']); } } public function __sleep(): array { return array_keys(get_object_vars($this)); } /** * Returns the serializable trace (without 'args'). */ public function getSerializableTrace(): array { return $this->serializableTrace; } } Exception/EmptyStringException.php 0000644 00000000702 15107326342 0013361 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class EmptyStringException extends InvalidArgumentException { } Exception/NoChildTestSuiteException.php 0000644 00000000670 15107326342 0014272 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class NoChildTestSuiteException extends Exception { } Exception/InvalidDataProviderException.php 0000644 00000000673 15107326342 0014776 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class InvalidDataProviderException extends Exception { } Exception/GeneratorNotSupportedException.php 0000644 00000001400 15107326342 0015405 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class GeneratorNotSupportedException extends InvalidArgumentException { public static function fromParameterName(string $parameterName): self { return new self( sprintf( 'Passing an argument of type Generator for the %s parameter is not supported', $parameterName, ), ); } } Exception/InvalidArgumentException.php 0000644 00000000672 15107326342 0014173 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ abstract class InvalidArgumentException extends Exception { } Exception/UnknownTypeException.php 0000644 00000001240 15107326342 0013373 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class UnknownTypeException extends InvalidArgumentException { public function __construct(string $name) { parent::__construct( sprintf( 'Type "%s" is not known', $name, ), ); } } Exception/UnknownClassOrInterfaceException.php 0000644 00000001274 15107326342 0015650 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function sprintf; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class UnknownClassOrInterfaceException extends InvalidArgumentException { public function __construct(string $name) { parent::__construct( sprintf( 'Class or interface "%s" does not exist', $name, ), ); } } Exception/PhptAssertionFailedError.php 0000644 00000002453 15107326342 0014144 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @psalm-immutable * * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class PhptAssertionFailedError extends AssertionFailedError { private readonly string $syntheticFile; private readonly int $syntheticLine; private readonly array $syntheticTrace; private readonly string $diff; public function __construct(string $message, int $code, string $file, int $line, array $trace, string $diff) { parent::__construct($message, $code); $this->syntheticFile = $file; $this->syntheticLine = $line; $this->syntheticTrace = $trace; $this->diff = $diff; } public function syntheticFile(): string { return $this->syntheticFile; } public function syntheticLine(): int { return $this->syntheticLine; } public function syntheticTrace(): array { return $this->syntheticTrace; } public function diff(): string { return $this->diff; } } Exception/InvalidCoversTargetException.php 0000644 00000000707 15107326342 0015020 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class InvalidCoversTargetException extends CodeCoverageException { } Reorderable.php 0000644 00000001224 15107326342 0007505 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface Reorderable { public function sortId(): string; /** * @psalm-return list<ExecutionOrderDependency> */ public function provides(): array; /** * @psalm-return list<ExecutionOrderDependency> */ public function requires(): array; } TestStatus/Error.php 0000644 00000001334 15107326342 0010475 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Error extends Known { /** * @psalm-assert-if-true Error $this */ public function isError(): bool { return true; } public function asInt(): int { return 8; } public function asString(): string { return 'error'; } } TestStatus/Deprecation.php 0000644 00000001364 15107326342 0011644 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Deprecation extends Known { /** * @psalm-assert-if-true Deprecation $this */ public function isDeprecation(): bool { return true; } public function asInt(): int { return 4; } public function asString(): string { return 'deprecation'; } } TestStatus/Success.php 0000644 00000001344 15107326342 0011015 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Success extends Known { /** * @psalm-assert-if-true Success $this */ public function isSuccess(): bool { return true; } public function asInt(): int { return 0; } public function asString(): string { return 'success'; } } TestStatus/TestStatus.php 0000644 00000007550 15107326342 0011535 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ abstract class TestStatus { private readonly string $message; public static function from(int $status): self { return match ($status) { 0 => self::success(), 1 => self::skipped(), 2 => self::incomplete(), 3 => self::notice(), 4 => self::deprecation(), 5 => self::risky(), 6 => self::warning(), 7 => self::failure(), 8 => self::error(), default => self::unknown(), }; } public static function unknown(): self { return new Unknown; } public static function success(): self { return new Success; } public static function skipped(string $message = ''): self { return new Skipped($message); } public static function incomplete(string $message = ''): self { return new Incomplete($message); } public static function notice(string $message = ''): self { return new Notice($message); } public static function deprecation(string $message = ''): self { return new Deprecation($message); } public static function failure(string $message = ''): self { return new Failure($message); } public static function error(string $message = ''): self { return new Error($message); } public static function warning(string $message = ''): self { return new Warning($message); } public static function risky(string $message = ''): self { return new Risky($message); } private function __construct(string $message = '') { $this->message = $message; } /** * @psalm-assert-if-true Known $this */ public function isKnown(): bool { return false; } /** * @psalm-assert-if-true Unknown $this */ public function isUnknown(): bool { return false; } /** * @psalm-assert-if-true Success $this */ public function isSuccess(): bool { return false; } /** * @psalm-assert-if-true Skipped $this */ public function isSkipped(): bool { return false; } /** * @psalm-assert-if-true Incomplete $this */ public function isIncomplete(): bool { return false; } /** * @psalm-assert-if-true Notice $this */ public function isNotice(): bool { return false; } /** * @psalm-assert-if-true Deprecation $this */ public function isDeprecation(): bool { return false; } /** * @psalm-assert-if-true Failure $this */ public function isFailure(): bool { return false; } /** * @psalm-assert-if-true Error $this */ public function isError(): bool { return false; } /** * @psalm-assert-if-true Warning $this */ public function isWarning(): bool { return false; } /** * @psalm-assert-if-true Risky $this */ public function isRisky(): bool { return false; } public function message(): string { return $this->message; } public function isMoreImportantThan(self $other): bool { return $this->asInt() > $other->asInt(); } abstract public function asInt(): int; abstract public function asString(): string; } TestStatus/Skipped.php 0000644 00000001344 15107326342 0011004 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Skipped extends Known { /** * @psalm-assert-if-true Skipped $this */ public function isSkipped(): bool { return true; } public function asInt(): int { return 1; } public function asString(): string { return 'skipped'; } } TestStatus/Risky.php 0000644 00000001334 15107326342 0010505 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Risky extends Known { /** * @psalm-assert-if-true Risky $this */ public function isRisky(): bool { return true; } public function asInt(): int { return 5; } public function asString(): string { return 'risky'; } } TestStatus/Notice.php 0000644 00000001340 15107326342 0010622 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Notice extends Known { /** * @psalm-assert-if-true Notice $this */ public function isNotice(): bool { return true; } public function asInt(): int { return 3; } public function asString(): string { return 'notice'; } } TestStatus/Known.php 0000644 00000001130 15107326342 0010472 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ abstract class Known extends TestStatus { /** * @psalm-assert-if-true Known $this */ public function isKnown(): bool { return true; } } TestStatus/Incomplete.php 0000644 00000001360 15107326342 0011502 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Incomplete extends Known { /** * @psalm-assert-if-true Incomplete $this */ public function isIncomplete(): bool { return true; } public function asInt(): int { return 2; } public function asString(): string { return 'incomplete'; } } TestStatus/Failure.php 0000644 00000001344 15107326342 0010774 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Failure extends Known { /** * @psalm-assert-if-true Failure $this */ public function isFailure(): bool { return true; } public function asInt(): int { return 7; } public function asString(): string { return 'failure'; } } TestStatus/Unknown.php 0000644 00000001352 15107326342 0011043 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Unknown extends TestStatus { /** * @psalm-assert-if-true Unknown $this */ public function isUnknown(): bool { return true; } public function asInt(): int { return -1; } public function asString(): string { return 'unknown'; } } TestStatus/Warning.php 0000644 00000001344 15107326342 0011012 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\TestStatus; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @psalm-immutable */ final class Warning extends Known { /** * @psalm-assert-if-true Warning $this */ public function isWarning(): bool { return true; } public function asInt(): int { return 6; } public function asString(): string { return 'warning'; } } TestCase.php 0000644 00000212733 15107326342 0007003 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use const LC_ALL; use const LC_COLLATE; use const LC_CTYPE; use const LC_MONETARY; use const LC_NUMERIC; use const LC_TIME; use const PATHINFO_FILENAME; use const PHP_EOL; use const PHP_URL_PATH; use function array_keys; use function array_merge; use function array_values; use function assert; use function basename; use function chdir; use function class_exists; use function clearstatcache; use function count; use function defined; use function explode; use function getcwd; use function implode; use function in_array; use function ini_set; use function is_array; use function is_callable; use function is_int; use function is_object; use function is_string; use function libxml_clear_errors; use function method_exists; use function ob_end_clean; use function ob_get_clean; use function ob_get_contents; use function ob_get_level; use function ob_start; use function parse_url; use function pathinfo; use function preg_replace; use function setlocale; use function sprintf; use function str_contains; use function trim; use AssertionError; use DeepCopy\DeepCopy; use PHPUnit\Event; use PHPUnit\Event\NoPreviousThrowableException; use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException; use PHPUnit\Event\TestData\NoDataSetFromDataProviderException; use PHPUnit\Framework\Constraint\Exception as ExceptionConstraint; use PHPUnit\Framework\Constraint\ExceptionCode; use PHPUnit\Framework\Constraint\ExceptionMessageIsOrContains; use PHPUnit\Framework\Constraint\ExceptionMessageMatchesRegularExpression; use PHPUnit\Framework\MockObject\Generator\Generator as MockGenerator; use PHPUnit\Framework\MockObject\MockBuilder; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObjectInternal; use PHPUnit\Framework\MockObject\Rule\AnyInvokedCount as AnyInvokedCountMatcher; use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastCount as InvokedAtLeastCountMatcher; use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastOnce as InvokedAtLeastOnceMatcher; use PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount as InvokedAtMostCountMatcher; use PHPUnit\Framework\MockObject\Rule\InvokedCount as InvokedCountMatcher; use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls as ConsecutiveCallsStub; use PHPUnit\Framework\MockObject\Stub\Exception as ExceptionStub; use PHPUnit\Framework\MockObject\Stub\ReturnArgument as ReturnArgumentStub; use PHPUnit\Framework\MockObject\Stub\ReturnCallback as ReturnCallbackStub; use PHPUnit\Framework\MockObject\Stub\ReturnSelf as ReturnSelfStub; use PHPUnit\Framework\MockObject\Stub\ReturnStub; use PHPUnit\Framework\MockObject\Stub\ReturnValueMap as ReturnValueMapStub; use PHPUnit\Framework\TestSize\TestSize; use PHPUnit\Framework\TestStatus\TestStatus; use PHPUnit\Metadata\Api\Groups; use PHPUnit\Metadata\Api\HookMethods; use PHPUnit\Metadata\Api\Requirements; use PHPUnit\Metadata\Parser\Registry as MetadataRegistry; use PHPUnit\TestRunner\TestResult\PassedTests; use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry; use PHPUnit\Util\Cloner; use PHPUnit\Util\Test as TestUtil; use ReflectionClass; use ReflectionException; use ReflectionObject; use SebastianBergmann\CodeCoverage\StaticAnalysisCacheNotConfiguredException; use SebastianBergmann\CodeCoverage\UnintentionallyCoveredCodeException; use SebastianBergmann\Comparator\Comparator; use SebastianBergmann\Comparator\Factory as ComparatorFactory; use SebastianBergmann\Diff\Differ; use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder; use SebastianBergmann\Exporter\Exporter; use SebastianBergmann\GlobalState\ExcludeList as GlobalStateExcludeList; use SebastianBergmann\GlobalState\Restorer; use SebastianBergmann\GlobalState\Snapshot; use SebastianBergmann\Invoker\TimeoutException; use SebastianBergmann\ObjectEnumerator\Enumerator; use SebastianBergmann\RecursionContext\Context; use Throwable; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, Test { private const LOCALE_CATEGORIES = [LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME]; private ?bool $backupGlobals = null; /** * @psalm-var list<string> */ private array $backupGlobalsExcludeList = []; private ?bool $backupStaticProperties = null; /** * @psalm-var array<string,list<class-string>> */ private array $backupStaticPropertiesExcludeList = []; private ?Snapshot $snapshot = null; private ?bool $runClassInSeparateProcess = null; private ?bool $runTestInSeparateProcess = null; private bool $preserveGlobalState = false; private bool $inIsolation = false; private ?string $expectedException = null; private ?string $expectedExceptionMessage = null; private ?string $expectedExceptionMessageRegExp = null; private null|int|string $expectedExceptionCode = null; /** * @psalm-var list<ExecutionOrderDependency> */ private array $providedTests = []; private array $data = []; private int|string $dataName = ''; /** * @psalm-var non-empty-string */ private string $name; /** * @psalm-var list<string> */ private array $groups = []; /** * @psalm-var list<ExecutionOrderDependency> */ private array $dependencies = []; private array $dependencyInput = []; /** * @psalm-var array<string,string> */ private array $iniSettings = []; private array $locale = []; /** * @psalm-var list<MockObjectInternal> */ private array $mockObjects = []; private bool $registerMockObjectsFromTestArgumentsRecursively = false; private TestStatus $status; private int $numberOfAssertionsPerformed = 0; private mixed $testResult = null; private string $output = ''; private ?string $outputExpectedRegex = null; private ?string $outputExpectedString = null; private bool $outputBufferingActive = false; private int $outputBufferingLevel; private bool $outputRetrievedForAssertion = false; private bool $doesNotPerformAssertions = false; /** * @psalm-var list<Comparator> */ private array $customComparators = []; private ?Event\Code\TestMethod $testValueObjectForEvents = null; private bool $wasPrepared = false; /** * @psalm-var array<class-string, true> */ private array $failureTypes = []; /** * Returns a matcher that matches when the method is executed * zero or more times. */ final public static function any(): AnyInvokedCountMatcher { return new AnyInvokedCountMatcher; } /** * Returns a matcher that matches when the method is never executed. */ final public static function never(): InvokedCountMatcher { return new InvokedCountMatcher(0); } /** * Returns a matcher that matches when the method is executed * at least N times. */ final public static function atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher { return new InvokedAtLeastCountMatcher( $requiredInvocations, ); } /** * Returns a matcher that matches when the method is executed at least once. */ final public static function atLeastOnce(): InvokedAtLeastOnceMatcher { return new InvokedAtLeastOnceMatcher; } /** * Returns a matcher that matches when the method is executed exactly once. */ final public static function once(): InvokedCountMatcher { return new InvokedCountMatcher(1); } /** * Returns a matcher that matches when the method is executed * exactly $count times. */ final public static function exactly(int $count): InvokedCountMatcher { return new InvokedCountMatcher($count); } /** * Returns a matcher that matches when the method is executed * at most N times. */ final public static function atMost(int $allowedInvocations): InvokedAtMostCountMatcher { return new InvokedAtMostCountMatcher($allowedInvocations); } /** * @deprecated Use <code>$double->willReturn()</code> instead of <code>$double->will($this->returnValue())</code> * @see https://github.com/sebastianbergmann/phpunit/issues/5423 */ final public static function returnValue(mixed $value): ReturnStub { return new ReturnStub($value); } /** * @deprecated Use <code>$double->willReturnMap()</code> instead of <code>$double->will($this->returnValueMap())</code> * @see https://github.com/sebastianbergmann/phpunit/issues/5423 */ final public static function returnValueMap(array $valueMap): ReturnValueMapStub { return new ReturnValueMapStub($valueMap); } /** * @deprecated Use <code>$double->willReturnArgument()</code> instead of <code>$double->will($this->returnArgument())</code> * @see https://github.com/sebastianbergmann/phpunit/issues/5423 */ final public static function returnArgument(int $argumentIndex): ReturnArgumentStub { return new ReturnArgumentStub($argumentIndex); } /** * @deprecated Use <code>$double->willReturnCallback()</code> instead of <code>$double->will($this->returnCallback())</code> * @see https://github.com/sebastianbergmann/phpunit/issues/5423 */ final public static function returnCallback(callable $callback): ReturnCallbackStub { return new ReturnCallbackStub($callback); } /** * @deprecated Use <code>$double->willReturnSelf()</code> instead of <code>$double->will($this->returnSelf())</code> * @see https://github.com/sebastianbergmann/phpunit/issues/5423 */ final public static function returnSelf(): ReturnSelfStub { return new ReturnSelfStub; } final public static function throwException(Throwable $exception): ExceptionStub { return new ExceptionStub($exception); } /** * @deprecated Use <code>$double->willReturn()</code> instead of <code>$double->will($this->onConsecutiveCalls())</code> * @see https://github.com/sebastianbergmann/phpunit/issues/5423 * @see https://github.com/sebastianbergmann/phpunit/issues/5425 */ final public static function onConsecutiveCalls(mixed ...$arguments): ConsecutiveCallsStub { return new ConsecutiveCallsStub($arguments); } /** * @psalm-param non-empty-string $name * * @internal This method is not covered by the backward compatibility promise for PHPUnit */ public function __construct(string $name) { $this->setName($name); $this->status = TestStatus::unknown(); } /** * This method is called before the first test of this test class is run. */ public static function setUpBeforeClass(): void { } /** * This method is called after the last test of this test class is run. */ public static function tearDownAfterClass(): void { } /** * This method is called before each test. */ protected function setUp(): void { } /** * Performs assertions shared by all tests of a test case. * * This method is called between setUp() and test. */ protected function assertPreConditions(): void { } /** * Performs assertions shared by all tests of a test case. * * This method is called between test and tearDown(). */ protected function assertPostConditions(): void { } /** * This method is called after each test. */ protected function tearDown(): void { } /** * Returns a string representation of the test case. * * @throws Exception * * @internal This method is not covered by the backward compatibility promise for PHPUnit */ public function toString(): string { $buffer = sprintf( '%s::%s', (new ReflectionClass($this))->getName(), $this->name, ); return $buffer . $this->dataSetAsStringWithData(); } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function count(): int { return 1; } final public function getActualOutputForAssertion(): string { $this->outputRetrievedForAssertion = true; return $this->output(); } final public function expectOutputRegex(string $expectedRegex): void { $this->outputExpectedRegex = $expectedRegex; } final public function expectOutputString(string $expectedString): void { $this->outputExpectedString = $expectedString; } /** * @psalm-param class-string<Throwable> $exception */ final public function expectException(string $exception): void { $this->expectedException = $exception; } final public function expectExceptionCode(int|string $code): void { $this->expectedExceptionCode = $code; } final public function expectExceptionMessage(string $message): void { $this->expectedExceptionMessage = $message; } final public function expectExceptionMessageMatches(string $regularExpression): void { $this->expectedExceptionMessageRegExp = $regularExpression; } /** * Sets up an expectation for an exception to be raised by the code under test. * Information for expected exception class, expected exception message, and * expected exception code are retrieved from a given Exception object. */ final public function expectExceptionObject(\Exception $exception): void { $this->expectException($exception::class); $this->expectExceptionMessage($exception->getMessage()); $this->expectExceptionCode($exception->getCode()); } final public function expectNotToPerformAssertions(): void { $this->doesNotPerformAssertions = true; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function status(): TestStatus { return $this->status; } /** * @throws \PHPUnit\Runner\Exception * @throws \PHPUnit\Util\Exception * @throws \SebastianBergmann\CodeCoverage\InvalidArgumentException * @throws \SebastianBergmann\Template\InvalidArgumentException * @throws CodeCoverageException * @throws Exception * @throws MoreThanOneDataSetFromDataProviderException * @throws NoDataSetFromDataProviderException * @throws NoPreviousThrowableException * @throws ProcessIsolationException * @throws StaticAnalysisCacheNotConfiguredException * @throws UnintentionallyCoveredCodeException * * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function run(): void { if (!$this->handleDependencies()) { return; } if (!$this->shouldRunInSeparateProcess()) { (new TestRunner)->run($this); } else { (new TestRunner)->runInSeparateProcess( $this, $this->runClassInSeparateProcess && !$this->runTestInSeparateProcess, $this->preserveGlobalState, ); } } /** * Returns a builder object to create mock objects using a fluent interface. * * @psalm-template RealInstanceType of object * * @psalm-param class-string<RealInstanceType> $className * * @psalm-return MockBuilder<RealInstanceType> */ final public function getMockBuilder(string $className): MockBuilder { return new MockBuilder($this, $className); } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function groups(): array { return $this->groups; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setGroups(array $groups): void { $this->groups = $groups; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function nameWithDataSet(): string { return $this->name . $this->dataSetAsString(); } /** * @psalm-return non-empty-string * * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function name(): string { return $this->name; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function size(): TestSize { return (new Groups)->size( static::class, $this->name, ); } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function hasUnexpectedOutput(): bool { if ($this->output === '') { return false; } if ($this->expectsOutput()) { return false; } return true; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function output(): string { if (!$this->outputBufferingActive) { return $this->output; } return (string) ob_get_contents(); } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function doesNotPerformAssertions(): bool { return $this->doesNotPerformAssertions; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function expectsOutput(): bool { return $this->hasExpectationOnOutput() || $this->outputRetrievedForAssertion; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function registerMockObjectsFromTestArgumentsRecursively(): void { $this->registerMockObjectsFromTestArgumentsRecursively = true; } /** * @throws Throwable * * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function runBare(): void { $emitter = Event\Facade::emitter(); $emitter->testPreparationStarted( $this->valueObjectForEvents(), ); $this->snapshotGlobalState(); $this->startOutputBuffering(); clearstatcache(); $hookMethods = (new HookMethods)->hookMethods(static::class); $hasMetRequirements = false; $this->numberOfAssertionsPerformed = 0; $currentWorkingDirectory = getcwd(); try { $this->checkRequirements(); $hasMetRequirements = true; if ($this->inIsolation) { $this->invokeBeforeClassHookMethods($hookMethods, $emitter); } if (method_exists(static::class, $this->name) && MetadataRegistry::parser()->forClassAndMethod(static::class, $this->name)->isDoesNotPerformAssertions()->isNotEmpty()) { $this->doesNotPerformAssertions = true; } $this->invokeBeforeTestHookMethods($hookMethods, $emitter); $this->invokePreConditionHookMethods($hookMethods, $emitter); $emitter->testPrepared( $this->valueObjectForEvents(), ); $this->wasPrepared = true; $this->testResult = $this->runTest(); $this->verifyMockObjects(); $this->invokePostConditionHookMethods($hookMethods, $emitter); $this->status = TestStatus::success(); } catch (IncompleteTest $e) { $this->status = TestStatus::incomplete($e->getMessage()); $emitter->testMarkedAsIncomplete( $this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($e), ); } catch (SkippedTest $e) { $this->status = TestStatus::skipped($e->getMessage()); $emitter->testSkipped( $this->valueObjectForEvents(), $e->getMessage(), ); } catch (AssertionError|AssertionFailedError $e) { if (!$this->wasPrepared) { $this->wasPrepared = true; $emitter->testPreparationFailed( $this->valueObjectForEvents(), ); } $this->status = TestStatus::failure($e->getMessage()); $emitter->testFailed( $this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($e), Event\Code\ComparisonFailureBuilder::from($e), ); } catch (TimeoutException $e) { $this->status = TestStatus::risky($e->getMessage()); } catch (Throwable $_e) { if ($this->isRegisteredFailure($_e)) { $this->status = TestStatus::failure($_e->getMessage()); $emitter->testFailed( $this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($_e), null, ); } else { $e = $this->transformException($_e); $this->status = TestStatus::error($e->getMessage()); $emitter->testErrored( $this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($e), ); } } $outputBufferingStopped = false; if (!isset($e) && $this->hasExpectationOnOutput() && $this->stopOutputBuffering()) { $outputBufferingStopped = true; $this->performAssertionsOnOutput(); } if ($this->status->isSuccess()) { Event\Facade::emitter()->testPassed( $this->valueObjectForEvents(), ); if (!$this->usesDataProvider()) { PassedTests::instance()->testMethodPassed( $this->valueObjectForEvents(), $this->testResult, ); } } $this->mockObjects = []; // Tear down the fixture. An exception raised in tearDown() will be // caught and passed on when no exception was raised before. try { if ($hasMetRequirements) { $this->invokeAfterTestHookMethods($hookMethods, $emitter); if ($this->inIsolation) { $this->invokeAfterClassHookMethods($hookMethods, $emitter); } } } catch (AssertionError|AssertionFailedError $e) { $this->status = TestStatus::failure($e->getMessage()); $emitter->testFailed( $this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($e), Event\Code\ComparisonFailureBuilder::from($e), ); } catch (Throwable $exceptionRaisedDuringTearDown) { if (!isset($e)) { $this->status = TestStatus::error($exceptionRaisedDuringTearDown->getMessage()); $e = $exceptionRaisedDuringTearDown; $emitter->testErrored( $this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($exceptionRaisedDuringTearDown), ); } } if (!$outputBufferingStopped) { $this->stopOutputBuffering(); } clearstatcache(); if ($currentWorkingDirectory !== getcwd()) { chdir($currentWorkingDirectory); } $this->restoreGlobalState(); $this->unregisterCustomComparators(); $this->cleanupIniSettings(); $this->cleanupLocaleSettings(); libxml_clear_errors(); $this->testValueObjectForEvents = null; if (isset($e)) { $this->onNotSuccessfulTest($e); } } /** * @psalm-param non-empty-string $name * * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setName(string $name): void { $this->name = $name; if (is_callable($this->sortId(), true)) { $this->providedTests = [new ExecutionOrderDependency($this->sortId())]; } } /** * @psalm-param list<ExecutionOrderDependency> $dependencies * * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setDependencies(array $dependencies): void { $this->dependencies = $dependencies; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setDependencyInput(array $dependencyInput): void { $this->dependencyInput = $dependencyInput; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function dependencyInput(): array { return $this->dependencyInput; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function hasDependencyInput(): bool { return !empty($this->dependencyInput); } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setBackupGlobals(bool $backupGlobals): void { $this->backupGlobals = $backupGlobals; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setBackupGlobalsExcludeList(array $backupGlobalsExcludeList): void { $this->backupGlobalsExcludeList = $backupGlobalsExcludeList; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setBackupStaticProperties(bool $backupStaticProperties): void { $this->backupStaticProperties = $backupStaticProperties; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setBackupStaticPropertiesExcludeList(array $backupStaticPropertiesExcludeList): void { $this->backupStaticPropertiesExcludeList = $backupStaticPropertiesExcludeList; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setRunTestInSeparateProcess(bool $runTestInSeparateProcess): void { if ($this->runTestInSeparateProcess === null) { $this->runTestInSeparateProcess = $runTestInSeparateProcess; } } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setRunClassInSeparateProcess(bool $runClassInSeparateProcess): void { $this->runClassInSeparateProcess = $runClassInSeparateProcess; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setPreserveGlobalState(bool $preserveGlobalState): void { $this->preserveGlobalState = $preserveGlobalState; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setInIsolation(bool $inIsolation): void { $this->inIsolation = $inIsolation; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function isInIsolation(): bool { return $this->inIsolation; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function result(): mixed { return $this->testResult; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setResult(mixed $result): void { $this->testResult = $result; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function registerMockObject(MockObject $mockObject): void { assert($mockObject instanceof MockObjectInternal); $this->mockObjects[] = $mockObject; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function addToAssertionCount(int $count): void { $this->numberOfAssertionsPerformed += $count; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function numberOfAssertionsPerformed(): int { return $this->numberOfAssertionsPerformed; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function usesDataProvider(): bool { return !empty($this->data); } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function dataName(): int|string { return $this->dataName; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function dataSetAsString(): string { $buffer = ''; if (!empty($this->data)) { if (is_int($this->dataName)) { $buffer .= sprintf(' with data set #%d', $this->dataName); } else { $buffer .= sprintf(' with data set "%s"', $this->dataName); } } return $buffer; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function dataSetAsStringWithData(): string { if (empty($this->data)) { return ''; } return $this->dataSetAsString() . sprintf( ' (%s)', (new Exporter)->shortenedRecursiveExport($this->data), ); } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function providedData(): array { return $this->data; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function sortId(): string { $id = $this->name; if (!str_contains($id, '::')) { $id = static::class . '::' . $id; } if ($this->usesDataProvider()) { $id .= $this->dataSetAsString(); } return $id; } /** * @psalm-return list<ExecutionOrderDependency> * * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function provides(): array { return $this->providedTests; } /** * @psalm-return list<ExecutionOrderDependency> * * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function requires(): array { return $this->dependencies; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function setData(int|string $dataName, array $data): void { $this->dataName = $dataName; $this->data = $data; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit * * @throws MoreThanOneDataSetFromDataProviderException */ final public function valueObjectForEvents(): Event\Code\TestMethod { if ($this->testValueObjectForEvents !== null) { return $this->testValueObjectForEvents; } $this->testValueObjectForEvents = Event\Code\TestMethodBuilder::fromTestCase($this); return $this->testValueObjectForEvents; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ final public function wasPrepared(): bool { return $this->wasPrepared; } final protected function registerComparator(Comparator $comparator): void { ComparatorFactory::getInstance()->register($comparator); Event\Facade::emitter()->testRegisteredComparator($comparator::class); $this->customComparators[] = $comparator; } /** * @psalm-param class-string $classOrInterface */ final protected function registerFailureType(string $classOrInterface): void { $this->failureTypes[$classOrInterface] = true; } /** * @throws AssertionFailedError * @throws Exception * @throws ExpectationFailedException * @throws Throwable * * @internal This method is not covered by the backward compatibility promise for PHPUnit */ protected function runTest(): mixed { $testArguments = array_merge($this->data, $this->dependencyInput); $this->registerMockObjectsFromTestArguments($testArguments); try { $testResult = $this->{$this->name}(...array_values($testArguments)); } catch (Throwable $exception) { if (!$this->shouldExceptionExpectationsBeVerified($exception)) { throw $exception; } $this->verifyExceptionExpectations($exception); return null; } $this->expectedExceptionWasNotRaised(); return $testResult; } /** * This method is a wrapper for the ini_set() function that automatically * resets the modified php.ini setting to its original value after the * test is run. * * @throws Exception * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5214 */ protected function iniSet(string $varName, string $newValue): void { $currentValue = ini_set($varName, $newValue); if ($currentValue !== false) { $this->iniSettings[$varName] = $currentValue; } else { throw new Exception( sprintf( 'INI setting "%s" could not be set to "%s".', $varName, $newValue, ), ); } } /** * This method is a wrapper for the setlocale() function that automatically * resets the locale to its original value after the test is run. * * @throws Exception * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5216 */ protected function setLocale(mixed ...$arguments): void { if (count($arguments) < 2) { throw new Exception; } [$category, $locale] = $arguments; if (!in_array($category, self::LOCALE_CATEGORIES, true)) { throw new Exception; } if (!is_array($locale) && !is_string($locale)) { throw new Exception; } $this->locale[$category] = setlocale($category, 0); $result = setlocale(...$arguments); if ($result === false) { throw new Exception( 'The locale functionality is not implemented on your platform, ' . 'the specified locale does not exist or the category name is ' . 'invalid.', ); } } /** * Creates a mock object for the specified interface or class. * * @psalm-template RealInstanceType of object * * @psalm-param class-string<RealInstanceType> $originalClassName * * @psalm-return MockObject&RealInstanceType * * @throws \PHPUnit\Framework\MockObject\Exception * @throws InvalidArgumentException * @throws NoPreviousThrowableException */ protected function createMock(string $originalClassName): MockObject { $mock = (new MockGenerator)->testDouble( $originalClassName, true, callOriginalConstructor: false, callOriginalClone: false, cloneArguments: false, allowMockingUnknownTypes: false, ); assert($mock instanceof $originalClassName); assert($mock instanceof MockObject); $this->registerMockObject($mock); Event\Facade::emitter()->testCreatedMockObject($originalClassName); return $mock; } /** * @psalm-param list<class-string> $interfaces * * @throws \PHPUnit\Framework\MockObject\Exception */ protected function createMockForIntersectionOfInterfaces(array $interfaces): MockObject { $mock = (new MockGenerator)->testDoubleForInterfaceIntersection($interfaces, true); Event\Facade::emitter()->testCreatedMockObjectForIntersectionOfInterfaces($interfaces); assert($mock instanceof MockObject); return $mock; } /** * Creates (and configures) a mock object for the specified interface or class. * * @psalm-template RealInstanceType of object * * @psalm-param class-string<RealInstanceType> $originalClassName * * @psalm-return MockObject&RealInstanceType * * @throws \PHPUnit\Framework\MockObject\Exception * @throws InvalidArgumentException * @throws NoPreviousThrowableException */ protected function createConfiguredMock(string $originalClassName, array $configuration): MockObject { $o = $this->createMock($originalClassName); foreach ($configuration as $method => $return) { $o->method($method)->willReturn($return); } return $o; } /** * Creates a partial mock object for the specified interface or class. * * @psalm-param list<non-empty-string> $methods * * @psalm-template RealInstanceType of object * * @psalm-param class-string<RealInstanceType> $originalClassName * * @psalm-return MockObject&RealInstanceType * * @throws \PHPUnit\Framework\MockObject\Exception * @throws InvalidArgumentException */ protected function createPartialMock(string $originalClassName, array $methods): MockObject { $partialMock = $this->getMockBuilder($originalClassName) ->disableOriginalConstructor() ->disableOriginalClone() ->disableArgumentCloning() ->disallowMockingUnknownTypes() ->onlyMethods($methods) ->getMock(); Event\Facade::emitter()->testCreatedPartialMockObject( $originalClassName, ...$methods, ); return $partialMock; } /** * Creates a test proxy for the specified class. * * @psalm-template RealInstanceType of object * * @psalm-param class-string<RealInstanceType> $originalClassName * * @psalm-return MockObject&RealInstanceType * * @throws \PHPUnit\Framework\MockObject\Exception * @throws InvalidArgumentException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5240 */ protected function createTestProxy(string $originalClassName, array $constructorArguments = []): MockObject { $testProxy = $this->getMockBuilder($originalClassName) ->setConstructorArgs($constructorArguments) ->enableProxyingToOriginalMethods() ->getMock(); Event\Facade::emitter()->testCreatedTestProxy( $originalClassName, $constructorArguments, ); return $testProxy; } /** * Creates a mock object for the specified abstract class with all abstract * methods of the class mocked. Concrete methods are not mocked by default. * To mock concrete methods, use the 7th parameter ($mockedMethods). * * @psalm-template RealInstanceType of object * * @psalm-param class-string<RealInstanceType> $originalClassName * * @psalm-return MockObject&RealInstanceType * * @throws \PHPUnit\Framework\MockObject\Exception * @throws InvalidArgumentException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5241 */ protected function getMockForAbstractClass(string $originalClassName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject { $mockObject = (new MockGenerator)->mockObjectForAbstractClass( $originalClassName, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $mockedMethods, $cloneArguments, ); $this->registerMockObject($mockObject); Event\Facade::emitter()->testCreatedMockObjectForAbstractClass($originalClassName); assert($mockObject instanceof $originalClassName); assert($mockObject instanceof MockObject); return $mockObject; } /** * Creates a mock object based on the given WSDL file. * * @throws \PHPUnit\Framework\MockObject\Exception * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5242 */ protected function getMockFromWsdl(string $wsdlFile, string $originalClassName = '', string $mockClassName = '', array $methods = [], bool $callOriginalConstructor = true, array $options = []): MockObject { if ($originalClassName === '') { $fileName = pathinfo(basename(parse_url($wsdlFile, PHP_URL_PATH)), PATHINFO_FILENAME); $originalClassName = preg_replace('/\W/', '', $fileName); } if (!class_exists($originalClassName)) { eval( (new MockGenerator)->generateClassFromWsdl( $wsdlFile, $originalClassName, $methods, $options, ) ); } $mockObject = (new MockGenerator)->testDouble( $originalClassName, true, $methods, ['', $options], $mockClassName, $callOriginalConstructor, false, false, ); Event\Facade::emitter()->testCreatedMockObjectFromWsdl( $wsdlFile, $originalClassName, $mockClassName, $methods, $callOriginalConstructor, $options, ); assert($mockObject instanceof MockObject); $this->registerMockObject($mockObject); return $mockObject; } /** * Creates a mock object for the specified trait with all abstract methods * of the trait mocked. Concrete methods to mock can be specified with the * `$mockedMethods` parameter. * * @psalm-param trait-string $traitName * * @throws \PHPUnit\Framework\MockObject\Exception * @throws InvalidArgumentException * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5243 */ protected function getMockForTrait(string $traitName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject { $mockObject = (new MockGenerator)->mockObjectForTrait( $traitName, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $mockedMethods, $cloneArguments, ); $this->registerMockObject($mockObject); Event\Facade::emitter()->testCreatedMockObjectForTrait($traitName); return $mockObject; } /** * Creates an object that uses the specified trait. * * @psalm-param trait-string $traitName * * @throws \PHPUnit\Framework\MockObject\Exception * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5244 */ protected function getObjectForTrait(string $traitName, array $arguments = [], string $traitClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true): object { return (new MockGenerator)->objectForTrait( $traitName, $traitClassName, $callAutoload, $callOriginalConstructor, $arguments, ); } protected function transformException(Throwable $t): Throwable { return $t; } /** * This method is called when a test method did not execute successfully. * * @throws Throwable */ protected function onNotSuccessfulTest(Throwable $t): never { throw $t; } /** * @throws Throwable */ private function verifyMockObjects(): void { foreach ($this->mockObjects as $mockObject) { if ($mockObject->__phpunit_hasMatchers()) { $this->numberOfAssertionsPerformed++; } $mockObject->__phpunit_verify( $this->shouldInvocationMockerBeReset($mockObject), ); } } /** * @throws SkippedTest */ private function checkRequirements(): void { if (!$this->name || !method_exists($this, $this->name)) { return; } $missingRequirements = (new Requirements)->requirementsNotSatisfiedFor( static::class, $this->name, ); if (!empty($missingRequirements)) { $this->markTestSkipped(implode(PHP_EOL, $missingRequirements)); } } private function handleDependencies(): bool { if ([] === $this->dependencies || $this->inIsolation) { return true; } $passedTests = PassedTests::instance(); foreach ($this->dependencies as $dependency) { if (!$dependency->isValid()) { $this->markErrorForInvalidDependency(); return false; } if ($dependency->targetIsClass()) { $dependencyClassName = $dependency->getTargetClassName(); if (!class_exists($dependencyClassName)) { $this->markErrorForInvalidDependency($dependency); return false; } if (!$passedTests->hasTestClassPassed($dependencyClassName)) { $this->markSkippedForMissingDependency($dependency); return false; } continue; } $dependencyTarget = $dependency->getTarget(); if (!$passedTests->hasTestMethodPassed($dependencyTarget)) { if (!$this->isCallableTestMethod($dependencyTarget)) { $this->markErrorForInvalidDependency($dependency); } else { $this->markSkippedForMissingDependency($dependency); } return false; } if ($passedTests->isGreaterThan($dependencyTarget, $this->size())) { Event\Facade::emitter()->testConsideredRisky( $this->valueObjectForEvents(), 'This test depends on a test that is larger than itself', ); return false; } $returnValue = $passedTests->returnValue($dependencyTarget); if ($dependency->deepClone()) { $deepCopy = new DeepCopy; $deepCopy->skipUncloneable(false); $this->dependencyInput[$dependencyTarget] = $deepCopy->copy($returnValue); } elseif ($dependency->shallowClone()) { $this->dependencyInput[$dependencyTarget] = clone $returnValue; } else { $this->dependencyInput[$dependencyTarget] = $returnValue; } } $this->testValueObjectForEvents = null; return true; } /** * @throws Exception * @throws MoreThanOneDataSetFromDataProviderException * @throws NoPreviousThrowableException */ private function markErrorForInvalidDependency(?ExecutionOrderDependency $dependency = null): void { $message = 'This test has an invalid dependency'; if ($dependency !== null) { $message = sprintf( 'This test depends on "%s" which does not exist', $dependency->targetIsClass() ? $dependency->getTargetClassName() : $dependency->getTarget(), ); } $exception = new InvalidDependencyException($message); Event\Facade::emitter()->testErrored( $this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($exception), ); $this->status = TestStatus::error($message); } /** * @throws MoreThanOneDataSetFromDataProviderException */ private function markSkippedForMissingDependency(ExecutionOrderDependency $dependency): void { $message = sprintf( 'This test depends on "%s" to pass', $dependency->getTarget(), ); Event\Facade::emitter()->testSkipped( $this->valueObjectForEvents(), $message, ); $this->status = TestStatus::skipped($message); } private function startOutputBuffering(): void { ob_start(); $this->outputBufferingActive = true; $this->outputBufferingLevel = ob_get_level(); } /** * @throws MoreThanOneDataSetFromDataProviderException */ private function stopOutputBuffering(): bool { $bufferingLevel = ob_get_level(); if ($bufferingLevel !== $this->outputBufferingLevel) { if ($bufferingLevel > $this->outputBufferingLevel) { $message = 'Test code or tested code did not close its own output buffers'; } else { $message = 'Test code or tested code closed output buffers other than its own'; } while (ob_get_level() >= $this->outputBufferingLevel) { ob_end_clean(); } Event\Facade::emitter()->testConsideredRisky( $this->valueObjectForEvents(), $message, ); $this->status = TestStatus::risky($message); return false; } $this->output = ob_get_clean(); $this->outputBufferingActive = false; $this->outputBufferingLevel = ob_get_level(); return true; } private function snapshotGlobalState(): void { if ($this->runTestInSeparateProcess || $this->inIsolation || (!$this->backupGlobals && !$this->backupStaticProperties)) { return; } $snapshot = $this->createGlobalStateSnapshot($this->backupGlobals === true); $this->snapshot = $snapshot; } /** * @throws MoreThanOneDataSetFromDataProviderException */ private function restoreGlobalState(): void { if (!$this->snapshot instanceof Snapshot) { return; } if (ConfigurationRegistry::get()->beStrictAboutChangesToGlobalState()) { $this->compareGlobalStateSnapshots( $this->snapshot, $this->createGlobalStateSnapshot($this->backupGlobals === true), ); } $restorer = new Restorer; if ($this->backupGlobals) { $restorer->restoreGlobalVariables($this->snapshot); } if ($this->backupStaticProperties) { $restorer->restoreStaticProperties($this->snapshot); } $this->snapshot = null; } private function createGlobalStateSnapshot(bool $backupGlobals): Snapshot { $excludeList = new GlobalStateExcludeList; foreach ($this->backupGlobalsExcludeList as $globalVariable) { $excludeList->addGlobalVariable($globalVariable); } if (!defined('PHPUNIT_TESTSUITE')) { $excludeList->addClassNamePrefix('PHPUnit'); $excludeList->addClassNamePrefix('SebastianBergmann\CodeCoverage'); $excludeList->addClassNamePrefix('SebastianBergmann\FileIterator'); $excludeList->addClassNamePrefix('SebastianBergmann\Invoker'); $excludeList->addClassNamePrefix('SebastianBergmann\Template'); $excludeList->addClassNamePrefix('SebastianBergmann\Timer'); $excludeList->addStaticProperty(ComparatorFactory::class, 'instance'); foreach ($this->backupStaticPropertiesExcludeList as $class => $properties) { foreach ($properties as $property) { $excludeList->addStaticProperty($class, $property); } } } return new Snapshot( $excludeList, $backupGlobals, (bool) $this->backupStaticProperties, false, false, false, false, false, false, false, ); } /** * @throws MoreThanOneDataSetFromDataProviderException */ private function compareGlobalStateSnapshots(Snapshot $before, Snapshot $after): void { $backupGlobals = $this->backupGlobals === null || $this->backupGlobals; if ($backupGlobals) { $this->compareGlobalStateSnapshotPart( $before->globalVariables(), $after->globalVariables(), "--- Global variables before the test\n+++ Global variables after the test\n", ); $this->compareGlobalStateSnapshotPart( $before->superGlobalVariables(), $after->superGlobalVariables(), "--- Super-global variables before the test\n+++ Super-global variables after the test\n", ); } if ($this->backupStaticProperties) { $this->compareGlobalStateSnapshotPart( $before->staticProperties(), $after->staticProperties(), "--- Static properties before the test\n+++ Static properties after the test\n", ); } } /** * @throws MoreThanOneDataSetFromDataProviderException */ private function compareGlobalStateSnapshotPart(array $before, array $after, string $header): void { if ($before != $after) { $differ = new Differ(new UnifiedDiffOutputBuilder($header)); $exporter = new Exporter; Event\Facade::emitter()->testConsideredRisky( $this->valueObjectForEvents(), 'This test modified global state but was not expected to do so' . PHP_EOL . trim( $differ->diff( $exporter->export($before), $exporter->export($after), ), ), ); } } private function shouldInvocationMockerBeReset(MockObject $mock): bool { $enumerator = new Enumerator; if (in_array($mock, $enumerator->enumerate($this->dependencyInput), true)) { return false; } if (!is_array($this->testResult) && !is_object($this->testResult)) { return true; } return !in_array($mock, $enumerator->enumerate($this->testResult), true); } private function registerMockObjectsFromTestArguments(array $testArguments, Context $context = new Context): void { if ($this->registerMockObjectsFromTestArgumentsRecursively) { foreach ((new Enumerator)->enumerate($testArguments) as $object) { if ($object instanceof MockObject) { $this->registerMockObject($object); } } } else { foreach ($testArguments as $testArgument) { if ($testArgument instanceof MockObject) { $testArgument = Cloner::clone($testArgument); $this->registerMockObject($testArgument); } elseif (is_array($testArgument) && !$context->contains($testArgument)) { $context->add($testArgument); $this->registerMockObjectsFromTestArguments( $testArgument, $context, ); } } } } private function unregisterCustomComparators(): void { $factory = ComparatorFactory::getInstance(); foreach ($this->customComparators as $comparator) { $factory->unregister($comparator); } $this->customComparators = []; } private function cleanupIniSettings(): void { foreach ($this->iniSettings as $varName => $oldValue) { ini_set($varName, $oldValue); } $this->iniSettings = []; } private function cleanupLocaleSettings(): void { foreach ($this->locale as $category => $locale) { setlocale($category, $locale); } $this->locale = []; } /** * @throws Exception */ private function shouldExceptionExpectationsBeVerified(Throwable $throwable): bool { $result = false; if ($this->expectedException !== null || $this->expectedExceptionCode !== null || $this->expectedExceptionMessage !== null || $this->expectedExceptionMessageRegExp !== null) { $result = true; } if ($throwable instanceof Exception) { $result = false; } if (is_string($this->expectedException)) { try { $reflector = new ReflectionClass($this->expectedException); // @codeCoverageIgnoreStart } catch (ReflectionException $e) { throw new Exception( $e->getMessage(), $e->getCode(), $e, ); } // @codeCoverageIgnoreEnd if ($this->expectedException === 'PHPUnit\Framework\Exception' || $this->expectedException === '\PHPUnit\Framework\Exception' || $reflector->isSubclassOf(Exception::class)) { $result = true; } } return $result; } private function shouldRunInSeparateProcess(): bool { if ($this->inIsolation) { return false; } if ($this->runTestInSeparateProcess) { return true; } if ($this->runClassInSeparateProcess) { return true; } return ConfigurationRegistry::get()->processIsolation(); } private function isCallableTestMethod(string $dependency): bool { [$className, $methodName] = explode('::', $dependency); if (!class_exists($className)) { return false; } $class = new ReflectionClass($className); if (!$class->isSubclassOf(__CLASS__)) { return false; } if (!$class->hasMethod($methodName)) { return false; } return TestUtil::isTestMethod( $class->getMethod($methodName), ); } /** * @throws Exception * @throws ExpectationFailedException * @throws MoreThanOneDataSetFromDataProviderException * @throws NoPreviousThrowableException */ private function performAssertionsOnOutput(): void { try { if ($this->outputExpectedRegex !== null) { $this->assertMatchesRegularExpression($this->outputExpectedRegex, $this->output); } elseif ($this->outputExpectedString !== null) { $this->assertSame($this->outputExpectedString, $this->output); } } catch (ExpectationFailedException $e) { $this->status = TestStatus::failure($e->getMessage()); Event\Facade::emitter()->testFailed( $this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($e), Event\Code\ComparisonFailureBuilder::from($e), ); throw $e; } } /** * @throws Throwable */ private function invokeBeforeClassHookMethods(array $hookMethods, Event\Emitter $emitter): void { $this->invokeHookMethods( $hookMethods['beforeClass'], $emitter, 'testBeforeFirstTestMethodCalled', 'testBeforeFirstTestMethodFinished', ); } /** * @throws Throwable */ private function invokeBeforeTestHookMethods(array $hookMethods, Event\Emitter $emitter): void { $this->invokeHookMethods( $hookMethods['before'], $emitter, 'testBeforeTestMethodCalled', 'testBeforeTestMethodFinished', ); } /** * @throws Throwable */ private function invokePreConditionHookMethods(array $hookMethods, Event\Emitter $emitter): void { $this->invokeHookMethods( $hookMethods['preCondition'], $emitter, 'testPreConditionCalled', 'testPreConditionFinished', ); } /** * @throws Throwable */ private function invokePostConditionHookMethods(array $hookMethods, Event\Emitter $emitter): void { $this->invokeHookMethods( $hookMethods['postCondition'], $emitter, 'testPostConditionCalled', 'testPostConditionFinished', ); } /** * @throws Throwable */ private function invokeAfterTestHookMethods(array $hookMethods, Event\Emitter $emitter): void { $this->invokeHookMethods( $hookMethods['after'], $emitter, 'testAfterTestMethodCalled', 'testAfterTestMethodFinished', ); } /** * @throws Throwable */ private function invokeAfterClassHookMethods(array $hookMethods, Event\Emitter $emitter): void { $this->invokeHookMethods( $hookMethods['afterClass'], $emitter, 'testAfterLastTestMethodCalled', 'testAfterLastTestMethodFinished', ); } /** * @psalm-param list<non-empty-string> $hookMethods * @psalm-param 'testBeforeFirstTestMethodCalled'|'testBeforeTestMethodCalled'|'testPreConditionCalled'|'testPostConditionCalled'|'testAfterTestMethodCalled'|'testAfterLastTestMethodCalled' $calledMethod * @psalm-param 'testBeforeFirstTestMethodFinished'|'testBeforeTestMethodFinished'|'testPreConditionFinished'|'testPostConditionFinished'|'testAfterTestMethodFinished'|'testAfterLastTestMethodFinished' $finishedMethod * * @throws Throwable */ private function invokeHookMethods(array $hookMethods, Event\Emitter $emitter, string $calledMethod, string $finishedMethod): void { $methodsInvoked = []; foreach ($hookMethods as $methodName) { if ($this->methodDoesNotExistOrIsDeclaredInTestCase($methodName)) { continue; } try { $this->{$methodName}(); } catch (Throwable $t) { } $methodInvoked = new Event\Code\ClassMethod( static::class, $methodName, ); $emitter->{$calledMethod}( static::class, $methodInvoked ); $methodsInvoked[] = $methodInvoked; if (isset($t)) { break; } } if (!empty($methodsInvoked)) { $emitter->{$finishedMethod}( static::class, ...$methodsInvoked ); } if (isset($t)) { throw $t; } } private function methodDoesNotExistOrIsDeclaredInTestCase(string $methodName): bool { $reflector = new ReflectionObject($this); return !$reflector->hasMethod($methodName) || $reflector->getMethod($methodName)->getDeclaringClass()->getName() === self::class; } /** * @throws ExpectationFailedException */ private function verifyExceptionExpectations(\Exception|Throwable $exception): void { if ($this->expectedException !== null) { $this->assertThat( $exception, new ExceptionConstraint( $this->expectedException, ), ); } if ($this->expectedExceptionMessage !== null) { $this->assertThat( $exception->getMessage(), new ExceptionMessageIsOrContains( $this->expectedExceptionMessage, ), ); } if ($this->expectedExceptionMessageRegExp !== null) { $this->assertThat( $exception->getMessage(), new ExceptionMessageMatchesRegularExpression( $this->expectedExceptionMessageRegExp, ), ); } if ($this->expectedExceptionCode !== null) { $this->assertThat( $exception->getCode(), new ExceptionCode( $this->expectedExceptionCode, ), ); } } /** * @throws AssertionFailedError */ private function expectedExceptionWasNotRaised(): void { if ($this->expectedException !== null) { $this->assertThat( null, new ExceptionConstraint($this->expectedException), ); } elseif ($this->expectedExceptionMessage !== null) { $this->numberOfAssertionsPerformed++; throw new AssertionFailedError( sprintf( 'Failed asserting that exception with message "%s" is thrown', $this->expectedExceptionMessage, ), ); } elseif ($this->expectedExceptionMessageRegExp !== null) { $this->numberOfAssertionsPerformed++; throw new AssertionFailedError( sprintf( 'Failed asserting that exception with message matching "%s" is thrown', $this->expectedExceptionMessageRegExp, ), ); } elseif ($this->expectedExceptionCode !== null) { $this->numberOfAssertionsPerformed++; throw new AssertionFailedError( sprintf( 'Failed asserting that exception with code "%s" is thrown', $this->expectedExceptionCode, ), ); } } private function isRegisteredFailure(Throwable $t): bool { foreach (array_keys($this->failureTypes) as $failureType) { if ($t instanceof $failureType) { return true; } } return false; } /** * @internal This method is not covered by the backward compatibility promise for PHPUnit */ private function hasExpectationOnOutput(): bool { return is_string($this->outputExpectedString) || is_string($this->outputExpectedRegex); } /** * Creates a test stub for the specified interface or class. * * @psalm-template RealInstanceType of object * * @psalm-param class-string<RealInstanceType> $originalClassName * * @psalm-return Stub&RealInstanceType * * @throws \PHPUnit\Framework\MockObject\Exception * @throws InvalidArgumentException * @throws NoPreviousThrowableException */ protected static function createStub(string $originalClassName): Stub { $stub = (new MockGenerator)->testDouble( $originalClassName, true, callOriginalConstructor: false, callOriginalClone: false, cloneArguments: false, allowMockingUnknownTypes: false, ); Event\Facade::emitter()->testCreatedStub($originalClassName); assert($stub instanceof $originalClassName); assert($stub instanceof Stub); return $stub; } /** * @psalm-param list<class-string> $interfaces * * @throws \PHPUnit\Framework\MockObject\Exception */ protected static function createStubForIntersectionOfInterfaces(array $interfaces): Stub { $stub = (new MockGenerator)->testDoubleForInterfaceIntersection($interfaces, false); Event\Facade::emitter()->testCreatedStubForIntersectionOfInterfaces($interfaces); return $stub; } /** * Creates (and configures) a test stub for the specified interface or class. * * @psalm-template RealInstanceType of object * * @psalm-param class-string<RealInstanceType> $originalClassName * * @psalm-return Stub&RealInstanceType * * @throws \PHPUnit\Framework\MockObject\Exception * @throws InvalidArgumentException * @throws NoPreviousThrowableException */ final protected static function createConfiguredStub(string $originalClassName, array $configuration): Stub { $o = self::createStub($originalClassName); foreach ($configuration as $method => $return) { $o->method($method)->willReturn($return); } return $o; } } DataProviderTestSuite.php 0000644 00000003635 15107326342 0011525 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function explode; use PHPUnit\Framework\TestSize\TestSize; use PHPUnit\Metadata\Api\Groups; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class DataProviderTestSuite extends TestSuite { /** * @psalm-var list<ExecutionOrderDependency> */ private array $dependencies = []; private ?array $providedTests = null; /** * @psalm-param list<ExecutionOrderDependency> $dependencies */ public function setDependencies(array $dependencies): void { $this->dependencies = $dependencies; foreach ($this->tests() as $test) { if (!$test instanceof TestCase) { continue; } $test->setDependencies($dependencies); } } /** * @psalm-return list<ExecutionOrderDependency> */ public function provides(): array { if ($this->providedTests === null) { $this->providedTests = [new ExecutionOrderDependency($this->name())]; } return $this->providedTests; } /** * @psalm-return list<ExecutionOrderDependency> */ public function requires(): array { // A DataProviderTestSuite does not have to traverse its child tests // as these are inherited and cannot reference dataProvider rows directly return $this->dependencies; } /** * Returns the size of each test created using the data provider(s). */ public function size(): TestSize { [$className, $methodName] = explode('::', $this->name()); return (new Groups)->size($className, $methodName); } } Test.php 0000644 00000000742 15107326342 0006202 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use Countable; /** * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ interface Test extends Countable { public function run(): void; } Assert/Functions.php 0000644 00000247554 15107326342 0010512 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function func_get_args; use function function_exists; use ArrayAccess; use Countable; use PHPUnit\Framework\Constraint\ArrayHasKey; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\Count; use PHPUnit\Framework\Constraint\DirectoryExists; use PHPUnit\Framework\Constraint\FileExists; use PHPUnit\Framework\Constraint\GreaterThan; use PHPUnit\Framework\Constraint\IsAnything; use PHPUnit\Framework\Constraint\IsEmpty; use PHPUnit\Framework\Constraint\IsEqual; use PHPUnit\Framework\Constraint\IsEqualCanonicalizing; use PHPUnit\Framework\Constraint\IsEqualIgnoringCase; use PHPUnit\Framework\Constraint\IsEqualWithDelta; use PHPUnit\Framework\Constraint\IsFalse; use PHPUnit\Framework\Constraint\IsFinite; use PHPUnit\Framework\Constraint\IsIdentical; use PHPUnit\Framework\Constraint\IsInfinite; use PHPUnit\Framework\Constraint\IsInstanceOf; use PHPUnit\Framework\Constraint\IsJson; use PHPUnit\Framework\Constraint\IsList; use PHPUnit\Framework\Constraint\IsNan; use PHPUnit\Framework\Constraint\IsNull; use PHPUnit\Framework\Constraint\IsReadable; use PHPUnit\Framework\Constraint\IsTrue; use PHPUnit\Framework\Constraint\IsType; use PHPUnit\Framework\Constraint\IsWritable; use PHPUnit\Framework\Constraint\LessThan; use PHPUnit\Framework\Constraint\LogicalAnd; use PHPUnit\Framework\Constraint\LogicalNot; use PHPUnit\Framework\Constraint\LogicalOr; use PHPUnit\Framework\Constraint\LogicalXor; use PHPUnit\Framework\Constraint\ObjectEquals; use PHPUnit\Framework\Constraint\RegularExpression; use PHPUnit\Framework\Constraint\StringContains; use PHPUnit\Framework\Constraint\StringEndsWith; use PHPUnit\Framework\Constraint\StringEqualsStringIgnoringLineEndings; use PHPUnit\Framework\Constraint\StringMatchesFormatDescription; use PHPUnit\Framework\Constraint\StringStartsWith; use PHPUnit\Framework\Constraint\TraversableContainsEqual; use PHPUnit\Framework\Constraint\TraversableContainsIdentical; use PHPUnit\Framework\Constraint\TraversableContainsOnly; use PHPUnit\Framework\MockObject\Rule\AnyInvokedCount as AnyInvokedCountMatcher; use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastCount as InvokedAtLeastCountMatcher; use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastOnce as InvokedAtLeastOnceMatcher; use PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount as InvokedAtMostCountMatcher; use PHPUnit\Framework\MockObject\Rule\InvokedCount as InvokedCountMatcher; use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls as ConsecutiveCallsStub; use PHPUnit\Framework\MockObject\Stub\Exception as ExceptionStub; use PHPUnit\Framework\MockObject\Stub\ReturnArgument as ReturnArgumentStub; use PHPUnit\Framework\MockObject\Stub\ReturnCallback as ReturnCallbackStub; use PHPUnit\Framework\MockObject\Stub\ReturnSelf as ReturnSelfStub; use PHPUnit\Framework\MockObject\Stub\ReturnStub; use PHPUnit\Framework\MockObject\Stub\ReturnValueMap as ReturnValueMapStub; use PHPUnit\Util\Xml\XmlException; use Throwable; if (!function_exists('PHPUnit\Framework\assertArrayHasKey')) { /** * Asserts that an array has a specified key. * * @throws Exception * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertArrayHasKey */ function assertArrayHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void { Assert::assertArrayHasKey(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertArrayNotHasKey')) { /** * Asserts that an array does not have a specified key. * * @throws Exception * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertArrayNotHasKey */ function assertArrayNotHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void { Assert::assertArrayNotHasKey(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsList')) { /** * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsList */ function assertIsList(mixed $array, string $message = ''): void { Assert::assertIsList(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertContains')) { /** * Asserts that a haystack contains a needle. * * @throws Exception * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertContains */ function assertContains(mixed $needle, iterable $haystack, string $message = ''): void { Assert::assertContains(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertContainsEquals')) { /** * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertContainsEquals */ function assertContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void { Assert::assertContainsEquals(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotContains')) { /** * Asserts that a haystack does not contain a needle. * * @throws Exception * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotContains */ function assertNotContains(mixed $needle, iterable $haystack, string $message = ''): void { Assert::assertNotContains(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotContainsEquals')) { /** * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotContainsEquals */ function assertNotContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void { Assert::assertNotContainsEquals(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertContainsOnly')) { /** * Asserts that a haystack contains only values of a given type. * * @throws Exception * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertContainsOnly */ function assertContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void { Assert::assertContainsOnly(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertContainsOnlyInstancesOf')) { /** * Asserts that a haystack contains only instances of a given class name. * * @throws Exception * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertContainsOnlyInstancesOf */ function assertContainsOnlyInstancesOf(string $className, iterable $haystack, string $message = ''): void { Assert::assertContainsOnlyInstancesOf(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotContainsOnly')) { /** * Asserts that a haystack does not contain only values of a given type. * * @throws Exception * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotContainsOnly */ function assertNotContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void { Assert::assertNotContainsOnly(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertCount')) { /** * Asserts the number of elements of an array, Countable or Traversable. * * @throws Exception * @throws ExpectationFailedException * @throws GeneratorNotSupportedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertCount */ function assertCount(int $expectedCount, Countable|iterable $haystack, string $message = ''): void { Assert::assertCount(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotCount')) { /** * Asserts the number of elements of an array, Countable or Traversable. * * @throws Exception * @throws ExpectationFailedException * @throws GeneratorNotSupportedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotCount */ function assertNotCount(int $expectedCount, Countable|iterable $haystack, string $message = ''): void { Assert::assertNotCount(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertEquals')) { /** * Asserts that two variables are equal. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertEquals */ function assertEquals(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertEquals(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertEqualsCanonicalizing')) { /** * Asserts that two variables are equal (canonicalizing). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertEqualsCanonicalizing */ function assertEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertEqualsCanonicalizing(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertEqualsIgnoringCase')) { /** * Asserts that two variables are equal (ignoring case). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertEqualsIgnoringCase */ function assertEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertEqualsIgnoringCase(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertEqualsWithDelta')) { /** * Asserts that two variables are equal (with delta). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertEqualsWithDelta */ function assertEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void { Assert::assertEqualsWithDelta(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotEquals')) { /** * Asserts that two variables are not equal. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotEquals */ function assertNotEquals(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertNotEquals(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotEqualsCanonicalizing')) { /** * Asserts that two variables are not equal (canonicalizing). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotEqualsCanonicalizing */ function assertNotEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertNotEqualsCanonicalizing(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotEqualsIgnoringCase')) { /** * Asserts that two variables are not equal (ignoring case). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotEqualsIgnoringCase */ function assertNotEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertNotEqualsIgnoringCase(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotEqualsWithDelta')) { /** * Asserts that two variables are not equal (with delta). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotEqualsWithDelta */ function assertNotEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void { Assert::assertNotEqualsWithDelta(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertObjectEquals')) { /** * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertObjectEquals */ function assertObjectEquals(object $expected, object $actual, string $method = 'equals', string $message = ''): void { Assert::assertObjectEquals(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertEmpty')) { /** * Asserts that a variable is empty. * * @throws ExpectationFailedException * @throws GeneratorNotSupportedException * * @psalm-assert empty $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertEmpty */ function assertEmpty(mixed $actual, string $message = ''): void { Assert::assertEmpty(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotEmpty')) { /** * Asserts that a variable is not empty. * * @throws ExpectationFailedException * @throws GeneratorNotSupportedException * * @psalm-assert !empty $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotEmpty */ function assertNotEmpty(mixed $actual, string $message = ''): void { Assert::assertNotEmpty(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertGreaterThan')) { /** * Asserts that a value is greater than another value. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertGreaterThan */ function assertGreaterThan(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertGreaterThan(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertGreaterThanOrEqual')) { /** * Asserts that a value is greater than or equal to another value. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertGreaterThanOrEqual */ function assertGreaterThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertGreaterThanOrEqual(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertLessThan')) { /** * Asserts that a value is smaller than another value. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertLessThan */ function assertLessThan(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertLessThan(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertLessThanOrEqual')) { /** * Asserts that a value is smaller than or equal to another value. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertLessThanOrEqual */ function assertLessThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertLessThanOrEqual(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileEquals')) { /** * Asserts that the contents of one file is equal to the contents of another * file. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileEquals */ function assertFileEquals(string $expected, string $actual, string $message = ''): void { Assert::assertFileEquals(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileEqualsCanonicalizing')) { /** * Asserts that the contents of one file is equal to the contents of another * file (canonicalizing). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileEqualsCanonicalizing */ function assertFileEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void { Assert::assertFileEqualsCanonicalizing(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileEqualsIgnoringCase')) { /** * Asserts that the contents of one file is equal to the contents of another * file (ignoring case). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileEqualsIgnoringCase */ function assertFileEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void { Assert::assertFileEqualsIgnoringCase(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileNotEquals')) { /** * Asserts that the contents of one file is not equal to the contents of * another file. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileNotEquals */ function assertFileNotEquals(string $expected, string $actual, string $message = ''): void { Assert::assertFileNotEquals(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileNotEqualsCanonicalizing')) { /** * Asserts that the contents of one file is not equal to the contents of another * file (canonicalizing). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileNotEqualsCanonicalizing */ function assertFileNotEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void { Assert::assertFileNotEqualsCanonicalizing(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileNotEqualsIgnoringCase')) { /** * Asserts that the contents of one file is not equal to the contents of another * file (ignoring case). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileNotEqualsIgnoringCase */ function assertFileNotEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void { Assert::assertFileNotEqualsIgnoringCase(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringEqualsFile')) { /** * Asserts that the contents of a string is equal * to the contents of a file. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringEqualsFile */ function assertStringEqualsFile(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringEqualsFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringEqualsFileCanonicalizing')) { /** * Asserts that the contents of a string is equal * to the contents of a file (canonicalizing). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringEqualsFileCanonicalizing */ function assertStringEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringEqualsFileCanonicalizing(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringEqualsFileIgnoringCase')) { /** * Asserts that the contents of a string is equal * to the contents of a file (ignoring case). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringEqualsFileIgnoringCase */ function assertStringEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringEqualsFileIgnoringCase(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringNotEqualsFile')) { /** * Asserts that the contents of a string is not equal * to the contents of a file. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringNotEqualsFile */ function assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringNotEqualsFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringNotEqualsFileCanonicalizing')) { /** * Asserts that the contents of a string is not equal * to the contents of a file (canonicalizing). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringNotEqualsFileCanonicalizing */ function assertStringNotEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringNotEqualsFileCanonicalizing(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringNotEqualsFileIgnoringCase')) { /** * Asserts that the contents of a string is not equal * to the contents of a file (ignoring case). * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringNotEqualsFileIgnoringCase */ function assertStringNotEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void { Assert::assertStringNotEqualsFileIgnoringCase(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsReadable')) { /** * Asserts that a file/dir is readable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsReadable */ function assertIsReadable(string $filename, string $message = ''): void { Assert::assertIsReadable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotReadable')) { /** * Asserts that a file/dir exists and is not readable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotReadable */ function assertIsNotReadable(string $filename, string $message = ''): void { Assert::assertIsNotReadable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsWritable')) { /** * Asserts that a file/dir exists and is writable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsWritable */ function assertIsWritable(string $filename, string $message = ''): void { Assert::assertIsWritable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotWritable')) { /** * Asserts that a file/dir exists and is not writable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotWritable */ function assertIsNotWritable(string $filename, string $message = ''): void { Assert::assertIsNotWritable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertDirectoryExists')) { /** * Asserts that a directory exists. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertDirectoryExists */ function assertDirectoryExists(string $directory, string $message = ''): void { Assert::assertDirectoryExists(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertDirectoryDoesNotExist')) { /** * Asserts that a directory does not exist. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertDirectoryDoesNotExist */ function assertDirectoryDoesNotExist(string $directory, string $message = ''): void { Assert::assertDirectoryDoesNotExist(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertDirectoryIsReadable')) { /** * Asserts that a directory exists and is readable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertDirectoryIsReadable */ function assertDirectoryIsReadable(string $directory, string $message = ''): void { Assert::assertDirectoryIsReadable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertDirectoryIsNotReadable')) { /** * Asserts that a directory exists and is not readable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertDirectoryIsNotReadable */ function assertDirectoryIsNotReadable(string $directory, string $message = ''): void { Assert::assertDirectoryIsNotReadable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertDirectoryIsWritable')) { /** * Asserts that a directory exists and is writable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertDirectoryIsWritable */ function assertDirectoryIsWritable(string $directory, string $message = ''): void { Assert::assertDirectoryIsWritable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertDirectoryIsNotWritable')) { /** * Asserts that a directory exists and is not writable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertDirectoryIsNotWritable */ function assertDirectoryIsNotWritable(string $directory, string $message = ''): void { Assert::assertDirectoryIsNotWritable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileExists')) { /** * Asserts that a file exists. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileExists */ function assertFileExists(string $filename, string $message = ''): void { Assert::assertFileExists(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileDoesNotExist')) { /** * Asserts that a file does not exist. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileDoesNotExist */ function assertFileDoesNotExist(string $filename, string $message = ''): void { Assert::assertFileDoesNotExist(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileIsReadable')) { /** * Asserts that a file exists and is readable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileIsReadable */ function assertFileIsReadable(string $file, string $message = ''): void { Assert::assertFileIsReadable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileIsNotReadable')) { /** * Asserts that a file exists and is not readable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileIsNotReadable */ function assertFileIsNotReadable(string $file, string $message = ''): void { Assert::assertFileIsNotReadable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileIsWritable')) { /** * Asserts that a file exists and is writable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileIsWritable */ function assertFileIsWritable(string $file, string $message = ''): void { Assert::assertFileIsWritable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileIsNotWritable')) { /** * Asserts that a file exists and is not writable. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileIsNotWritable */ function assertFileIsNotWritable(string $file, string $message = ''): void { Assert::assertFileIsNotWritable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertTrue')) { /** * Asserts that a condition is true. * * @throws ExpectationFailedException * * @psalm-assert true $condition * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertTrue */ function assertTrue(mixed $condition, string $message = ''): void { Assert::assertTrue(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotTrue')) { /** * Asserts that a condition is not true. * * @throws ExpectationFailedException * * @psalm-assert !true $condition * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotTrue */ function assertNotTrue(mixed $condition, string $message = ''): void { Assert::assertNotTrue(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFalse')) { /** * Asserts that a condition is false. * * @throws ExpectationFailedException * * @psalm-assert false $condition * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFalse */ function assertFalse(mixed $condition, string $message = ''): void { Assert::assertFalse(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotFalse')) { /** * Asserts that a condition is not false. * * @throws ExpectationFailedException * * @psalm-assert !false $condition * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotFalse */ function assertNotFalse(mixed $condition, string $message = ''): void { Assert::assertNotFalse(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNull')) { /** * Asserts that a variable is null. * * @throws ExpectationFailedException * * @psalm-assert null $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNull */ function assertNull(mixed $actual, string $message = ''): void { Assert::assertNull(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotNull')) { /** * Asserts that a variable is not null. * * @throws ExpectationFailedException * * @psalm-assert !null $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotNull */ function assertNotNull(mixed $actual, string $message = ''): void { Assert::assertNotNull(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFinite')) { /** * Asserts that a variable is finite. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFinite */ function assertFinite(mixed $actual, string $message = ''): void { Assert::assertFinite(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertInfinite')) { /** * Asserts that a variable is infinite. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertInfinite */ function assertInfinite(mixed $actual, string $message = ''): void { Assert::assertInfinite(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNan')) { /** * Asserts that a variable is nan. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNan */ function assertNan(mixed $actual, string $message = ''): void { Assert::assertNan(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertObjectHasProperty')) { /** * Asserts that an object has a specified property. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertObjectHasProperty() */ function assertObjectHasProperty(string $attributeName, object $object, string $message = ''): void { Assert::assertObjectHasProperty(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertObjectNotHasProperty')) { /** * Asserts that an object does not have a specified property. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertObjectNotHasProperty() */ function assertObjectNotHasProperty(string $attributeName, object $object, string $message = ''): void { Assert::assertObjectNotHasProperty(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertSame')) { /** * Asserts that two variables have the same type and value. * Used on objects, it asserts that two variables reference * the same object. * * @throws ExpectationFailedException * * @psalm-template ExpectedType * * @psalm-param ExpectedType $expected * * @psalm-assert =ExpectedType $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertSame */ function assertSame(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertSame(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotSame')) { /** * Asserts that two variables do not have the same type and value. * Used on objects, it asserts that two variables do not reference * the same object. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotSame */ function assertNotSame(mixed $expected, mixed $actual, string $message = ''): void { Assert::assertNotSame(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertInstanceOf')) { /** * Asserts that a variable is of a given type. * * @throws Exception * @throws ExpectationFailedException * * @psalm-template ExpectedType of object * * @psalm-param class-string<ExpectedType> $expected * * @psalm-assert =ExpectedType $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertInstanceOf */ function assertInstanceOf(string $expected, mixed $actual, string $message = ''): void { Assert::assertInstanceOf(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotInstanceOf')) { /** * Asserts that a variable is not of a given type. * * @throws Exception * @throws ExpectationFailedException * * @psalm-template ExpectedType of object * * @psalm-param class-string<ExpectedType> $expected * * @psalm-assert !ExpectedType $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotInstanceOf */ function assertNotInstanceOf(string $expected, mixed $actual, string $message = ''): void { Assert::assertNotInstanceOf(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsArray')) { /** * Asserts that a variable is of type array. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert array $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsArray */ function assertIsArray(mixed $actual, string $message = ''): void { Assert::assertIsArray(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsBool')) { /** * Asserts that a variable is of type bool. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert bool $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsBool */ function assertIsBool(mixed $actual, string $message = ''): void { Assert::assertIsBool(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsFloat')) { /** * Asserts that a variable is of type float. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert float $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsFloat */ function assertIsFloat(mixed $actual, string $message = ''): void { Assert::assertIsFloat(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsInt')) { /** * Asserts that a variable is of type int. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert int $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsInt */ function assertIsInt(mixed $actual, string $message = ''): void { Assert::assertIsInt(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNumeric')) { /** * Asserts that a variable is of type numeric. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert numeric $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNumeric */ function assertIsNumeric(mixed $actual, string $message = ''): void { Assert::assertIsNumeric(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsObject')) { /** * Asserts that a variable is of type object. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert object $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsObject */ function assertIsObject(mixed $actual, string $message = ''): void { Assert::assertIsObject(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsResource')) { /** * Asserts that a variable is of type resource. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert resource $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsResource */ function assertIsResource(mixed $actual, string $message = ''): void { Assert::assertIsResource(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsClosedResource')) { /** * Asserts that a variable is of type resource and is closed. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert resource $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsClosedResource */ function assertIsClosedResource(mixed $actual, string $message = ''): void { Assert::assertIsClosedResource(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsString')) { /** * Asserts that a variable is of type string. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert string $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsString */ function assertIsString(mixed $actual, string $message = ''): void { Assert::assertIsString(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsScalar')) { /** * Asserts that a variable is of type scalar. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert scalar $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsScalar */ function assertIsScalar(mixed $actual, string $message = ''): void { Assert::assertIsScalar(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsCallable')) { /** * Asserts that a variable is of type callable. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert callable $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsCallable */ function assertIsCallable(mixed $actual, string $message = ''): void { Assert::assertIsCallable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsIterable')) { /** * Asserts that a variable is of type iterable. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert iterable $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsIterable */ function assertIsIterable(mixed $actual, string $message = ''): void { Assert::assertIsIterable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotArray')) { /** * Asserts that a variable is not of type array. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !array $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotArray */ function assertIsNotArray(mixed $actual, string $message = ''): void { Assert::assertIsNotArray(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotBool')) { /** * Asserts that a variable is not of type bool. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !bool $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotBool */ function assertIsNotBool(mixed $actual, string $message = ''): void { Assert::assertIsNotBool(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotFloat')) { /** * Asserts that a variable is not of type float. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !float $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotFloat */ function assertIsNotFloat(mixed $actual, string $message = ''): void { Assert::assertIsNotFloat(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotInt')) { /** * Asserts that a variable is not of type int. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !int $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotInt */ function assertIsNotInt(mixed $actual, string $message = ''): void { Assert::assertIsNotInt(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotNumeric')) { /** * Asserts that a variable is not of type numeric. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !numeric $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotNumeric */ function assertIsNotNumeric(mixed $actual, string $message = ''): void { Assert::assertIsNotNumeric(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotObject')) { /** * Asserts that a variable is not of type object. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !object $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotObject */ function assertIsNotObject(mixed $actual, string $message = ''): void { Assert::assertIsNotObject(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotResource')) { /** * Asserts that a variable is not of type resource. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !resource $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotResource */ function assertIsNotResource(mixed $actual, string $message = ''): void { Assert::assertIsNotResource(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotClosedResource')) { /** * Asserts that a variable is not of type resource. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !resource $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotClosedResource */ function assertIsNotClosedResource(mixed $actual, string $message = ''): void { Assert::assertIsNotClosedResource(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotString')) { /** * Asserts that a variable is not of type string. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !string $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotString */ function assertIsNotString(mixed $actual, string $message = ''): void { Assert::assertIsNotString(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotScalar')) { /** * Asserts that a variable is not of type scalar. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !scalar $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotScalar */ function assertIsNotScalar(mixed $actual, string $message = ''): void { Assert::assertIsNotScalar(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotCallable')) { /** * Asserts that a variable is not of type callable. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !callable $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotCallable */ function assertIsNotCallable(mixed $actual, string $message = ''): void { Assert::assertIsNotCallable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertIsNotIterable')) { /** * Asserts that a variable is not of type iterable. * * @throws Exception * @throws ExpectationFailedException * * @psalm-assert !iterable $actual * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertIsNotIterable */ function assertIsNotIterable(mixed $actual, string $message = ''): void { Assert::assertIsNotIterable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertMatchesRegularExpression')) { /** * Asserts that a string matches a given regular expression. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertMatchesRegularExpression */ function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void { Assert::assertMatchesRegularExpression(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertDoesNotMatchRegularExpression')) { /** * Asserts that a string does not match a given regular expression. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertDoesNotMatchRegularExpression */ function assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = ''): void { Assert::assertDoesNotMatchRegularExpression(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertSameSize')) { /** * Assert that the size of two arrays (or `Countable` or `Traversable` objects) * is the same. * * @throws Exception * @throws ExpectationFailedException * @throws GeneratorNotSupportedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertSameSize */ function assertSameSize(Countable|iterable $expected, Countable|iterable $actual, string $message = ''): void { Assert::assertSameSize(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertNotSameSize')) { /** * Assert that the size of two arrays (or `Countable` or `Traversable` objects) * is not the same. * * @throws Exception * @throws ExpectationFailedException * @throws GeneratorNotSupportedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertNotSameSize */ function assertNotSameSize(Countable|iterable $expected, Countable|iterable $actual, string $message = ''): void { Assert::assertNotSameSize(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringContainsStringIgnoringLineEndings')) { /** * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringContainsStringIgnoringLineEndings */ function assertStringContainsStringIgnoringLineEndings(string $needle, string $haystack, string $message = ''): void { Assert::assertStringContainsStringIgnoringLineEndings(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringEqualsStringIgnoringLineEndings')) { /** * Asserts that two strings are equal except for line endings. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringEqualsStringIgnoringLineEndings */ function assertStringEqualsStringIgnoringLineEndings(string $expected, string $actual, string $message = ''): void { Assert::assertStringEqualsStringIgnoringLineEndings(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileMatchesFormat')) { /** * Asserts that a string matches a given format string. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileMatchesFormat */ function assertFileMatchesFormat(string $format, string $actualFile, string $message = ''): void { Assert::assertFileMatchesFormat(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertFileMatchesFormatFile')) { /** * Asserts that a string matches a given format string. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertFileMatchesFormatFile */ function assertFileMatchesFormatFile(string $formatFile, string $actualFile, string $message = ''): void { Assert::assertFileMatchesFormatFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringMatchesFormat')) { /** * Asserts that a string matches a given format string. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringMatchesFormat */ function assertStringMatchesFormat(string $format, string $string, string $message = ''): void { Assert::assertStringMatchesFormat(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringNotMatchesFormat')) { /** * Asserts that a string does not match a given format string. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringNotMatchesFormat * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5472 */ function assertStringNotMatchesFormat(string $format, string $string, string $message = ''): void { Assert::assertStringNotMatchesFormat(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringMatchesFormatFile')) { /** * Asserts that a string matches a given format file. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringMatchesFormatFile */ function assertStringMatchesFormatFile(string $formatFile, string $string, string $message = ''): void { Assert::assertStringMatchesFormatFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringNotMatchesFormatFile')) { /** * Asserts that a string does not match a given format string. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringNotMatchesFormatFile * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5472 */ function assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = ''): void { Assert::assertStringNotMatchesFormatFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringStartsWith')) { /** * Asserts that a string starts with a given prefix. * * @psalm-param non-empty-string $prefix * * @throws ExpectationFailedException * @throws InvalidArgumentException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringStartsWith */ function assertStringStartsWith(string $prefix, string $string, string $message = ''): void { Assert::assertStringStartsWith(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringStartsNotWith')) { /** * Asserts that a string starts not with a given prefix. * * @psalm-param non-empty-string $prefix * * @throws ExpectationFailedException * @throws InvalidArgumentException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringStartsNotWith */ function assertStringStartsNotWith(string $prefix, string $string, string $message = ''): void { Assert::assertStringStartsNotWith(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringContainsString')) { /** * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringContainsString */ function assertStringContainsString(string $needle, string $haystack, string $message = ''): void { Assert::assertStringContainsString(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringContainsStringIgnoringCase')) { /** * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringContainsStringIgnoringCase */ function assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void { Assert::assertStringContainsStringIgnoringCase(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringNotContainsString')) { /** * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringNotContainsString */ function assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void { Assert::assertStringNotContainsString(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringNotContainsStringIgnoringCase')) { /** * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringNotContainsStringIgnoringCase */ function assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void { Assert::assertStringNotContainsStringIgnoringCase(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringEndsWith')) { /** * Asserts that a string ends with a given suffix. * * @psalm-param non-empty-string $suffix * * @throws ExpectationFailedException * @throws InvalidArgumentException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringEndsWith */ function assertStringEndsWith(string $suffix, string $string, string $message = ''): void { Assert::assertStringEndsWith(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertStringEndsNotWith')) { /** * Asserts that a string ends not with a given suffix. * * @psalm-param non-empty-string $suffix * * @throws ExpectationFailedException * @throws InvalidArgumentException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertStringEndsNotWith */ function assertStringEndsNotWith(string $suffix, string $string, string $message = ''): void { Assert::assertStringEndsNotWith(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertXmlFileEqualsXmlFile')) { /** * Asserts that two XML files are equal. * * @throws Exception * @throws ExpectationFailedException * @throws XmlException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertXmlFileEqualsXmlFile */ function assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void { Assert::assertXmlFileEqualsXmlFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertXmlFileNotEqualsXmlFile')) { /** * Asserts that two XML files are not equal. * * @throws \PHPUnit\Util\Exception * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertXmlFileNotEqualsXmlFile */ function assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void { Assert::assertXmlFileNotEqualsXmlFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertXmlStringEqualsXmlFile')) { /** * Asserts that two XML documents are equal. * * @throws ExpectationFailedException * @throws XmlException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertXmlStringEqualsXmlFile */ function assertXmlStringEqualsXmlFile(string $expectedFile, string $actualXml, string $message = ''): void { Assert::assertXmlStringEqualsXmlFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertXmlStringNotEqualsXmlFile')) { /** * Asserts that two XML documents are not equal. * * @throws ExpectationFailedException * @throws XmlException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertXmlStringNotEqualsXmlFile */ function assertXmlStringNotEqualsXmlFile(string $expectedFile, string $actualXml, string $message = ''): void { Assert::assertXmlStringNotEqualsXmlFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertXmlStringEqualsXmlString')) { /** * Asserts that two XML documents are equal. * * @throws ExpectationFailedException * @throws XmlException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertXmlStringEqualsXmlString */ function assertXmlStringEqualsXmlString(string $expectedXml, string $actualXml, string $message = ''): void { Assert::assertXmlStringEqualsXmlString(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertXmlStringNotEqualsXmlString')) { /** * Asserts that two XML documents are not equal. * * @throws ExpectationFailedException * @throws XmlException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertXmlStringNotEqualsXmlString */ function assertXmlStringNotEqualsXmlString(string $expectedXml, string $actualXml, string $message = ''): void { Assert::assertXmlStringNotEqualsXmlString(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertThat')) { /** * Evaluates a PHPUnit\Framework\Constraint matcher object. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertThat */ function assertThat(mixed $value, Constraint $constraint, string $message = ''): void { Assert::assertThat(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertJson')) { /** * Asserts that a string is a valid JSON string. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertJson */ function assertJson(string $actual, string $message = ''): void { Assert::assertJson(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertJsonStringEqualsJsonString')) { /** * Asserts that two given JSON encoded objects or arrays are equal. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertJsonStringEqualsJsonString */ function assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void { Assert::assertJsonStringEqualsJsonString(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertJsonStringNotEqualsJsonString')) { /** * Asserts that two given JSON encoded objects or arrays are not equal. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertJsonStringNotEqualsJsonString */ function assertJsonStringNotEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void { Assert::assertJsonStringNotEqualsJsonString(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertJsonStringEqualsJsonFile')) { /** * Asserts that the generated JSON encoded object and the content of the given file are equal. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertJsonStringEqualsJsonFile */ function assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void { Assert::assertJsonStringEqualsJsonFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertJsonStringNotEqualsJsonFile')) { /** * Asserts that the generated JSON encoded object and the content of the given file are not equal. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertJsonStringNotEqualsJsonFile */ function assertJsonStringNotEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void { Assert::assertJsonStringNotEqualsJsonFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertJsonFileEqualsJsonFile')) { /** * Asserts that two JSON files are equal. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertJsonFileEqualsJsonFile */ function assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void { Assert::assertJsonFileEqualsJsonFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\assertJsonFileNotEqualsJsonFile')) { /** * Asserts that two JSON files are not equal. * * @throws ExpectationFailedException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @see Assert::assertJsonFileNotEqualsJsonFile */ function assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void { Assert::assertJsonFileNotEqualsJsonFile(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\logicalAnd')) { /** * @throws Exception */ function logicalAnd(mixed ...$constraints): LogicalAnd { return Assert::logicalAnd(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\logicalOr')) { function logicalOr(mixed ...$constraints): LogicalOr { return Assert::logicalOr(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\logicalNot')) { function logicalNot(Constraint $constraint): LogicalNot { return Assert::logicalNot(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\logicalXor')) { function logicalXor(mixed ...$constraints): LogicalXor { return Assert::logicalXor(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\anything')) { function anything(): IsAnything { return Assert::anything(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isTrue')) { function isTrue(): IsTrue { return Assert::isTrue(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\callback')) { function callback(callable $callback): Callback { return Assert::callback(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isFalse')) { function isFalse(): IsFalse { return Assert::isFalse(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isJson')) { function isJson(): IsJson { return Assert::isJson(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isNull')) { function isNull(): IsNull { return Assert::isNull(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isFinite')) { function isFinite(): IsFinite { return Assert::isFinite(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isInfinite')) { function isInfinite(): IsInfinite { return Assert::isInfinite(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isNan')) { function isNan(): IsNan { return Assert::isNan(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\containsEqual')) { function containsEqual(mixed $value): TraversableContainsEqual { return Assert::containsEqual(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\containsIdentical')) { function containsIdentical(mixed $value): TraversableContainsIdentical { return Assert::containsIdentical(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\containsOnly')) { /** * @throws Exception */ function containsOnly(string $type): TraversableContainsOnly { return Assert::containsOnly(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\containsOnlyInstancesOf')) { /** * @throws Exception */ function containsOnlyInstancesOf(string $className): TraversableContainsOnly { return Assert::containsOnlyInstancesOf(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\arrayHasKey')) { function arrayHasKey(int|string $key): ArrayHasKey { return Assert::arrayHasKey(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isList')) { function isList(): IsList { return Assert::isList(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\equalTo')) { function equalTo(mixed $value): IsEqual { return Assert::equalTo(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\equalToCanonicalizing')) { function equalToCanonicalizing(mixed $value): IsEqualCanonicalizing { return Assert::equalToCanonicalizing(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\equalToIgnoringCase')) { function equalToIgnoringCase(mixed $value): IsEqualIgnoringCase { return Assert::equalToIgnoringCase(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\equalToWithDelta')) { function equalToWithDelta(mixed $value, float $delta): IsEqualWithDelta { return Assert::equalToWithDelta(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isEmpty')) { function isEmpty(): IsEmpty { return Assert::isEmpty(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isWritable')) { function isWritable(): IsWritable { return Assert::isWritable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isReadable')) { function isReadable(): IsReadable { return Assert::isReadable(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\directoryExists')) { function directoryExists(): DirectoryExists { return Assert::directoryExists(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\fileExists')) { function fileExists(): FileExists { return Assert::fileExists(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\greaterThan')) { function greaterThan(mixed $value): GreaterThan { return Assert::greaterThan(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\greaterThanOrEqual')) { function greaterThanOrEqual(mixed $value): LogicalOr { return Assert::greaterThanOrEqual(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\identicalTo')) { function identicalTo(mixed $value): IsIdentical { return Assert::identicalTo(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isInstanceOf')) { /** * @throws UnknownClassOrInterfaceException */ function isInstanceOf(string $className): IsInstanceOf { return Assert::isInstanceOf(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\isType')) { /** * @throws Exception */ function isType(string $type): IsType { return Assert::isType(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\lessThan')) { function lessThan(mixed $value): LessThan { return Assert::lessThan(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\lessThanOrEqual')) { function lessThanOrEqual(mixed $value): LogicalOr { return Assert::lessThanOrEqual(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\matchesRegularExpression')) { function matchesRegularExpression(string $pattern): RegularExpression { return Assert::matchesRegularExpression(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\matches')) { function matches(string $string): StringMatchesFormatDescription { return Assert::matches(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\stringStartsWith')) { /** * @throws InvalidArgumentException */ function stringStartsWith(string $prefix): StringStartsWith { return Assert::stringStartsWith(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\stringContains')) { /** * @throws InvalidArgumentException */ function stringContains(string $string, bool $case = true): StringContains { return Assert::stringContains(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\stringEndsWith')) { /** * @throws InvalidArgumentException */ function stringEndsWith(string $suffix): StringEndsWith { return Assert::stringEndsWith(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\stringEqualsStringIgnoringLineEndings')) { function stringEqualsStringIgnoringLineEndings(string $string): StringEqualsStringIgnoringLineEndings { return Assert::stringEqualsStringIgnoringLineEndings(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\countOf')) { function countOf(int $count): Count { return Assert::countOf(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\objectEquals')) { function objectEquals(object $object, string $method = 'equals'): ObjectEquals { return Assert::objectEquals(...func_get_args()); } } if (!function_exists('PHPUnit\Framework\any')) { /** * Returns a matcher that matches when the method is executed * zero or more times. */ function any(): AnyInvokedCountMatcher { return new AnyInvokedCountMatcher; } } if (!function_exists('PHPUnit\Framework\never')) { /** * Returns a matcher that matches when the method is never executed. */ function never(): InvokedCountMatcher { return new InvokedCountMatcher(0); } } if (!function_exists('PHPUnit\Framework\atLeast')) { /** * Returns a matcher that matches when the method is executed * at least N times. */ function atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher { return new InvokedAtLeastCountMatcher( $requiredInvocations, ); } } if (!function_exists('PHPUnit\Framework\atLeastOnce')) { /** * Returns a matcher that matches when the method is executed at least once. */ function atLeastOnce(): InvokedAtLeastOnceMatcher { return new InvokedAtLeastOnceMatcher; } } if (!function_exists('PHPUnit\Framework\once')) { /** * Returns a matcher that matches when the method is executed exactly once. */ function once(): InvokedCountMatcher { return new InvokedCountMatcher(1); } } if (!function_exists('PHPUnit\Framework\exactly')) { /** * Returns a matcher that matches when the method is executed * exactly $count times. */ function exactly(int $count): InvokedCountMatcher { return new InvokedCountMatcher($count); } } if (!function_exists('PHPUnit\Framework\atMost')) { /** * Returns a matcher that matches when the method is executed * at most N times. */ function atMost(int $allowedInvocations): InvokedAtMostCountMatcher { return new InvokedAtMostCountMatcher($allowedInvocations); } } if (!function_exists('PHPUnit\Framework\returnValue')) { function returnValue(mixed $value): ReturnStub { return new ReturnStub($value); } } if (!function_exists('PHPUnit\Framework\returnValueMap')) { function returnValueMap(array $valueMap): ReturnValueMapStub { return new ReturnValueMapStub($valueMap); } } if (!function_exists('PHPUnit\Framework\returnArgument')) { function returnArgument(int $argumentIndex): ReturnArgumentStub { return new ReturnArgumentStub($argumentIndex); } } if (!function_exists('PHPUnit\Framework\returnCallback')) { function returnCallback(callable $callback): ReturnCallbackStub { return new ReturnCallbackStub($callback); } } if (!function_exists('PHPUnit\Framework\returnSelf')) { /** * Returns the current object. * * This method is useful when mocking a fluent interface. */ function returnSelf(): ReturnSelfStub { return new ReturnSelfStub; } } if (!function_exists('PHPUnit\Framework\throwException')) { function throwException(Throwable $exception): ExceptionStub { return new ExceptionStub($exception); } } if (!function_exists('PHPUnit\Framework\onConsecutiveCalls')) { function onConsecutiveCalls(): ConsecutiveCallsStub { $arguments = func_get_args(); return new ConsecutiveCallsStub($arguments); } } Attributes/RequiresMethod.php 0000644 00000002425 15107326342 0012351 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class RequiresMethod { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-var non-empty-string */ private readonly string $methodName; /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ public function __construct(string $className, string $methodName) { $this->className = $className; $this->methodName = $methodName; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } } Attributes/IgnoreFunctionForCodeCoverage.php 0000644 00000002033 15107326342 0015253 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5513 */ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final class IgnoreFunctionForCodeCoverage { /** * @psalm-var non-empty-string */ private readonly string $functionName; /** * @psalm-param non-empty-string $functionName */ public function __construct(string $functionName) { $this->functionName = $functionName; } /** * @psalm-return non-empty-string */ public function functionName(): string { return $this->functionName; } } Attributes/BackupGlobals.php 0000644 00000001360 15107326342 0012117 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class BackupGlobals { private readonly bool $enabled; public function __construct(bool $enabled) { $this->enabled = $enabled; } public function enabled(): bool { return $this->enabled; } } Attributes/PreCondition.php 0000644 00000001002 15107326342 0011774 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD)] final class PreCondition { } Attributes/DependsUsingDeepClone.php 0000644 00000001673 15107326342 0013564 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class DependsUsingDeepClone { /** * @psalm-var non-empty-string */ private readonly string $methodName; /** * @psalm-param non-empty-string $methodName */ public function __construct(string $methodName) { $this->methodName = $methodName; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } } Attributes/DependsOnClassUsingShallowClone.php 0000644 00000001662 15107326342 0015601 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class DependsOnClassUsingShallowClone { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-param class-string $className */ public function __construct(string $className) { $this->className = $className; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } } Attributes/Depends.php 0000644 00000001655 15107326342 0010777 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class Depends { /** * @psalm-var non-empty-string */ private readonly string $methodName; /** * @psalm-param non-empty-string $methodName */ public function __construct(string $methodName) { $this->methodName = $methodName; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } } Attributes/IgnoreMethodForCodeCoverage.php 0000644 00000002522 15107326342 0014711 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5513 */ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final class IgnoreMethodForCodeCoverage { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-var non-empty-string */ private readonly string $methodName; /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ public function __construct(string $className, string $methodName) { $this->className = $className; $this->methodName = $methodName; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } } Attributes/RequiresOperatingSystemFamily.php 0000644 00000002017 15107326342 0015425 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class RequiresOperatingSystemFamily { /** * @psalm-var non-empty-string */ private readonly string $operatingSystemFamily; /** * @psalm-param non-empty-string $operatingSystemFamily */ public function __construct(string $operatingSystemFamily) { $this->operatingSystemFamily = $operatingSystemFamily; } /** * @psalm-return non-empty-string */ public function operatingSystemFamily(): string { return $this->operatingSystemFamily; } } Attributes/ExcludeGlobalVariableFromBackup.php 0000644 00000002027 15107326342 0015541 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class ExcludeGlobalVariableFromBackup { /** * @psalm-var non-empty-string */ private readonly string $globalVariableName; /** * @psalm-param non-empty-string $globalVariableName */ public function __construct(string $globalVariableName) { $this->globalVariableName = $globalVariableName; } /** * @psalm-return non-empty-string */ public function globalVariableName(): string { return $this->globalVariableName; } } Attributes/DependsUsingShallowClone.php 0000644 00000001676 15107326342 0014323 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class DependsUsingShallowClone { /** * @psalm-var non-empty-string */ private readonly string $methodName; /** * @psalm-param non-empty-string $methodName */ public function __construct(string $methodName) { $this->methodName = $methodName; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } } Attributes/RequiresFunction.php 0000644 00000001736 15107326342 0012722 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class RequiresFunction { /** * @psalm-var non-empty-string */ private readonly string $functionName; /** * @psalm-param non-empty-string $functionName */ public function __construct(string $functionName) { $this->functionName = $functionName; } /** * @psalm-return non-empty-string */ public function functionName(): string { return $this->functionName; } } Attributes/IgnoreClassForCodeCoverage.php 0000644 00000001767 15107326342 0014550 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5513 */ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final class IgnoreClassForCodeCoverage { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-param class-string $className */ public function __construct(string $className) { $this->className = $className; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } } Attributes/After.php 0000644 00000000773 15107326342 0010456 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD)] final class After { } Attributes/DataProviderExternal.php 0000644 00000002401 15107326342 0013472 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class DataProviderExternal { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-var non-empty-string */ private readonly string $methodName; /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ public function __construct(string $className, string $methodName) { $this->className = $className; $this->methodName = $methodName; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } } Attributes/CoversFunction.php 0000644 00000001701 15107326342 0012354 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final class CoversFunction { /** * @psalm-var non-empty-string */ private readonly string $functionName; /** * @psalm-param non-empty-string $functionName */ public function __construct(string $functionName) { $this->functionName = $functionName; } /** * @psalm-return non-empty-string */ public function functionName(): string { return $this->functionName; } } Attributes/RequiresPhp.php 0000644 00000001750 15107326342 0011660 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class RequiresPhp { /** * @psalm-var non-empty-string */ private readonly string $versionRequirement; /** * @psalm-param non-empty-string $versionRequirement */ public function __construct(string $versionRequirement) { $this->versionRequirement = $versionRequirement; } /** * @psalm-return non-empty-string */ public function versionRequirement(): string { return $this->versionRequirement; } } Attributes/Medium.php 0000644 00000000773 15107326342 0010635 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS)] final class Medium { } Attributes/TestDox.php 0000644 00000001602 15107326342 0010777 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class TestDox { /** * @psalm-var non-empty-string */ private readonly string $text; /** * @psalm-param non-empty-string $text */ public function __construct(string $text) { $this->text = $text; } /** * @psalm-return non-empty-string */ public function text(): string { return $this->text; } } Attributes/DependsExternal.php 0000644 00000002374 15107326342 0012501 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class DependsExternal { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-var non-empty-string */ private readonly string $methodName; /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ public function __construct(string $className, string $methodName) { $this->className = $className; $this->methodName = $methodName; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } } Attributes/AfterClass.php 0000644 00000001000 15107326342 0011424 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD)] final class AfterClass { } Attributes/BackupStaticProperties.php 0000644 00000001371 15107326342 0014042 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class BackupStaticProperties { private readonly bool $enabled; public function __construct(bool $enabled) { $this->enabled = $enabled; } public function enabled(): bool { return $this->enabled; } } Attributes/CoversNothing.php 0000644 00000001035 15107326342 0012175 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class CoversNothing { } Attributes/UsesClass.php 0000644 00000001633 15107326342 0011316 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final class UsesClass { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-param class-string $className */ public function __construct(string $className) { $this->className = $className; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } } Attributes/ExcludeStaticPropertyFromBackup.php 0000644 00000002466 15107326342 0015676 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class ExcludeStaticPropertyFromBackup { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-var non-empty-string */ private readonly string $propertyName; /** * @psalm-param class-string $className * @psalm-param non-empty-string $propertyName */ public function __construct(string $className, string $propertyName) { $this->className = $className; $this->propertyName = $propertyName; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } /** * @psalm-return non-empty-string */ public function propertyName(): string { return $this->propertyName; } } Attributes/WithoutErrorHandler.php 0000644 00000001011 15107326342 0013352 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD)] final class WithoutErrorHandler { } Attributes/RequiresPhpExtension.php 0000644 00000002600 15107326342 0013550 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class RequiresPhpExtension { /** * @psalm-var non-empty-string */ private readonly string $extension; /** * @psalm-var null|non-empty-string */ private readonly ?string $versionRequirement; /** * @psalm-param non-empty-string $extension * @psalm-param null|non-empty-string $versionRequirement */ public function __construct(string $extension, ?string $versionRequirement = null) { $this->extension = $extension; $this->versionRequirement = $versionRequirement; } /** * @psalm-return non-empty-string */ public function extension(): string { return $this->extension; } /** * @psalm-return null|non-empty-string */ public function versionRequirement(): ?string { return $this->versionRequirement; } } Attributes/RequiresOperatingSystem.php 0000644 00000001755 15107326342 0014273 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class RequiresOperatingSystem { /** * @psalm-var non-empty-string */ private readonly string $regularExpression; /** * @psalm-param non-empty-string $regularExpression */ public function __construct(string $regularExpression) { $this->regularExpression = $regularExpression; } /** * @psalm-return non-empty-string */ public function regularExpression(): string { return $this->regularExpression; } } Attributes/DoesNotPerformAssertions.php 0000644 00000001050 15107326342 0014363 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class DoesNotPerformAssertions { } Attributes/Test.php 0000644 00000000772 15107326342 0010333 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD)] final class Test { } Attributes/RequiresPhpunit.php 0000644 00000001754 15107326342 0012564 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class RequiresPhpunit { /** * @psalm-var non-empty-string */ private readonly string $versionRequirement; /** * @psalm-param non-empty-string $versionRequirement */ public function __construct(string $versionRequirement) { $this->versionRequirement = $versionRequirement; } /** * @psalm-return non-empty-string */ public function versionRequirement(): string { return $this->versionRequirement; } } Attributes/DataProvider.php 0000644 00000001662 15107326342 0011777 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class DataProvider { /** * @psalm-var non-empty-string */ private readonly string $methodName; /** * @psalm-param non-empty-string $methodName */ public function __construct(string $methodName) { $this->methodName = $methodName; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } } Attributes/BeforeClass.php 0000644 00000001001 15107326342 0011566 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD)] final class BeforeClass { } Attributes/UsesFunction.php 0000644 00000001677 15107326342 0012046 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final class UsesFunction { /** * @psalm-var non-empty-string */ private readonly string $functionName; /** * @psalm-param non-empty-string $functionName */ public function __construct(string $functionName) { $this->functionName = $functionName; } /** * @psalm-return non-empty-string */ public function functionName(): string { return $this->functionName; } } Attributes/Ticket.php 0000644 00000001634 15107326342 0010635 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class Ticket { /** * @psalm-var non-empty-string */ private readonly string $text; /** * @psalm-param non-empty-string $text */ public function __construct(string $text) { $this->text = $text; } /** * @psalm-return non-empty-string */ public function text(): string { return $this->text; } } Attributes/PostCondition.php 0000644 00000001003 15107326342 0012174 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD)] final class PostCondition { } Attributes/PreserveGlobalState.php 0000644 00000001366 15107326342 0013331 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class PreserveGlobalState { private readonly bool $enabled; public function __construct(bool $enabled) { $this->enabled = $enabled; } public function enabled(): bool { return $this->enabled; } } Attributes/DependsExternalUsingShallowClone.php 0000644 00000002415 15107326342 0016016 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class DependsExternalUsingShallowClone { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-var non-empty-string */ private readonly string $methodName; /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ public function __construct(string $className, string $methodName) { $this->className = $className; $this->methodName = $methodName; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } } Attributes/CodeCoverageIgnore.php 0000644 00000001155 15107326342 0013102 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5236 */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] final class CodeCoverageIgnore { } Attributes/Group.php 0000644 00000001633 15107326342 0010505 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class Group { /** * @psalm-var non-empty-string */ private readonly string $name; /** * @psalm-param non-empty-string $name */ public function __construct(string $name) { $this->name = $name; } /** * @psalm-return non-empty-string */ public function name(): string { return $this->name; } } Attributes/RunClassInSeparateProcess.php 0000644 00000001016 15107326342 0014451 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS)] final class RunClassInSeparateProcess { } Attributes/DependsOnClass.php 0000644 00000001641 15107326342 0012255 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class DependsOnClass { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-param class-string $className */ public function __construct(string $className) { $this->className = $className; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } } Attributes/DependsExternalUsingDeepClone.php 0000644 00000002412 15107326342 0015257 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class DependsExternalUsingDeepClone { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-var non-empty-string */ private readonly string $methodName; /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ public function __construct(string $className, string $methodName) { $this->className = $className; $this->methodName = $methodName; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } /** * @psalm-return non-empty-string */ public function methodName(): string { return $this->methodName; } } Attributes/RunTestsInSeparateProcesses.php 0000644 00000001020 15107326342 0015031 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS)] final class RunTestsInSeparateProcesses { } Attributes/RequiresSetting.php 0000644 00000002362 15107326342 0012546 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class RequiresSetting { /** * @psalm-var non-empty-string */ private readonly string $setting; /** * @psalm-var non-empty-string */ private readonly string $value; /** * @psalm-param non-empty-string $setting * @psalm-param non-empty-string $value */ public function __construct(string $setting, string $value) { $this->setting = $setting; $this->value = $value; } /** * @psalm-return non-empty-string */ public function setting(): string { return $this->setting; } /** * @psalm-return non-empty-string */ public function value(): string { return $this->value; } } Attributes/Large.php 0000644 00000000772 15107326342 0010446 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS)] final class Large { } Attributes/RunInSeparateProcess.php 0000644 00000001012 15107326342 0013457 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD)] final class RunInSeparateProcess { } Attributes/TestWith.php 0000644 00000001335 15107326342 0011163 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class TestWith { private readonly array $data; public function __construct(array $data) { $this->data = $data; } public function data(): array { return $this->data; } } Attributes/Before.php 0000644 00000000774 15107326342 0010620 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD)] final class Before { } Attributes/Small.php 0000644 00000000772 15107326342 0010464 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS)] final class Small { } Attributes/TestWithJson.php 0000644 00000001610 15107326342 0012011 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class TestWithJson { /** * @psalm-var non-empty-string */ private readonly string $json; /** * @psalm-param non-empty-string $json */ public function __construct(string $json) { $this->json = $json; } /** * @psalm-return non-empty-string */ public function json(): string { return $this->json; } } Attributes/CoversClass.php 0000644 00000001635 15107326342 0011642 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final class CoversClass { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-param class-string $className */ public function __construct(string $className) { $this->className = $className; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } } Attributes/DependsOnClassUsingDeepClone.php 0000644 00000001657 15107326342 0015051 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\Attributes; use Attribute; /** * @psalm-immutable * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class DependsOnClassUsingDeepClone { /** * @psalm-var class-string */ private readonly string $className; /** * @psalm-param class-string $className */ public function __construct(string $className) { $this->className = $className; } /** * @psalm-return class-string */ public function className(): string { return $this->className; } } SelfDescribing.php 0000644 00000001007 15107326342 0010141 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ interface SelfDescribing { /** * Returns a string representation of the object. */ public function toString(): string; } TestRunner.php 0000644 00000037545 15107326342 0007407 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use const PHP_EOL; use function assert; use function class_exists; use function defined; use function extension_loaded; use function get_include_path; use function hrtime; use function serialize; use function sprintf; use function sys_get_temp_dir; use function tempnam; use function unlink; use function var_export; use AssertionError; use PHPUnit\Event; use PHPUnit\Event\NoPreviousThrowableException; use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException; use PHPUnit\Event\TestData\NoDataSetFromDataProviderException; use PHPUnit\Metadata\Api\CodeCoverage as CodeCoverageMetadataApi; use PHPUnit\Metadata\Parser\Registry as MetadataRegistry; use PHPUnit\Runner\CodeCoverage; use PHPUnit\Runner\ErrorHandler; use PHPUnit\TextUI\Configuration\Configuration; use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry; use PHPUnit\Util\GlobalState; use PHPUnit\Util\PHP\AbstractPhpProcess; use ReflectionClass; use SebastianBergmann\CodeCoverage\Exception as OriginalCodeCoverageException; use SebastianBergmann\CodeCoverage\StaticAnalysisCacheNotConfiguredException; use SebastianBergmann\CodeCoverage\UnintentionallyCoveredCodeException; use SebastianBergmann\Invoker\Invoker; use SebastianBergmann\Invoker\TimeoutException; use SebastianBergmann\Template\Template; use Throwable; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class TestRunner { private ?bool $timeLimitCanBeEnforced = null; private readonly Configuration $configuration; public function __construct() { $this->configuration = ConfigurationRegistry::get(); } /** * @throws \PHPUnit\Runner\Exception * @throws \SebastianBergmann\CodeCoverage\InvalidArgumentException * @throws CodeCoverageException * @throws MoreThanOneDataSetFromDataProviderException * @throws NoDataSetFromDataProviderException * @throws UnintentionallyCoveredCodeException */ public function run(TestCase $test): void { Assert::resetCount(); if ($this->configuration->registerMockObjectsFromTestArgumentsRecursively()) { $test->registerMockObjectsFromTestArgumentsRecursively(); } $shouldCodeCoverageBeCollected = (new CodeCoverageMetadataApi)->shouldCodeCoverageBeCollectedFor( $test::class, $test->name(), ); $error = false; $failure = false; $incomplete = false; $risky = false; $skipped = false; if ($this->shouldErrorHandlerBeUsed($test)) { ErrorHandler::instance()->enable(); } $collectCodeCoverage = CodeCoverage::instance()->isActive() && $shouldCodeCoverageBeCollected; if ($collectCodeCoverage) { CodeCoverage::instance()->start($test); } try { if ($this->canTimeLimitBeEnforced() && $this->shouldTimeLimitBeEnforced($test)) { $risky = $this->runTestWithTimeout($test); } else { $test->runBare(); } } catch (AssertionFailedError $e) { $failure = true; if ($e instanceof IncompleteTestError) { $incomplete = true; } elseif ($e instanceof SkippedTest) { $skipped = true; } } catch (AssertionError $e) { $test->addToAssertionCount(1); $failure = true; $frame = $e->getTrace()[0]; assert(isset($frame['file'])); assert(isset($frame['line'])); $e = new AssertionFailedError( sprintf( '%s in %s:%s', $e->getMessage(), $frame['file'], $frame['line'], ), ); } catch (Throwable $e) { $error = true; } $test->addToAssertionCount(Assert::getCount()); if ($this->configuration->reportUselessTests() && !$test->doesNotPerformAssertions() && $test->numberOfAssertionsPerformed() === 0) { $risky = true; } if (!$error && !$failure && !$incomplete && !$skipped && !$risky && $this->configuration->requireCoverageMetadata() && !$this->hasCoverageMetadata($test::class, $test->name())) { Event\Facade::emitter()->testConsideredRisky( $test->valueObjectForEvents(), 'This test does not define a code coverage target but is expected to do so', ); $risky = true; } if ($collectCodeCoverage) { $append = !$risky && !$incomplete && !$skipped; $linesToBeCovered = []; $linesToBeUsed = []; if ($append) { try { $linesToBeCovered = (new CodeCoverageMetadataApi)->linesToBeCovered( $test::class, $test->name(), ); $linesToBeUsed = (new CodeCoverageMetadataApi)->linesToBeUsed( $test::class, $test->name(), ); } catch (InvalidCoversTargetException $cce) { Event\Facade::emitter()->testTriggeredPhpunitWarning( $test->valueObjectForEvents(), $cce->getMessage(), ); } } try { CodeCoverage::instance()->stop( $append, $linesToBeCovered, $linesToBeUsed, ); } catch (UnintentionallyCoveredCodeException $cce) { Event\Facade::emitter()->testConsideredRisky( $test->valueObjectForEvents(), 'This test executed code that is not listed as code to be covered or used:' . PHP_EOL . $cce->getMessage(), ); } catch (OriginalCodeCoverageException $cce) { $error = true; $e = $e ?? $cce; } } ErrorHandler::instance()->disable(); if (!$error && !$incomplete && !$skipped && $this->configuration->reportUselessTests() && !$test->doesNotPerformAssertions() && $test->numberOfAssertionsPerformed() === 0) { Event\Facade::emitter()->testConsideredRisky( $test->valueObjectForEvents(), 'This test did not perform any assertions', ); } if ($test->doesNotPerformAssertions() && $test->numberOfAssertionsPerformed() > 0) { Event\Facade::emitter()->testConsideredRisky( $test->valueObjectForEvents(), sprintf( 'This test is not expected to perform assertions but performed %d assertion%s', $test->numberOfAssertionsPerformed(), $test->numberOfAssertionsPerformed() > 1 ? 's' : '', ), ); } if ($test->hasUnexpectedOutput()) { Event\Facade::emitter()->testPrintedUnexpectedOutput($test->output()); } if ($this->configuration->disallowTestOutput() && $test->hasUnexpectedOutput()) { Event\Facade::emitter()->testConsideredRisky( $test->valueObjectForEvents(), sprintf( 'This test printed output: %s', $test->output(), ), ); } if ($test->wasPrepared()) { Event\Facade::emitter()->testFinished( $test->valueObjectForEvents(), $test->numberOfAssertionsPerformed(), ); } } /** * @throws \PHPUnit\Runner\Exception * @throws \PHPUnit\Util\Exception * @throws \SebastianBergmann\Template\InvalidArgumentException * @throws Exception * @throws MoreThanOneDataSetFromDataProviderException * @throws NoPreviousThrowableException * @throws ProcessIsolationException * @throws StaticAnalysisCacheNotConfiguredException */ public function runInSeparateProcess(TestCase $test, bool $runEntireClass, bool $preserveGlobalState): void { $class = new ReflectionClass($test); if ($runEntireClass) { $template = new Template( __DIR__ . '/../Util/PHP/Template/TestCaseClass.tpl', ); } else { $template = new Template( __DIR__ . '/../Util/PHP/Template/TestCaseMethod.tpl', ); } $bootstrap = ''; $constants = ''; $globals = ''; $includedFiles = ''; $iniSettings = ''; if (ConfigurationRegistry::get()->hasBootstrap()) { $bootstrap = ConfigurationRegistry::get()->bootstrap(); } if ($preserveGlobalState) { $constants = GlobalState::getConstantsAsString(); $globals = GlobalState::getGlobalsAsString(); $includedFiles = GlobalState::getIncludedFilesAsString(); $iniSettings = GlobalState::getIniSettingsAsString(); } $exportObjects = Event\Facade::emitter()->exportsObjects() ? 'true' : 'false'; $coverage = CodeCoverage::instance()->isActive() ? 'true' : 'false'; $linesToBeIgnored = var_export(CodeCoverage::instance()->linesToBeIgnored(), true); if (defined('PHPUNIT_COMPOSER_INSTALL')) { $composerAutoload = var_export(PHPUNIT_COMPOSER_INSTALL, true); } else { $composerAutoload = '\'\''; } if (defined('__PHPUNIT_PHAR__')) { $phar = var_export(__PHPUNIT_PHAR__, true); } else { $phar = '\'\''; } $data = var_export(serialize($test->providedData()), true); $dataName = var_export($test->dataName(), true); $dependencyInput = var_export(serialize($test->dependencyInput()), true); $includePath = var_export(get_include_path(), true); // must do these fixes because TestCaseMethod.tpl has unserialize('{data}') in it, and we can't break BC // the lines above used to use addcslashes() rather than var_export(), which breaks null byte escape sequences $data = "'." . $data . ".'"; $dataName = "'.(" . $dataName . ").'"; $dependencyInput = "'." . $dependencyInput . ".'"; $includePath = "'." . $includePath . ".'"; $offset = hrtime(); $serializedConfiguration = $this->saveConfigurationForChildProcess(); $processResultFile = tempnam(sys_get_temp_dir(), 'phpunit_'); $var = [ 'bootstrap' => $bootstrap, 'composerAutoload' => $composerAutoload, 'phar' => $phar, 'filename' => $class->getFileName(), 'className' => $class->getName(), 'collectCodeCoverageInformation' => $coverage, 'linesToBeIgnored' => $linesToBeIgnored, 'data' => $data, 'dataName' => $dataName, 'dependencyInput' => $dependencyInput, 'constants' => $constants, 'globals' => $globals, 'include_path' => $includePath, 'included_files' => $includedFiles, 'iniSettings' => $iniSettings, 'name' => $test->name(), 'offsetSeconds' => $offset[0], 'offsetNanoseconds' => $offset[1], 'serializedConfiguration' => $serializedConfiguration, 'processResultFile' => $processResultFile, 'exportObjects' => $exportObjects, ]; if (!$runEntireClass) { $var['methodName'] = $test->name(); } $template->setVar($var); $php = AbstractPhpProcess::factory(); $php->runTestJob($template->render(), $test, $processResultFile); @unlink($serializedConfiguration); } /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName */ private function hasCoverageMetadata(string $className, string $methodName): bool { $metadata = MetadataRegistry::parser()->forClassAndMethod($className, $methodName); if ($metadata->isCovers()->isNotEmpty()) { return true; } if ($metadata->isCoversClass()->isNotEmpty()) { return true; } if ($metadata->isCoversFunction()->isNotEmpty()) { return true; } if ($metadata->isCoversNothing()->isNotEmpty()) { return true; } return false; } private function canTimeLimitBeEnforced(): bool { if ($this->timeLimitCanBeEnforced !== null) { return $this->timeLimitCanBeEnforced; } if (!class_exists(Invoker::class)) { $this->timeLimitCanBeEnforced = false; return $this->timeLimitCanBeEnforced; } $this->timeLimitCanBeEnforced = (new Invoker)->canInvokeWithTimeout(); return $this->timeLimitCanBeEnforced; } private function shouldTimeLimitBeEnforced(TestCase $test): bool { if (!$this->configuration->enforceTimeLimit()) { return false; } if (!(($this->configuration->defaultTimeLimit() || $test->size()->isKnown()))) { return false; } if (extension_loaded('xdebug') && xdebug_is_debugger_active()) { return false; } return true; } /** * @throws Throwable */ private function runTestWithTimeout(TestCase $test): bool { $_timeout = $this->configuration->defaultTimeLimit(); if ($test->size()->isSmall()) { $_timeout = $this->configuration->timeoutForSmallTests(); } elseif ($test->size()->isMedium()) { $_timeout = $this->configuration->timeoutForMediumTests(); } elseif ($test->size()->isLarge()) { $_timeout = $this->configuration->timeoutForLargeTests(); } try { (new Invoker)->invoke([$test, 'runBare'], [], $_timeout); } catch (TimeoutException) { Event\Facade::emitter()->testConsideredRisky( $test->valueObjectForEvents(), sprintf( 'This test was aborted after %d second%s', $_timeout, $_timeout !== 1 ? 's' : '', ), ); return true; } return false; } /** * @throws ProcessIsolationException */ private function saveConfigurationForChildProcess(): string { $path = tempnam(sys_get_temp_dir(), 'phpunit_'); if (!$path) { throw new ProcessIsolationException; } if (!ConfigurationRegistry::saveTo($path)) { throw new ProcessIsolationException; } return $path; } private function shouldErrorHandlerBeUsed(TestCase $test): bool { if (MetadataRegistry::parser()->forMethod($test::class, $test->name())->isWithoutErrorHandler()->isNotEmpty()) { return false; } return true; } } TestSuite.php 0000644 00000044351 15107326342 0007220 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use const PHP_EOL; use function array_keys; use function array_map; use function assert; use function call_user_func; use function class_exists; use function count; use function implode; use function is_callable; use function is_file; use function is_subclass_of; use function sprintf; use function str_ends_with; use function str_starts_with; use function trim; use Iterator; use IteratorAggregate; use PHPUnit\Event; use PHPUnit\Event\Code\TestMethod; use PHPUnit\Event\NoPreviousThrowableException; use PHPUnit\Metadata\Api\Dependencies; use PHPUnit\Metadata\Api\Groups; use PHPUnit\Metadata\Api\HookMethods; use PHPUnit\Metadata\Api\Requirements; use PHPUnit\Metadata\MetadataCollection; use PHPUnit\Runner\Exception as RunnerException; use PHPUnit\Runner\Filter\Factory; use PHPUnit\Runner\PhptTestCase; use PHPUnit\Runner\TestSuiteLoader; use PHPUnit\TestRunner\TestResult\Facade as TestResultFacade; use PHPUnit\Util\Filter; use PHPUnit\Util\Reflection; use PHPUnit\Util\Test as TestUtil; use ReflectionClass; use ReflectionMethod; use SebastianBergmann\CodeCoverage\UnintentionallyCoveredCodeException; use Throwable; /** * @template-implements IteratorAggregate<int, Test> * * @internal This class is not covered by the backward compatibility promise for PHPUnit */ class TestSuite implements IteratorAggregate, Reorderable, SelfDescribing, Test { /** * @psalm-var non-empty-string */ private string $name; /** * @psalm-var array<string,list<Test>> */ private array $groups = []; private ?array $requiredTests = null; /** * @psalm-var list<Test> */ private array $tests = []; private ?array $providedTests = null; private ?Factory $iteratorFilter = null; /** * @psalm-param non-empty-string $name */ public static function empty(string $name): static { return new static($name); } /** * @psalm-param class-string $className */ public static function fromClassName(string $className): static { assert(class_exists($className)); $class = new ReflectionClass($className); return static::fromClassReflector($class); } public static function fromClassReflector(ReflectionClass $class): static { $testSuite = new static($class->getName()); $constructor = $class->getConstructor(); if ($constructor !== null && !$constructor->isPublic()) { Event\Facade::emitter()->testRunnerTriggeredWarning( sprintf( 'Class "%s" has no public constructor.', $class->getName(), ), ); return $testSuite; } foreach (Reflection::publicMethodsInTestClass($class) as $method) { if ($method->getDeclaringClass()->getName() === Assert::class) { continue; } if ($method->getDeclaringClass()->getName() === TestCase::class) { continue; } if (!TestUtil::isTestMethod($method)) { continue; } $testSuite->addTestMethod($class, $method); } if (count($testSuite) === 0) { Event\Facade::emitter()->testRunnerTriggeredWarning( sprintf( 'No tests found in class "%s".', $class->getName(), ), ); } return $testSuite; } /** * @psalm-param non-empty-string $name */ final private function __construct(string $name) { $this->name = $name; } /** * Returns a string representation of the test suite. */ public function toString(): string { return $this->name(); } /** * Adds a test to the suite. */ public function addTest(Test $test, array $groups = []): void { $class = new ReflectionClass($test); if (!$class->isAbstract()) { $this->tests[] = $test; $this->clearCaches(); if ($test instanceof self && empty($groups)) { $groups = $test->groups(); } if ($this->containsOnlyVirtualGroups($groups)) { $groups[] = 'default'; } foreach ($groups as $group) { if (!isset($this->groups[$group])) { $this->groups[$group] = [$test]; } else { $this->groups[$group][] = $test; } } if ($test instanceof TestCase) { $test->setGroups($groups); } } } /** * Adds the tests from the given class to the suite. * * @throws Exception */ public function addTestSuite(ReflectionClass $testClass): void { if ($testClass->isAbstract()) { throw new Exception( sprintf( 'Class %s is abstract', $testClass->getName(), ), ); } if (!$testClass->isSubclassOf(TestCase::class)) { throw new Exception( sprintf( 'Class %s is not a subclass of %s', $testClass->getName(), TestCase::class, ), ); } $this->addTest(self::fromClassReflector($testClass)); } /** * Wraps both <code>addTest()</code> and <code>addTestSuite</code> * as well as the separate import statements for the user's convenience. * * If the named file cannot be read or there are no new tests that can be * added, a <code>PHPUnit\Framework\WarningTestCase</code> will be created instead, * leaving the current test run untouched. * * @throws Exception */ public function addTestFile(string $filename): void { if (is_file($filename) && str_ends_with($filename, '.phpt')) { try { $this->addTest(new PhptTestCase($filename)); } catch (RunnerException $e) { Event\Facade::emitter()->testRunnerTriggeredWarning( $e->getMessage(), ); } return; } try { $this->addTestSuite( (new TestSuiteLoader)->load($filename), ); } catch (RunnerException $e) { Event\Facade::emitter()->testRunnerTriggeredWarning( $e->getMessage(), ); } } /** * Wrapper for addTestFile() that adds multiple test files. * * @throws Exception */ public function addTestFiles(iterable $fileNames): void { foreach ($fileNames as $filename) { $this->addTestFile((string) $filename); } } /** * Counts the number of test cases that will be run by this test. */ public function count(): int { $numTests = 0; foreach ($this as $test) { $numTests += count($test); } return $numTests; } public function isEmpty(): bool { return empty($this->tests); } /** * @psalm-return non-empty-string */ public function name(): string { return $this->name; } /** * Returns the test groups of the suite. * * @psalm-return list<string> */ public function groups(): array { return array_map( 'strval', array_keys($this->groups), ); } public function groupDetails(): array { return $this->groups; } /** * @throws \SebastianBergmann\CodeCoverage\InvalidArgumentException * @throws CodeCoverageException * @throws Event\RuntimeException * @throws Exception * @throws NoPreviousThrowableException * @throws UnintentionallyCoveredCodeException */ public function run(): void { if (count($this) === 0) { return; } $emitter = Event\Facade::emitter(); $testSuiteValueObjectForEvents = Event\TestSuite\TestSuiteBuilder::from($this); $emitter->testSuiteStarted($testSuiteValueObjectForEvents); if (!$this->invokeMethodsBeforeFirstTest($emitter, $testSuiteValueObjectForEvents)) { return; } foreach ($this as $test) { if (TestResultFacade::shouldStop()) { $emitter->testRunnerExecutionAborted(); break; } $test->run(); } $this->invokeMethodsAfterLastTest($emitter); $emitter->testSuiteFinished($testSuiteValueObjectForEvents); } /** * Returns the tests as an enumeration. * * @psalm-return list<Test> */ public function tests(): array { return $this->tests; } /** * Set tests of the test suite. * * @psalm-param list<Test> $tests */ public function setTests(array $tests): void { $this->tests = $tests; } /** * Mark the test suite as skipped. * * @throws SkippedTestSuiteError */ public function markTestSuiteSkipped(string $message = ''): never { throw new SkippedTestSuiteError($message); } /** * Returns an iterator for this test suite. */ public function getIterator(): Iterator { $iterator = new TestSuiteIterator($this); if ($this->iteratorFilter !== null) { $iterator = $this->iteratorFilter->factory($iterator, $this); } return $iterator; } public function injectFilter(Factory $filter): void { $this->iteratorFilter = $filter; foreach ($this as $test) { if ($test instanceof self) { $test->injectFilter($filter); } } } /** * @psalm-return list<ExecutionOrderDependency> */ public function provides(): array { if ($this->providedTests === null) { $this->providedTests = []; if (is_callable($this->sortId(), true)) { $this->providedTests[] = new ExecutionOrderDependency($this->sortId()); } foreach ($this->tests as $test) { if (!($test instanceof Reorderable)) { continue; } $this->providedTests = ExecutionOrderDependency::mergeUnique($this->providedTests, $test->provides()); } } return $this->providedTests; } /** * @psalm-return list<ExecutionOrderDependency> */ public function requires(): array { if ($this->requiredTests === null) { $this->requiredTests = []; foreach ($this->tests as $test) { if (!($test instanceof Reorderable)) { continue; } $this->requiredTests = ExecutionOrderDependency::mergeUnique( ExecutionOrderDependency::filterInvalid($this->requiredTests), $test->requires(), ); } $this->requiredTests = ExecutionOrderDependency::diff($this->requiredTests, $this->provides()); } return $this->requiredTests; } public function sortId(): string { return $this->name() . '::class'; } /** * @psalm-assert-if-true class-string $this->name */ public function isForTestClass(): bool { return class_exists($this->name, false) && is_subclass_of($this->name, TestCase::class); } /** * @throws \PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException * @throws Exception */ protected function addTestMethod(ReflectionClass $class, ReflectionMethod $method): void { $className = $class->getName(); $methodName = $method->getName(); assert(!empty($methodName)); try { $test = (new TestBuilder)->build($class, $methodName); } catch (InvalidDataProviderException $e) { Event\Facade::emitter()->testTriggeredPhpunitError( new TestMethod( $className, $methodName, $class->getFileName(), $method->getStartLine(), Event\Code\TestDoxBuilder::fromClassNameAndMethodName( $className, $methodName, ), MetadataCollection::fromArray([]), Event\TestData\TestDataCollection::fromArray([]), ), sprintf( "The data provider specified for %s::%s is invalid\n%s", $className, $methodName, $this->throwableToString($e), ), ); return; } if ($test instanceof TestCase || $test instanceof DataProviderTestSuite) { $test->setDependencies( Dependencies::dependencies($class->getName(), $methodName), ); } $this->addTest( $test, (new Groups)->groups($class->getName(), $methodName), ); } private function clearCaches(): void { $this->providedTests = null; $this->requiredTests = null; } private function containsOnlyVirtualGroups(array $groups): bool { foreach ($groups as $group) { if (!str_starts_with($group, '__phpunit_')) { return false; } } return true; } private function methodDoesNotExistOrIsDeclaredInTestCase(string $methodName): bool { $reflector = new ReflectionClass($this->name); return !$reflector->hasMethod($methodName) || $reflector->getMethod($methodName)->getDeclaringClass()->getName() === TestCase::class; } /** * @throws Exception */ private function throwableToString(Throwable $t): string { $message = $t->getMessage(); if (empty(trim($message))) { $message = '<no message>'; } if ($t instanceof InvalidDataProviderException) { return sprintf( "%s\n%s", $message, Filter::getFilteredStacktrace($t), ); } return sprintf( "%s: %s\n%s", $t::class, $message, Filter::getFilteredStacktrace($t), ); } /** * @throws Exception * @throws NoPreviousThrowableException */ private function invokeMethodsBeforeFirstTest(Event\Emitter $emitter, Event\TestSuite\TestSuite $testSuiteValueObjectForEvents): bool { if (!$this->isForTestClass()) { return true; } $methodsCalledBeforeFirstTest = []; $beforeClassMethods = (new HookMethods)->hookMethods($this->name)['beforeClass']; try { foreach ($beforeClassMethods as $beforeClassMethod) { if ($this->methodDoesNotExistOrIsDeclaredInTestCase($beforeClassMethod)) { continue; } if ($missingRequirements = (new Requirements)->requirementsNotSatisfiedFor($this->name, $beforeClassMethod)) { $this->markTestSuiteSkipped(implode(PHP_EOL, $missingRequirements)); } $methodCalledBeforeFirstTest = new Event\Code\ClassMethod( $this->name, $beforeClassMethod, ); $emitter->testBeforeFirstTestMethodCalled( $this->name, $methodCalledBeforeFirstTest, ); $methodsCalledBeforeFirstTest[] = $methodCalledBeforeFirstTest; call_user_func([$this->name, $beforeClassMethod]); } } catch (SkippedTest|SkippedTestSuiteError $e) { $emitter->testSuiteSkipped( $testSuiteValueObjectForEvents, $e->getMessage(), ); return false; } catch (Throwable $t) { assert(isset($methodCalledBeforeFirstTest)); $emitter->testBeforeFirstTestMethodErrored( $this->name, $methodCalledBeforeFirstTest, Event\Code\ThrowableBuilder::from($t), ); if (!empty($methodsCalledBeforeFirstTest)) { $emitter->testBeforeFirstTestMethodFinished( $this->name, ...$methodsCalledBeforeFirstTest, ); } return false; } if (!empty($methodsCalledBeforeFirstTest)) { $emitter->testBeforeFirstTestMethodFinished( $this->name, ...$methodsCalledBeforeFirstTest, ); } return true; } private function invokeMethodsAfterLastTest(Event\Emitter $emitter): void { if (!$this->isForTestClass()) { return; } $methodsCalledAfterLastTest = []; $afterClassMethods = (new HookMethods)->hookMethods($this->name)['afterClass']; foreach ($afterClassMethods as $afterClassMethod) { if ($this->methodDoesNotExistOrIsDeclaredInTestCase($afterClassMethod)) { continue; } try { call_user_func([$this->name, $afterClassMethod]); $methodCalledAfterLastTest = new Event\Code\ClassMethod( $this->name, $afterClassMethod, ); $emitter->testAfterLastTestMethodCalled( $this->name, $methodCalledAfterLastTest, ); $methodsCalledAfterLastTest[] = $methodCalledAfterLastTest; } catch (Throwable) { // @todo } } if (!empty($methodsCalledAfterLastTest)) { $emitter->testAfterLastTestMethodFinished( $this->name, ...$methodsCalledAfterLastTest, ); } } } ExecutionOrderDependency.php 0000644 00000011375 15107326342 0012225 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of PHPUnit. * * (c) Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework; use function array_filter; use function array_map; use function array_values; use function explode; use function in_array; use function str_contains; use PHPUnit\Metadata\DependsOnClass; use PHPUnit\Metadata\DependsOnMethod; use Stringable; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final class ExecutionOrderDependency implements Stringable { private string $className = ''; private string $methodName = ''; private readonly bool $shallowClone; private readonly bool $deepClone; public static function invalid(): self { return new self( '', '', false, false, ); } public static function forClass(DependsOnClass $metadata): self { return new self( $metadata->className(), 'class', $metadata->deepClone(), $metadata->shallowClone(), ); } public static function forMethod(DependsOnMethod $metadata): self { return new self( $metadata->className(), $metadata->methodName(), $metadata->deepClone(), $metadata->shallowClone(), ); } /** * @psalm-param list<ExecutionOrderDependency> $dependencies * * @psalm-return list<ExecutionOrderDependency> */ public static function filterInvalid(array $dependencies): array { return array_values( array_filter( $dependencies, static fn (self $d) => $d->isValid(), ), ); } /** * @psalm-param list<ExecutionOrderDependency> $existing * @psalm-param list<ExecutionOrderDependency> $additional * * @psalm-return list<ExecutionOrderDependency> */ public static function mergeUnique(array $existing, array $additional): array { $existingTargets = array_map( static fn ($dependency) => $dependency->getTarget(), $existing, ); foreach ($additional as $dependency) { if (in_array($dependency->getTarget(), $existingTargets, true)) { continue; } $existingTargets[] = $dependency->getTarget(); $existing[] = $dependency; } return $existing; } /** * @psalm-param list<ExecutionOrderDependency> $left * @psalm-param list<ExecutionOrderDependency> $right * * @psalm-return list<ExecutionOrderDependency> */ public static function diff(array $left, array $right): array { if ($right === []) { return $left; } if ($left === []) { return []; } $diff = []; $rightTargets = array_map( static fn ($dependency) => $dependency->getTarget(), $right, ); foreach ($left as $dependency) { if (in_array($dependency->getTarget(), $rightTargets, true)) { continue; } $diff[] = $dependency; } return $diff; } public function __construct(string $classOrCallableName, ?string $methodName = null, bool $deepClone = false, bool $shallowClone = false) { if ($classOrCallableName === '') { return; } if (str_contains($classOrCallableName, '::')) { [$this->className, $this->methodName] = explode('::', $classOrCallableName); } else { $this->className = $classOrCallableName; $this->methodName = !empty($methodName) ? $methodName : 'class'; } $this->deepClone = $deepClone; $this->shallowClone = $shallowClone; } public function __toString(): string { return $this->getTarget(); } public function isValid(): bool { // Invalid dependencies can be declared and are skipped by the runner return $this->className !== '' && $this->methodName !== ''; } public function shallowClone(): bool { return $this->shallowClone; } public function deepClone(): bool { return $this->deepClone; } public function targetIsClass(): bool { return $this->methodName === 'class'; } public function getTarget(): string { return $this->isValid() ? $this->className . '::' . $this->methodName : ''; } public function getTargetClassName(): string { return $this->className; } }