mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
feat(expectation-api): adds failed assertations on not methods
This commit is contained in:
@ -16,9 +16,11 @@ final class Expectation
|
||||
/**
|
||||
* The expectation value.
|
||||
*
|
||||
* @readonly
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $value;
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Creates a new expectation.
|
||||
|
||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Pest;
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -40,7 +41,8 @@ final class OppositeExpectation
|
||||
return $this->original;
|
||||
}
|
||||
|
||||
throw new ExpectationFailedException(sprintf('@todo'));
|
||||
// @phpstan-ignore-next-line
|
||||
$this->throwExpectationFailedExpection($name, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,6 +57,24 @@ final class OppositeExpectation
|
||||
return $this->original;
|
||||
}
|
||||
|
||||
throw new ExpectationFailedException(sprintf('@todo'));
|
||||
// @phpstan-ignore-next-line
|
||||
$this->throwExpectationFailedExpection($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new expectation failed exception
|
||||
* with a nice readable message.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
*/
|
||||
private function throwExpectationFailedExpection(string $name, array $arguments = []): void
|
||||
{
|
||||
$exporter = new Exporter();
|
||||
|
||||
$toString = function ($argument) use ($exporter): string {
|
||||
return $exporter->shortenedExport($argument);
|
||||
};
|
||||
|
||||
throw new ExpectationFailedException(sprintf('Expecting %s not %s %s.', $toString($this->original->value), strtolower((string) preg_replace('/(?<!\ )[A-Z]/', ' $0', $name)), implode(' ', array_map(function ($argument) use ($toString): string { return $toString($argument); }, $arguments))));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user