mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
feat: improves feedback when test misses description
This commit is contained in:
24
src/Exceptions/TestDescriptionMissing.php
Normal file
24
src/Exceptions/TestDescriptionMissing.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Exceptions;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use NunoMaduro\Collision\Contracts\RenderlessEditor;
|
||||||
|
use NunoMaduro\Collision\Contracts\RenderlessTrace;
|
||||||
|
use Symfony\Component\Console\Exception\ExceptionInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class TestDescriptionMissing extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Creates a new Exception instance.
|
||||||
|
*/
|
||||||
|
public function __construct(string $fileName)
|
||||||
|
{
|
||||||
|
parent::__construct(sprintf('Test misses description in the filename `%s`.', $fileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,6 +8,7 @@ use ParseError;
|
|||||||
use Pest\Concerns;
|
use Pest\Concerns;
|
||||||
use Pest\Contracts\HasPrintableTestCaseName;
|
use Pest\Contracts\HasPrintableTestCaseName;
|
||||||
use Pest\Exceptions\DatasetMissing;
|
use Pest\Exceptions\DatasetMissing;
|
||||||
|
use Pest\Exceptions\TestDescriptionMissing;
|
||||||
use Pest\Exceptions\ShouldNotHappen;
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
use Pest\Exceptions\TestAlreadyExist;
|
use Pest\Exceptions\TestAlreadyExist;
|
||||||
use Pest\Factories\Concerns\HigherOrderable;
|
use Pest\Factories\Concerns\HigherOrderable;
|
||||||
@ -224,7 +225,7 @@ final class TestCaseFactory
|
|||||||
public function addMethod(TestCaseMethodFactory $method): void
|
public function addMethod(TestCaseMethodFactory $method): void
|
||||||
{
|
{
|
||||||
if ($method->description === null) {
|
if ($method->description === null) {
|
||||||
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
|
throw new TestDescriptionMissing($method->filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($method->description, $this->methods)) {
|
if (array_key_exists($method->description, $this->methods)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user