/**
  * Transforms the annoated code in the given file and writes it to the
  * target file.
  *
  * @see LimeLexer#parse($content)
  */
 public function parse($content)
 {
     if (is_readable($content)) {
         $content = file_get_contents($content);
     }
     $lexer = new LimeLexerVariables($this->getAllowedAnnotations(), array('Before'));
     $this->variables = $lexer->parse($content);
     $lexer = new LimeLexerTestVariable();
     $this->testVariable = $lexer->parse($content);
     $this->initialized = false;
     $this->functionCount = 0;
     $this->functions = array();
     $this->classBuffer = '';
     $this->classNotLoaded = false;
     $this->firstAnnotation = true;
     foreach ($this->getAllowedAnnotations() as $annotation) {
         $this->functions[$annotation] = array();
     }
     // backup the contents for the case that the path == filename
     $this->file = fopen($this->fileName, 'w');
     $result = parent::parse($content);
     if ($this->inAnnotation()) {
         fwrite($this->file, "\n}");
     }
     fclose($this->file);
     return $result;
 }
Esempio n. 2
0
 protected function includeTest($__lime_path)
 {
     LimeAnnotationSupport::setScriptPath($__lime_path);
     $lexer = new LimeLexerVariables(array('Test', 'Before', 'After', 'BeforeAll', 'AfterAll'), array('Before'));
     // make global variables _really_ global (in case someone uses "global" statements)
     foreach ($lexer->parse(file_get_contents($__lime_path)) as $__lime_variable) {
         $__lime_variable = substr($__lime_variable, 1);
         // strip '$'
         global ${$__lime_variable};
     }
     return include $__lime_path;
 }
Esempio n. 3
0
<?php
\$a = 0;

// @Annotation
\$b = 1;

// @Annotation
\$c = 1;
EOF
);
// assertions
$expected = array('$a');
$t->is($actual, $expected, 'The correct variables are returned');
$t->diag('Variables in the given included annotations are included');
// fixtures
$l = new LimeLexerVariables(array('Annotation', 'Include'), array('Include'));
// test
$actual = $l->parse(<<<EOF
<?php
\$a = 0;

// @Include
\$b = 1;

// @Annotation
\$c = 1;
EOF
);
// assertions
$expected = array('$a', '$b');
$t->is($actual, $expected, 'The correct variables are returned');