From f5009df7ff6c93b1aa69ff1e821fb685641c43dc Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Mon, 5 Sep 2016 14:26:20 +0300 Subject: [PATCH] Implemented #120: Disable Magento validators by default - enamed class. Updated config. --- .../validators/Magento-MageExceptionThrow.xml | 28 ++++++++++ .../Magento-ModelEventFields.xml} | 6 +- .../MageExceptionThrow.php} | 9 +-- .../Test/Processor/PreCommitTest.php | 55 ++++++++++--------- .../MageExceptionThrowTest.php} | 16 +++--- 5 files changed, 72 insertions(+), 42 deletions(-) create mode 100644 src/config/validators/Magento-MageExceptionThrow.xml rename src/config/{pre-commit-magento.xml => validators/Magento-ModelEventFields.xml} (87%) rename src/lib/PreCommit/Validator/{CodingStandardMagento.php => Magento/MageExceptionThrow.php} (86%) rename src/tests/testsuite/PreCommit/Test/Validator/{CodingStandardMagentoTest.php => Magento/MageExceptionThrowTest.php} (53%) diff --git a/src/config/validators/Magento-MageExceptionThrow.xml b/src/config/validators/Magento-MageExceptionThrow.xml new file mode 100644 index 0000000..42f6db2 --- /dev/null +++ b/src/config/validators/Magento-MageExceptionThrow.xml @@ -0,0 +1,28 @@ + + + + + + + + + + 0 + + + + + + + 1 + + + + + + + diff --git a/src/config/pre-commit-magento.xml b/src/config/validators/Magento-ModelEventFields.xml similarity index 87% rename from src/config/pre-commit-magento.xml rename to src/config/validators/Magento-ModelEventFields.xml index 8533672..1729b5f 100644 --- a/src/config/pre-commit-magento.xml +++ b/src/config/validators/Magento-ModelEventFields.xml @@ -21,19 +21,17 @@ - 1 - 1 + 0 - 1 + 1 - diff --git a/src/lib/PreCommit/Validator/CodingStandardMagento.php b/src/lib/PreCommit/Validator/Magento/MageExceptionThrow.php similarity index 86% rename from src/lib/PreCommit/Validator/CodingStandardMagento.php rename to src/lib/PreCommit/Validator/Magento/MageExceptionThrow.php index e4632d8..cfb3020 100644 --- a/src/lib/PreCommit/Validator/CodingStandardMagento.php +++ b/src/lib/PreCommit/Validator/Magento/MageExceptionThrow.php @@ -2,20 +2,21 @@ /** * @license https://raw.githubusercontent.com/andkirby/commithook/master/LICENSE.md */ -namespace PreCommit\Validator; +namespace PreCommit\Validator\Magento; + +use PreCommit\Validator\CodingStandard; /** * Class CodingStandard validator * * @package PreCommit\Validator */ -class CodingStandardMagento extends CodingStandard +class MageExceptionThrow extends CodingStandard { /**#@+ * Error codes */ const CODE_PHP_DEPRECATED_THROW_EXCEPTION = 'deprecatedUsingMageThrowException'; - /**#@-*/ /** @@ -25,7 +26,7 @@ class CodingStandardMagento extends CodingStandard */ protected $errorMessages = array( - self::CODE_PHP_DEPRECATED_THROW_EXCEPTION => 'Used deprecated method Mage::throwException(). Use: throw new Mage_Core_Exception("Translated message.")', + self::CODE_PHP_DEPRECATED_THROW_EXCEPTION => 'Used deprecated method Mage::throwException(). Use: throw new Your_Module_Exception(\'Your message.\')', ); /** diff --git a/src/tests/testsuite/PreCommit/Test/Processor/PreCommitTest.php b/src/tests/testsuite/PreCommit/Test/Processor/PreCommitTest.php index 48bcb2d..8fab62d 100644 --- a/src/tests/testsuite/PreCommit/Test/Processor/PreCommitTest.php +++ b/src/tests/testsuite/PreCommit/Test/Processor/PreCommitTest.php @@ -14,10 +14,10 @@ class PreCommitTest extends \PHPUnit_Framework_TestCase /** * Set up test model */ - static public function setUpBeforeClass() + public static function setUpBeforeClass() { //init config - Config::initInstance(array('file' => PROJECT_ROOT . '/config.xml')); + Config::initInstance(['file' => PROJECT_ROOT.'/config.xml']); Config::setSrcRootDir(PROJECT_ROOT); Config::mergeExtraConfig(); } @@ -29,37 +29,38 @@ static public function setUpBeforeClass() */ public function dataTestValidatorsType() { - return array( - array( + return [ + [ 'php', - array( - 'PhpClass' => 1, - 'PhpDoc' => 1, - 'CodingStandard' => 1, - 'RedundantCode' => 1, - 'CodingStandardMagento' => 1, - ) - ), - array( + [ + 'PhpClass' => 1, + 'PhpDoc' => 1, + 'CodingStandard' => 1, + 'RedundantCode' => 1, + 'Magento-MageExceptionThrow' => 1, + 'Magento-ModelEventFields' => 1, + ], + ], + [ 'phtml', - array( - 'RedundantCode' => 1, + [ + 'RedundantCode' => 1, 'CodingStandardPhtml' => 1, - ) - ), - array( + ], + ], + [ 'js', - array( + [ 'RedundantCode' => 1, - ) - ), - array( + ], + ], + [ 'xml', - array( + [ 'XmlParser' => 1, - ) - ), - ); + ], + ], + ]; } /** @@ -72,7 +73,7 @@ public function dataTestValidatorsType() public function testGetValidatorsType($type, $expected) { /** @var \PreCommit\Processor\PreCommit $test */ - $test = $this->getMock('\PreCommit\Processor\PreCommit', array('____'), array(), '', false); + $test = $this->getMock('\PreCommit\Processor\PreCommit', ['____'], [], '', false); $result = $test->getValidators($type); $this->assertEquals($expected, $result); } diff --git a/src/tests/testsuite/PreCommit/Test/Validator/CodingStandardMagentoTest.php b/src/tests/testsuite/PreCommit/Test/Validator/Magento/MageExceptionThrowTest.php similarity index 53% rename from src/tests/testsuite/PreCommit/Test/Validator/CodingStandardMagentoTest.php rename to src/tests/testsuite/PreCommit/Test/Validator/Magento/MageExceptionThrowTest.php index 777e3c5..0a3bac3 100644 --- a/src/tests/testsuite/PreCommit/Test/Validator/CodingStandardMagentoTest.php +++ b/src/tests/testsuite/PreCommit/Test/Validator/Magento/MageExceptionThrowTest.php @@ -2,26 +2,28 @@ /** * @license https://raw.githubusercontent.com/andkirby/commithook/master/LICENSE.md */ -namespace PreCommit\Test\Validator; +namespace PreCommit\Test\Validator\Magento; -use PreCommit\Validator\CodingStandardMagento; +use PreCommit\Test\Validator\CodingStandardTest; +use PreCommit\Validator\Magento\MageExceptionThrow; /** * Class test for Processor */ -class CodingStandardMagentoTest extends CodingStandardTest +class MageExceptionThrowTest extends CodingStandardTest { /** * Test CODE_PHP_SPACE_BRACKET */ public function testDeprecatedThrowException() { - $errors = $this->_getSpecificErrorsList( + $errors = $this->_getSpecificErrorsList( self::$_classTest, - CodingStandardMagento::CODE_PHP_DEPRECATED_THROW_EXCEPTION); - $expected = array ( - "Mage::throwException('text');", + MageExceptionThrow::CODE_PHP_DEPRECATED_THROW_EXCEPTION ); + $expected = [ + "Mage::throwException('text');", + ]; $this->assertEquals($expected, array_values($errors)); } }