Skip to content

Commit

Permalink
Implemented #120: Disable Magento validators by default
Browse files Browse the repository at this point in the history
 - enamed class. Updated config.
  • Loading branch information
andkirby committed Sep 5, 2016
1 parent 1e59296 commit f5009df
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 42 deletions.
28 changes: 28 additions & 0 deletions src/config/validators/Magento-MageExceptionThrow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<!--
/**
* @license https://raw.githubusercontent.com/andkirby/commithook/master/LICENSE.md
*/
-->
<config>
<!--Hooks process setup-->
<hooks>
<pre-commit>
<filetype>
<php>
<validators>
<Magento-MageExceptionThrow>0</Magento-MageExceptionThrow>
</validators>
</php>
</filetype>
<ignore>
<validator>
<code>
<Magento-MageExceptionThrow>1</Magento-MageExceptionThrow>
</code>
</validator>
</ignore>
</pre-commit>
</hooks>
</config>

Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@
<filetype>
<php>
<validators>
<CodingStandardMagento>1</CodingStandardMagento>
<Magento-ModelEventFields>1</Magento-ModelEventFields>
<Magento-ModelEventFields>0</Magento-ModelEventFields>
</validators>
</php>
</filetype>
<ignore>
<validator>
<code>
<CodingStandardMagento>1</CodingStandardMagento>
<Magento-ModelEventFields>1</Magento-ModelEventFields>
</code>
</validator>
</ignore>
</pre-commit>
</hooks>
</config>

Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**#@-*/

/**
Expand All @@ -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.\')',
);

/**
Expand Down
55 changes: 28 additions & 27 deletions src/tests/testsuite/PreCommit/Test/Processor/PreCommitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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,
)
),
);
],
],
];
}

/**
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit f5009df

Please sign in to comment.