diff --git a/tests/Scoper/PhpScoperSpecTest.php b/tests/Scoper/PhpScoperSpecTest.php index 33d2f3b8..77acec6b 100644 --- a/tests/Scoper/PhpScoperSpecTest.php +++ b/tests/Scoper/PhpScoperSpecTest.php @@ -14,7 +14,6 @@ namespace Humbug\PhpScoper\Scoper; -use Error; use Humbug\PhpScoper\Configuration\SymbolsConfiguration; use Humbug\PhpScoper\Container; use Humbug\PhpScoper\PhpParser\TraverserFactory; @@ -22,6 +21,7 @@ use Humbug\PhpScoper\Scoper\Spec\SpecFormatter; use Humbug\PhpScoper\Scoper\Spec\SpecNormalizer; use Humbug\PhpScoper\Scoper\Spec\SpecParser; +use Humbug\PhpScoper\Scoper\Spec\UnparsableSpec; use Humbug\PhpScoper\Symbol\EnrichedReflector; use Humbug\PhpScoper\Symbol\Reflector; use Humbug\PhpScoper\Symbol\SymbolsRegistry; @@ -109,15 +109,7 @@ public function test_can_scope_valid_files( $error, ); } catch (Throwable $throwable) { - throw new Error( - sprintf( - 'Could not parse the spec %s: %s', - $spec, - $throwable->getMessage().$throwable->getTraceAsString(), - ), - 0, - $throwable, - ); + throw UnparsableSpec::create($spec, $throwable); } $specMessage = SpecFormatter::createSpecMessage( @@ -204,15 +196,7 @@ private static function handlePhpParserError( PhpParserError $error, ): never { if (!str_starts_with($error->getMessage(), 'Syntax error,')) { - throw new Error( - sprintf( - 'Could not parse the spec %s: %s', - $spec, - $error->getMessage(), - ), - 0, - $error, - ); + throw UnparsableSpec::create($spec, $error); } $lines = array_values(array_filter(explode("\n", $contents))); diff --git a/tests/Scoper/Spec/UnparsableSpec.php b/tests/Scoper/Spec/UnparsableSpec.php new file mode 100644 index 00000000..0ccb8008 --- /dev/null +++ b/tests/Scoper/Spec/UnparsableSpec.php @@ -0,0 +1,36 @@ +, + * Pádraic Brady + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Humbug\PhpScoper\Scoper\Spec; + +use DomainException; +use Throwable; +use function sprintf; + +final class UnparsableSpec extends DomainException +{ + public static function create( + string $specTitle, + Throwable $throwable, + ): self { + return new self( + sprintf( + 'Could not parse the spec "%s": %s', + $specTitle, + $throwable->getMessage(), + ), + previous: $throwable, + ); + } +}