|
14 | 14 |
|
15 | 15 | namespace Humbug\PhpScoper\Scoper; |
16 | 16 |
|
| 17 | +use function array_filter; |
| 18 | +use function array_slice; |
| 19 | +use function array_values; |
17 | 20 | use Error; |
| 21 | +use function explode; |
18 | 22 | use Generator; |
19 | 23 | use Humbug\PhpScoper\PhpParser\TraverserFactory; |
20 | 24 | use Humbug\PhpScoper\Reflector; |
21 | 25 | use Humbug\PhpScoper\Scoper; |
22 | 26 | use Humbug\PhpScoper\Whitelist; |
| 27 | +use PhpParser\Error as PhpParserError; |
23 | 28 | use PHPUnit\Framework\TestCase; |
24 | 29 | use Roave\BetterReflection\BetterReflection; |
25 | 30 | use Roave\BetterReflection\Reflector\ClassReflector; |
26 | 31 | use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator; |
27 | 32 | use Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator; |
28 | 33 | use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; |
| 34 | +use function strpos; |
29 | 35 | use Symfony\Component\Finder\Finder; |
30 | 36 | use Symfony\Component\Finder\SplFileInfo; |
31 | 37 | use Throwable; |
@@ -112,6 +118,34 @@ public function test_can_scope_valid_files( |
112 | 118 | $this->assertTrue(true); |
113 | 119 |
|
114 | 120 | return; |
| 121 | + } catch (PhpParserError $error) { |
| 122 | + if (0 !== strpos($error->getMessage(), 'Syntax error,')) { |
| 123 | + throw new Error( |
| 124 | + sprintf( |
| 125 | + 'Could not parse the spec %s: %s', |
| 126 | + $spec, |
| 127 | + $error->getMessage() |
| 128 | + ), |
| 129 | + 0, |
| 130 | + $error |
| 131 | + ); |
| 132 | + } |
| 133 | + |
| 134 | + $lines = array_values(array_filter(explode("\n", $contents))); |
| 135 | + |
| 136 | + $startLine = $error->getAttributes()['startLine'] - 1; |
| 137 | + $endLine = $error->getAttributes()['endLine'] + 1; |
| 138 | + |
| 139 | + $this->fail( |
| 140 | + sprintf( |
| 141 | + 'Unexpected parse error found in the following lines: %s%s', |
| 142 | + "\n\n> ", |
| 143 | + implode( |
| 144 | + "\n> ", |
| 145 | + array_slice($lines, $startLine, $endLine - $startLine + 1) |
| 146 | + ) |
| 147 | + ) |
| 148 | + ); |
115 | 149 | } catch (Throwable $throwable) { |
116 | 150 | throw new Error( |
117 | 151 | sprintf( |
|
0 commit comments