Skip to content

Commit

Permalink
Merge pull request magento#862 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksii Korshenko authored Feb 22, 2017
2 parents 469e2bb + 9566773 commit 8b16cd5
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use Magento\Backend\App\Action;

class Void extends \Magento\Backend\App\Action
class VoidAction extends Action
{
/**
* Authorization level of a basic admin session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
namespace Magento\Sales\Controller\Adminhtml\Order\Invoice;

class Void extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View
class VoidAction extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View
{
/**
* Void invoice action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
namespace Magento\Sales\Test\Unit\Controller\Adminhtml\Order\Creditmemo;

/**
* Class VoidTest
* Class VoidActionTest
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class VoidTest extends \PHPUnit_Framework_TestCase
class VoidActionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\AddComment
Expand Down Expand Up @@ -179,7 +179,7 @@ protected function setUp()

$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->controller = $objectManager->getObject(
\Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Void::class,
\Magento\Sales\Controller\Adminhtml\Order\Creditmemo\VoidAction::class,
[
'context' => $this->contextMock,
'creditmemoLoader' => $this->loaderMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use Magento\Sales\Api\InvoiceRepositoryInterface;

/**
* Class VoidTest
* Class VoidActionTest
* @package Magento\Sales\Controller\Adminhtml\Order\Invoice
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class VoidTest extends \PHPUnit_Framework_TestCase
class VoidActionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
Expand Down Expand Up @@ -166,7 +166,7 @@ protected function setUp()
->getMockForAbstractClass();

$this->controller = $objectManager->getObject(
\Magento\Sales\Controller\Adminhtml\Order\Invoice\Void::class,
\Magento\Sales\Controller\Adminhtml\Order\Invoice\VoidAction::class,
[
'context' => $contextMock,
'resultForwardFactory' => $this->resultForwardFactoryMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,35 @@
class ReservedWordsSniff implements PHP_CodeSniffer_Sniff
{
/**
* source: http://php.net/manual/en/reserved.other-reserved-words.php
* The following words cannot be used to name a class, interface or trait,
* and they are also prohibited from being used in namespaces.
*
* @var array PHP 7 reserved words for name spaces
* @link http://php.net/manual/en/reserved.other-reserved-words.php
*
* @var string[]
*/
protected $reservedWords = [
'int',
'float',
'bool',
'string',
'true',
'false',
'null',
'resource',
'object',
'mixed',
'numeric',
'int' => '7',
'float' => '7',
'bool' => '7',
'string' => '7',
'true' => '7',
'false' => '7',
'null' => '7',
'void' => '7.1',
'iterable' => '7.1',
'resource' => '7',
'object' => '7',
'mixed' => '7',
'numeric' => '7',
];

/**
* {@inheritdoc}
*/
public function register()
{
return [T_NAMESPACE, T_CLASS];
return [T_CLASS, T_INTERFACE, T_TRAIT, T_NAMESPACE];
}

/**
Expand All @@ -44,20 +49,23 @@ public function register()
* @param int $stackPtr
* @return void
*/
protected function validateNameSpace(PHP_CodeSniffer_File $sourceFile, $stackPtr)
protected function validateNamespace(PHP_CodeSniffer_File $sourceFile, $stackPtr)
{
$skippedTokens = ['T_NS_SEPARATOR', 'T_WHITESPACE'];
//skip "namespace" and whitespace
$stackPtr += 2;
$tokens = $sourceFile->getTokens();
while ('T_SEMICOLON' != $tokens[$stackPtr]['type']) {
if (in_array($tokens[$stackPtr]['type'], $skippedTokens)) {
$stackPtr++;
while ($stackPtr < $sourceFile->numTokens && $tokens[$stackPtr]['code'] !== T_SEMICOLON) {
if ($tokens[$stackPtr]['code'] === T_WHITESPACE || $tokens[$stackPtr]['code'] === T_NS_SEPARATOR) {
$stackPtr++; //skip "namespace" and whitespace
continue;
}
$nameSpacePart = strtolower($tokens[$stackPtr]['content']);
if (in_array($nameSpacePart, $this->reservedWords)) {
$sourceFile->addError('\'' . $nameSpacePart . '\' is a reserved word in PHP 7.', $stackPtr);
$namespacePart = $tokens[$stackPtr]['content'];
if (isset($this->reservedWords[strtolower($namespacePart)])) {
$sourceFile->addError(
'Cannot use "%s" in namespace as it is reserved since PHP %s',
$stackPtr,
'Namespace',
[$namespacePart, $this->reservedWords[$namespacePart]]
);
}
$stackPtr++;
}
Expand All @@ -73,12 +81,15 @@ protected function validateNameSpace(PHP_CodeSniffer_File $sourceFile, $stackPtr
protected function validateClass(PHP_CodeSniffer_File $sourceFile, $stackPtr)
{
$tokens = $sourceFile->getTokens();
//skipped "class" and whitespace
$stackPtr += 2;
$stackPtr += 2; //skip "class" and whitespace
$className = strtolower($tokens[$stackPtr]['content']);

if (in_array($className, $this->reservedWords)) {
$sourceFile->addError('Class name \'' . $className . '\' is a reserved word in PHP 7', $stackPtr);
if (isset($this->reservedWords[$className])) {
$sourceFile->addError(
'Cannot use "%s" as class name as it is reserved since PHP %s',
$stackPtr,
'Class',
[$className, $this->reservedWords[$className]]
);
}
}

Expand All @@ -88,12 +99,14 @@ protected function validateClass(PHP_CodeSniffer_File $sourceFile, $stackPtr)
public function process(PHP_CodeSniffer_File $sourceFile, $stackPtr)
{
$tokens = $sourceFile->getTokens();
switch ($tokens[$stackPtr]['type']) {
case "T_CLASS":
switch ($tokens[$stackPtr]['code']) {
case T_CLASS:
case T_INTERFACE:
case T_TRAIT:
$this->validateClass($sourceFile, $stackPtr);
break;
case "T_NAMESPACE":
$this->validateNameSpace($sourceFile, $stackPtr);
case T_NAMESPACE:
$this->validateNamespace($sourceFile, $stackPtr);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/App/Router/ActionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ActionList
'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'instanceof',
'insteadof','interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected',
'public', 'require', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var',
'while', 'xor',
'while', 'xor', 'void',
];

/**
Expand Down
12 changes: 7 additions & 5 deletions setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputArgument;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class JobSetCacheTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider setCacheDataProvider
* @param string $commandClass
* @param string $arrayInput
* @param array $arrayInput
* @param string $jobName
* @param array $params
*/
public function testSetCache($commandClass, $arrayInput, $jobName, $params)
{
$arrayInput = new ArrayInput($arrayInput);
$objectManagerProvider = $this->getMock(\Magento\Setup\Model\ObjectManagerProvider::class, [], [], '', false);
$objectManager =
$this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class, [], '', false);
Expand Down Expand Up @@ -62,18 +66,16 @@ public function testSetCache($commandClass, $arrayInput, $jobName, $params)
*/
public function setCacheDataProvider()
{
$cacheEnable = new ArrayInput(['command' => 'cache:enable', 'types' => ['cache1']]);
$cacheDisable = new ArrayInput(['command' => 'cache:disable']);
return [
[
\Magento\Backend\Console\Command\CacheEnableCommand::class,
$cacheEnable,
['command' => 'cache:enable', 'types' => ['cache1']],
'setup:cache:enable',
['cache1']
],
[
\Magento\Backend\Console\Command\CacheDisableCommand::class,
$cacheDisable,
['command' => 'cache:disable'],
'setup:cache:disable',
[]
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,15 @@
*/
namespace Magento\Setup\Test\Unit\Module\I18n\Dictionary\Writer\Csv;

use Magento\Setup\Module\I18n\Dictionary\Writer\Csv\Stdo;

class StdoTest extends \PHPUnit_Framework_TestCase
{
/**
* @var resource
*/
protected $_handler;

protected function setUp()
{
$this->_handler = STDOUT;
}

public function testThatHandlerIsRight()
{
$this->markTestSkipped('This is skiped as we should not close the STDO!');
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
/** @var \Magento\Setup\Module\I18n\Dictionary\Writer\Csv $writer */
$writer = $objectManagerHelper->getObject(\Magento\Setup\Module\I18n\Dictionary\Writer\Csv\Stdo::class);

$this->assertAttributeEquals($this->_handler, '_fileHandler', $writer);
$handler = STDOUT;
// Mocking object's under test destructor here is perfectly valid as there is no way to reopen STDOUT
$writer = $this->getMock(Stdo::class, ['__destruct']);
$this->assertAttributeEquals($handler, '_fileHandler', $writer);
}
}

0 comments on commit 8b16cd5

Please sign in to comment.