コード例 #1
0
 public function testNoLeadingWhitespace()
 {
     $tokenizer = new Tokenizer();
     $file = $tokenizer->tokenize('foo.php', "<?php\n");
     $rule = new MustStartWithOpenTag();
     $rule->visitFile($file);
     $this->assertRuleViolations($file, array());
 }
コード例 #2
0
 public function testTabulators()
 {
     $tokenizer = new Tokenizer();
     $file = $tokenizer->tokenize('foo.php', "<?php\n\t");
     $file->rewind();
     $file->seekTokenType(T_WHITESPACE);
     $rule = new DisallowTabulators();
     $rule->visitToken($file);
     $this->assertRuleViolations($file, array(array('line' => 2, 'column' => 1, 'message' => 'Tabulator found', 'source' => 'Flitch\\Whitespace\\DisallowTabulators')));
 }
コード例 #3
0
ファイル: ConstantsTest.php プロジェクト: dasprid/flitch
 public function testConstantNaming()
 {
     $tokenizer = new Tokenizer();
     $file = $tokenizer->tokenize('foo.php', "<?php class foo { const BAR = 'baz'; const BAZ = 'bar'; }");
     $file->rewind();
     $file->seekTokenType(T_CONST);
     $rule = new Constants();
     $rule->setFormat('BAZ');
     $rule->visitToken($file);
     $this->assertRuleViolations($file, array(array('line' => 1, 'column' => 25, 'message' => 'Constant name does not match format "BAZ"', 'source' => 'Flitch\\Naming\\Constants')));
 }
コード例 #4
0
ファイル: ClassesTest.php プロジェクト: dasprid/flitch
 public function testClassNaming()
 {
     $tokenizer = new Tokenizer();
     $file = $tokenizer->tokenize('foo.php', "<?php class foo {} class bar {}");
     $file->rewind();
     $file->seekTokenType(T_CLASS);
     $rule = new Classes();
     $rule->setFormat('bar');
     $rule->visitToken($file);
     $this->assertRuleViolations($file, array(array('line' => 1, 'column' => 13, 'message' => 'Class name does not match format "bar"', 'source' => 'Flitch\\Naming\\Classes')));
 }
コード例 #5
0
ファイル: MethodsTest.php プロジェクト: dasprid/flitch
 public function testNoViolationOnClosures()
 {
     $tokenizer = new Tokenizer();
     $file = $tokenizer->tokenize('foo.php', "<?php function() {}; class foo {}");
     $file->rewind();
     $file->seekTokenType(T_FUNCTION);
     $rule = new Methods();
     $rule->setFormat('bar');
     $rule->visitToken($file);
     $this->assertRuleViolations($file, array());
 }
コード例 #6
0
ファイル: Cli.php プロジェクト: dasprid/flitch
 /**
  * Analyze single file for coding standard violations.
  *
  * @param  string       $path
  * @param  Tokenizer    $tokenizer
  * @param  Manager      $manager
  * @return File
  */
 protected function analyzeFile($path, Tokenizer $tokenizer, Manager $manager)
 {
     $file = $tokenizer->tokenize($path, file_get_contents($path));
     $manager->check($file);
     foreach ($this->reports as $report) {
         $report->addFile($file);
     }
     return $file;
 }