mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +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.
|
* The expectation value.
|
||||||
*
|
*
|
||||||
|
* @readonly
|
||||||
|
*
|
||||||
* @var mixed
|
* @var mixed
|
||||||
*/
|
*/
|
||||||
private $value;
|
public $value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new expectation.
|
* Creates a new expectation.
|
||||||
|
|||||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Pest;
|
namespace Pest;
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
use SebastianBergmann\Exporter\Exporter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -40,7 +41,8 @@ final class OppositeExpectation
|
|||||||
return $this->original;
|
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;
|
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