|
2 | 2 | <?php |
3 | 3 |
|
4 | 4 | use Eloquent\Asplode\Asplode; |
| 5 | +use Eloquent\Phony\Assertion\Exception\AssertionException; |
5 | 6 | use Eloquent\Phony\Hook\FunctionHookGenerator; |
6 | 7 | use Eloquent\Phony\Mock\Builder\MockBuilderFactory; |
7 | 8 | use Eloquent\Phony\Reflection\FeatureDetector; |
8 | 9 | use Eloquent\Phony\Reflection\FunctionSignatureInspector; |
| 10 | +use Eloquent\Phony\Test\Phony as TestPhony; |
9 | 11 |
|
10 | 12 | $rootPath = dirname(__DIR__); |
11 | 13 | require $rootPath . '/vendor/autoload.php'; |
@@ -74,3 +76,77 @@ foreach (scandir($hookGeneratorFixturePath) as $name) { |
74 | 76 | "<?php\n\n" . $source |
75 | 77 | ); |
76 | 78 | } |
| 79 | + |
| 80 | +$verificationFixturePath = $fixturePath . '/verification'; |
| 81 | + |
| 82 | +function visualizeAnsi($data) |
| 83 | +{ |
| 84 | + return preg_replace_callback( |
| 85 | + '/(\x9B|\x1B\[)([0-?]*[ -\/]*[@-~])/', |
| 86 | + function ($matches) { |
| 87 | + if ("\033[" !== $matches[1]) { |
| 88 | + throw new RuntimeException('Unexpected ANSI sequence.'); |
| 89 | + } |
| 90 | + |
| 91 | + switch ($matches[2]) { |
| 92 | + case '0m': return '%RESET%'; |
| 93 | + case '1m': return '%BOLD%'; |
| 94 | + case '2m': return '%FAINT%'; |
| 95 | + |
| 96 | + case '31m': return '%RED%'; |
| 97 | + case '32m': return '%GREEN%'; |
| 98 | + case '33m': return '%YELLOW%'; |
| 99 | + case '36m': return '%CYAN%'; |
| 100 | + } |
| 101 | + |
| 102 | + throw new RuntimeException( |
| 103 | + sprintf( |
| 104 | + 'Unexpected ANSI code %s.', |
| 105 | + var_export($matches[2], true) |
| 106 | + ) |
| 107 | + ); |
| 108 | + }, |
| 109 | + $data |
| 110 | + ); |
| 111 | +} |
| 112 | + |
| 113 | +foreach (scandir($verificationFixturePath) as $group) { |
| 114 | + if ('.' === $group[0]) { |
| 115 | + continue; |
| 116 | + } |
| 117 | + |
| 118 | + $groupPath = $verificationFixturePath . '/' . $group; |
| 119 | + |
| 120 | + foreach (scandir($groupPath) as $name) { |
| 121 | + if ('.' === $name[0]) { |
| 122 | + continue; |
| 123 | + } |
| 124 | + |
| 125 | + $thisPath = $groupPath . '/' . $name; |
| 126 | + $supportedPath = $thisPath . '/supported.php'; |
| 127 | + |
| 128 | + if (is_file($supportedPath)) { |
| 129 | + $isSupported = require $supportedPath; |
| 130 | + |
| 131 | + if (!$isSupported) { |
| 132 | + continue; |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + try { |
| 137 | + require $thisPath . '/verification.php'; |
| 138 | + |
| 139 | + throw new RuntimeException( |
| 140 | + 'Verification did not throw an exception.' |
| 141 | + ); |
| 142 | + } catch (AssertionException $e) { |
| 143 | + } |
| 144 | + |
| 145 | + file_put_contents( |
| 146 | + $thisPath . '/expected', |
| 147 | + visualizeAnsi($e->getMessage()) . "\n" |
| 148 | + ); |
| 149 | + |
| 150 | + TestPhony::reset(); |
| 151 | + } |
| 152 | +} |
0 commit comments