Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 8b16cd5

Browse files
author
Oleksii Korshenko
authored
Merge pull request #862 from magento-engcom/develop-prs
magento/magento2#8611 magento/magento2#8610 magento/magento2#8609
2 parents 469e2bb + 9566773 commit 8b16cd5

File tree

8 files changed

+67
-62
lines changed

8 files changed

+67
-62
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Void.php renamed to app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/VoidAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Magento\Backend\App\Action;
99

10-
class Void extends \Magento\Backend\App\Action
10+
class VoidAction extends Action
1111
{
1212
/**
1313
* Authorization level of a basic admin session

app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php renamed to app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/VoidAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
namespace Magento\Sales\Controller\Adminhtml\Order\Invoice;
88

9-
class Void extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View
9+
class VoidAction extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View
1010
{
1111
/**
1212
* Void invoice action

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/VoidTest.php renamed to app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/VoidActionTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
namespace Magento\Sales\Test\Unit\Controller\Adminhtml\Order\Creditmemo;
77

88
/**
9-
* Class VoidTest
9+
* Class VoidActionTest
1010
* @SuppressWarnings(PHPMD.TooManyFields)
1111
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1212
*/
13-
class VoidTest extends \PHPUnit_Framework_TestCase
13+
class VoidActionTest extends \PHPUnit_Framework_TestCase
1414
{
1515
/**
1616
* @var \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\AddComment
@@ -179,7 +179,7 @@ protected function setUp()
179179

180180
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
181181
$this->controller = $objectManager->getObject(
182-
\Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Void::class,
182+
\Magento\Sales\Controller\Adminhtml\Order\Creditmemo\VoidAction::class,
183183
[
184184
'context' => $this->contextMock,
185185
'creditmemoLoader' => $this->loaderMock,

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/VoidTest.php renamed to app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/VoidActionTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
use Magento\Sales\Api\InvoiceRepositoryInterface;
1111

1212
/**
13-
* Class VoidTest
13+
* Class VoidActionTest
1414
* @package Magento\Sales\Controller\Adminhtml\Order\Invoice
1515
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1616
*/
17-
class VoidTest extends \PHPUnit_Framework_TestCase
17+
class VoidActionTest extends \PHPUnit_Framework_TestCase
1818
{
1919
/**
2020
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -166,7 +166,7 @@ protected function setUp()
166166
->getMockForAbstractClass();
167167

168168
$this->controller = $objectManager->getObject(
169-
\Magento\Sales\Controller\Adminhtml\Order\Invoice\Void::class,
169+
\Magento\Sales\Controller\Adminhtml\Order\Invoice\VoidAction::class,
170170
[
171171
'context' => $contextMock,
172172
'resultForwardFactory' => $this->resultForwardFactoryMock

dev/tests/static/framework/Magento/Sniffs/NamingConventions/ReservedWordsSniff.php

+45-32
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,35 @@
1111
class ReservedWordsSniff implements PHP_CodeSniffer_Sniff
1212
{
1313
/**
14-
* source: http://php.net/manual/en/reserved.other-reserved-words.php
14+
* The following words cannot be used to name a class, interface or trait,
15+
* and they are also prohibited from being used in namespaces.
1516
*
16-
* @var array PHP 7 reserved words for name spaces
17+
* @link http://php.net/manual/en/reserved.other-reserved-words.php
18+
*
19+
* @var string[]
1720
*/
1821
protected $reservedWords = [
19-
'int',
20-
'float',
21-
'bool',
22-
'string',
23-
'true',
24-
'false',
25-
'null',
26-
'resource',
27-
'object',
28-
'mixed',
29-
'numeric',
22+
'int' => '7',
23+
'float' => '7',
24+
'bool' => '7',
25+
'string' => '7',
26+
'true' => '7',
27+
'false' => '7',
28+
'null' => '7',
29+
'void' => '7.1',
30+
'iterable' => '7.1',
31+
'resource' => '7',
32+
'object' => '7',
33+
'mixed' => '7',
34+
'numeric' => '7',
3035
];
3136

3237
/**
3338
* {@inheritdoc}
3439
*/
3540
public function register()
3641
{
37-
return [T_NAMESPACE, T_CLASS];
42+
return [T_CLASS, T_INTERFACE, T_TRAIT, T_NAMESPACE];
3843
}
3944

4045
/**
@@ -44,20 +49,23 @@ public function register()
4449
* @param int $stackPtr
4550
* @return void
4651
*/
47-
protected function validateNameSpace(PHP_CodeSniffer_File $sourceFile, $stackPtr)
52+
protected function validateNamespace(PHP_CodeSniffer_File $sourceFile, $stackPtr)
4853
{
49-
$skippedTokens = ['T_NS_SEPARATOR', 'T_WHITESPACE'];
50-
//skip "namespace" and whitespace
5154
$stackPtr += 2;
5255
$tokens = $sourceFile->getTokens();
53-
while ('T_SEMICOLON' != $tokens[$stackPtr]['type']) {
54-
if (in_array($tokens[$stackPtr]['type'], $skippedTokens)) {
55-
$stackPtr++;
56+
while ($stackPtr < $sourceFile->numTokens && $tokens[$stackPtr]['code'] !== T_SEMICOLON) {
57+
if ($tokens[$stackPtr]['code'] === T_WHITESPACE || $tokens[$stackPtr]['code'] === T_NS_SEPARATOR) {
58+
$stackPtr++; //skip "namespace" and whitespace
5659
continue;
5760
}
58-
$nameSpacePart = strtolower($tokens[$stackPtr]['content']);
59-
if (in_array($nameSpacePart, $this->reservedWords)) {
60-
$sourceFile->addError('\'' . $nameSpacePart . '\' is a reserved word in PHP 7.', $stackPtr);
61+
$namespacePart = $tokens[$stackPtr]['content'];
62+
if (isset($this->reservedWords[strtolower($namespacePart)])) {
63+
$sourceFile->addError(
64+
'Cannot use "%s" in namespace as it is reserved since PHP %s',
65+
$stackPtr,
66+
'Namespace',
67+
[$namespacePart, $this->reservedWords[$namespacePart]]
68+
);
6169
}
6270
$stackPtr++;
6371
}
@@ -73,12 +81,15 @@ protected function validateNameSpace(PHP_CodeSniffer_File $sourceFile, $stackPtr
7381
protected function validateClass(PHP_CodeSniffer_File $sourceFile, $stackPtr)
7482
{
7583
$tokens = $sourceFile->getTokens();
76-
//skipped "class" and whitespace
77-
$stackPtr += 2;
84+
$stackPtr += 2; //skip "class" and whitespace
7885
$className = strtolower($tokens[$stackPtr]['content']);
79-
80-
if (in_array($className, $this->reservedWords)) {
81-
$sourceFile->addError('Class name \'' . $className . '\' is a reserved word in PHP 7', $stackPtr);
86+
if (isset($this->reservedWords[$className])) {
87+
$sourceFile->addError(
88+
'Cannot use "%s" as class name as it is reserved since PHP %s',
89+
$stackPtr,
90+
'Class',
91+
[$className, $this->reservedWords[$className]]
92+
);
8293
}
8394
}
8495

@@ -88,12 +99,14 @@ protected function validateClass(PHP_CodeSniffer_File $sourceFile, $stackPtr)
8899
public function process(PHP_CodeSniffer_File $sourceFile, $stackPtr)
89100
{
90101
$tokens = $sourceFile->getTokens();
91-
switch ($tokens[$stackPtr]['type']) {
92-
case "T_CLASS":
102+
switch ($tokens[$stackPtr]['code']) {
103+
case T_CLASS:
104+
case T_INTERFACE:
105+
case T_TRAIT:
93106
$this->validateClass($sourceFile, $stackPtr);
94107
break;
95-
case "T_NAMESPACE":
96-
$this->validateNameSpace($sourceFile, $stackPtr);
108+
case T_NAMESPACE:
109+
$this->validateNamespace($sourceFile, $stackPtr);
97110
break;
98111
}
99112
}

lib/internal/Magento/Framework/App/Router/ActionList.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ActionList
3434
'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'instanceof',
3535
'insteadof','interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected',
3636
'public', 'require', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var',
37-
'while', 'xor',
37+
'while', 'xor', 'void',
3838
];
3939

4040
/**

setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@
1010
use Symfony\Component\Console\Input\InputDefinition;
1111
use Symfony\Component\Console\Input\InputArgument;
1212

13+
/**
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
*/
1316
class JobSetCacheTest extends \PHPUnit_Framework_TestCase
1417
{
1518
/**
1619
* @dataProvider setCacheDataProvider
1720
* @param string $commandClass
18-
* @param string $arrayInput
21+
* @param array $arrayInput
1922
* @param string $jobName
2023
* @param array $params
2124
*/
2225
public function testSetCache($commandClass, $arrayInput, $jobName, $params)
2326
{
27+
$arrayInput = new ArrayInput($arrayInput);
2428
$objectManagerProvider = $this->getMock(\Magento\Setup\Model\ObjectManagerProvider::class, [], [], '', false);
2529
$objectManager =
2630
$this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class, [], '', false);
@@ -62,18 +66,16 @@ public function testSetCache($commandClass, $arrayInput, $jobName, $params)
6266
*/
6367
public function setCacheDataProvider()
6468
{
65-
$cacheEnable = new ArrayInput(['command' => 'cache:enable', 'types' => ['cache1']]);
66-
$cacheDisable = new ArrayInput(['command' => 'cache:disable']);
6769
return [
6870
[
6971
\Magento\Backend\Console\Command\CacheEnableCommand::class,
70-
$cacheEnable,
72+
['command' => 'cache:enable', 'types' => ['cache1']],
7173
'setup:cache:enable',
7274
['cache1']
7375
],
7476
[
7577
\Magento\Backend\Console\Command\CacheDisableCommand::class,
76-
$cacheDisable,
78+
['command' => 'cache:disable'],
7779
'setup:cache:disable',
7880
[]
7981
],

setup/src/Magento/Setup/Test/Unit/Module/I18n/Dictionary/Writer/Csv/StdoTest.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,15 @@
55
*/
66
namespace Magento\Setup\Test\Unit\Module\I18n\Dictionary\Writer\Csv;
77

8+
use Magento\Setup\Module\I18n\Dictionary\Writer\Csv\Stdo;
9+
810
class StdoTest extends \PHPUnit_Framework_TestCase
911
{
10-
/**
11-
* @var resource
12-
*/
13-
protected $_handler;
14-
15-
protected function setUp()
16-
{
17-
$this->_handler = STDOUT;
18-
}
19-
2012
public function testThatHandlerIsRight()
2113
{
22-
$this->markTestSkipped('This is skiped as we should not close the STDO!');
23-
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
24-
/** @var \Magento\Setup\Module\I18n\Dictionary\Writer\Csv $writer */
25-
$writer = $objectManagerHelper->getObject(\Magento\Setup\Module\I18n\Dictionary\Writer\Csv\Stdo::class);
26-
27-
$this->assertAttributeEquals($this->_handler, '_fileHandler', $writer);
14+
$handler = STDOUT;
15+
// Mocking object's under test destructor here is perfectly valid as there is no way to reopen STDOUT
16+
$writer = $this->getMock(Stdo::class, ['__destruct']);
17+
$this->assertAttributeEquals($handler, '_fileHandler', $writer);
2818
}
2919
}

0 commit comments

Comments
 (0)