Пример #1
0
 /**
  * getLintsShouldReturnArrayClassAndPath
  * @author Alistair Stead
  * @test
  */
 public function getLintsShouldReturnArrayClassAndPath()
 {
     $lints = array('MageTool_Lint_Xml' => 'MageTool/Lint/Xml.php', 'MageTool_Lint_Config' => 'MageTool/Lint/Config.php', 'MageTool_Lint_System' => 'MageTool/Lint/System.php', 'MageTool_Lint_Adminhtml' => 'MageTool/Lint/Adminhtml.php', 'MageTool_Lint_Api' => 'MageTool/Lint/Api.php');
     $lintObjects = array();
     foreach ($lints as $lintClass => $includePath) {
         include_once $includePath;
         $lintTest = new $lintClass();
         $lintObjects[] = $lintTest;
     }
     $this->_lint->addLints($lintObjects);
     $result = $this->_lint->getLints();
     $this->assertTrue(is_array($result), 'No lints array has been returned');
     $this->assertEquals(5, count($result), 'An unexpected number of lints has been found');
     foreach ($lints as $class => $path) {
         $this->assertFileExists($path, 'Path not found on the include path');
     }
 }
Пример #2
0
 /**
  * Validate the Magento xml config using lint tests
  *
  * @return void
  * @author Alistair Stead
  **/
 public function lint($configFilePath = 'app/code/local', $lintFilePath = null)
 {
     $this->_bootstrap();
     // TODO search local file path and the supplied path for files that implement lint
     $lints = array('MageTool_Lint_Xml' => 'MageTool/Lint/Xml.php', 'MageTool_Lint_Config' => 'MageTool/Lint/Config.php', 'MageTool_Lint_System' => 'MageTool/Lint/System.php', 'MageTool_Lint_Adminhtml' => 'MageTool/Lint/Adminhtml.php', 'MageTool_Lint_Api' => 'MageTool/Lint/Api.php');
     $lintObjects = array();
     foreach ($lints as $lintClass => $includePath) {
         try {
             include_once $includePath;
             $lintTest = new $lintClass();
             $lintObjects[] = $lintTest;
         } catch (MageTool_Lint_Exception $e) {
             $this->_response->appendContent("{$e->getMessage()}", array('color' => array('red')));
         }
     }
     $lint = new MageTool_Lint();
     $lint->setPathFilter($configFilePath);
     // If an additional lint file path is supplied pass it to be loaded
     if (!is_null($lintFilePath)) {
         $lint->addLints($lintFilePath);
     } else {
         $lint->addLints($lintObjects);
     }
     $lint->run();
     foreach ($lint->getMessages() as $message) {
         $this->_response->appendContent("{$message->getLevel()}: {$message->getMessage()}", array('color' => array($message->getColour())));
     }
     $count = count($lint->getMessages());
     if ($count > 0) {
         $this->_response->appendContent("({$count}) Messages reported", array('color' => array('red')));
     } else {
         $this->_response->appendContent("No errors found", array('color' => array('green')));
     }
 }