Example #1
0
 function run()
 {
     $raw = is_readable($this->file) ? file_get_contents($this->file) : '';
     $sections = array_values(array_filter(array_map('trim', preg_split('/^--(TEST|FILE|EXPECTF)--$/m', $raw))));
     if (3 === count($sections)) {
         list($this->name, $this->source, $this->expected) = $sections;
         try {
             $this->out = yay_parse($this->source);
             if (false !== strpos($this->name, '--pretty-print')) {
                 $this->out = yay_pretty($this->out) . PHP_EOL . PHP_EOL . '?>';
             }
         } catch (YayParseError $e) {
             $this->out = $e->getMessage();
             // $this->out = (string) $e;
         } catch (\PhpParser\Error $e) {
             $this->out = 'PHP ' . $e->getMessage();
             // $this->out = (string) $e;
         } catch (Exception $e) {
             $this->out = (string) $e;
         }
         try {
             Assert::assertStringMatchesFormat($this->expected, $this->out);
             $this->status = self::PASSED;
         } catch (Exception $e) {
             $this->status = self::FAILED;
             throw $e;
         }
     } else {
         $this->status = self::BORKED;
     }
 }
Example #2
0
function expand(TokenStream $ts, Context $context) : TokenStream
{
    $ts = TokenStream::fromSource(yay_parse('<?php ' . (string) $ts, $context->get('directives'), $context->get('blueContext')));
    $ts->shift();
    return $ts;
}