Skip to content

Commit 1164adc

Browse files
author
Cari Spruiell
committed
Merge remote-tracking branch 'ext/MAGETWO-54031-static-tests' into pull-request
2 parents cae60bb + b20c0c8 commit 1164adc

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\TestFramework\Integrity;
7+
8+
use Magento\Framework\Exception\ValidatorException;
9+
use Magento\Framework\Interception\Code\InterfaceValidator;
10+
use Magento\Framework\Phrase;
11+
12+
class PluginValidator
13+
{
14+
/** @var InterfaceValidator */
15+
private $frameworkValidator;
16+
17+
/**
18+
* @param InterfaceValidator $frameworkValidator
19+
*/
20+
public function __construct(InterfaceValidator $frameworkValidator)
21+
{
22+
$this->frameworkValidator = $frameworkValidator;
23+
}
24+
25+
/**
26+
* Validate plugin and intercepted class
27+
*
28+
* @param string $pluginClass
29+
* @param string $interceptedType
30+
* @throws ValidatorException
31+
*/
32+
public function validate($pluginClass, $interceptedType)
33+
{
34+
$this->frameworkValidator->validate($pluginClass, $interceptedType);
35+
$this->validateClassNameMatchesCase($pluginClass);
36+
$this->validateClassNameMatchesCase($interceptedType);
37+
}
38+
39+
/**
40+
* Verify that the class name has same capitalization as the class declaration
41+
*
42+
* @param string $className
43+
* @throws ValidatorException
44+
*/
45+
private function validateClassNameMatchesCase($className)
46+
{
47+
$declarationName = (new \ReflectionClass($className))->getName();;
48+
if (ltrim($className, '\\') != ltrim($declarationName)) {
49+
throw new ValidatorException(
50+
new Phrase(
51+
"Capitalization of class name '%1' does not match expected '%2'",
52+
[$className, $declarationName]
53+
)
54+
);
55+
}
56+
}
57+
}

dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
use Magento\Framework\Api\Code\Generator\SearchResults;
1212
use Magento\Framework\App\Filesystem\DirectoryList;
1313
use Magento\Framework\Component\ComponentRegistrar;
14+
use Magento\Framework\Interception\Code\InterfaceValidator;
1415
use Magento\Framework\ObjectManager\Code\Generator\Converter;
1516
use Magento\Framework\ObjectManager\Code\Generator\Factory;
1617
use Magento\Framework\ObjectManager\Code\Generator\Repository;
1718
use Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceGenerator;
1819
use Magento\Framework\Api\Code\Generator\ExtensionAttributesGenerator;
1920
use Magento\Framework\App\Utility\Files;
21+
use Magento\TestFramework\Integrity\PluginValidator;
2022

2123
/**
2224
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -56,7 +58,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase
5658
/**
5759
* Class arguments reader
5860
*
59-
* @var \Magento\Framework\Interception\Code\InterfaceValidator
61+
* @var PluginValidator
6062
*/
6163
protected $pluginValidator;
6264

@@ -103,7 +105,7 @@ protected function setUp()
103105
$this->_validator->add(new \Magento\Framework\Code\Validator\TypeDuplication());
104106
$this->_validator->add(new \Magento\Framework\Code\Validator\ArgumentSequence());
105107
$this->_validator->add(new \Magento\Framework\Code\Validator\ConstructorArgumentTypes());
106-
$this->pluginValidator = new \Magento\Framework\Interception\Code\InterfaceValidator();
108+
$this->pluginValidator = new PluginValidator(new InterfaceValidator());
107109
}
108110

109111
/**

0 commit comments

Comments
 (0)