Skip to content

test: Do not hide the original throwable stack trace when failing to parse a file #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions tests/Scoper/PhpScoperSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Humbug\PhpScoper\Container;
use Humbug\PhpScoper\PhpParser\TraverserFactory;
use Humbug\PhpScoper\Scoper\Spec\SpecFinder;
use Humbug\PhpScoper\Scoper\Spec\UnparsableFile;
use Humbug\PhpScoper\Symbol\EnrichedReflector;
use Humbug\PhpScoper\Symbol\NamespaceRegistry;
use Humbug\PhpScoper\Symbol\Reflector;
Expand Down Expand Up @@ -244,13 +245,7 @@ public static function provideValidFiles(): iterable
);
}
} catch (Throwable $throwable) {
self::fail(
sprintf(
'An error occurred while parsing the file "%s": %s',
$file,
$throwable->getMessage(),
),
);
throw UnparsableFile::create($file, $throwable);
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions tests/Scoper/Spec/UnparsableFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <[email protected]>,
* Pádraic Brady <[email protected]>
*
* 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 SplFileInfo;
use Throwable;
use function sprintf;

final class UnparsableFile extends DomainException
{
public static function create(
SplFileInfo $file,
Throwable $throwable,
): self {
return new self(
sprintf(
'An error occurred while parsing the file "%s": %s',
$file,
$throwable->getMessage(),
),
previous: $throwable,
);
}
}