Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions
ClassesTest Class Reference
Inheritance diagram for ClassesTest:

Public Member Functions

 testPhpCode ()
 
 testConfiguration ()
 
 testLayouts ()
 

Protected Member Functions

 _assertNonFactoryName ($names, $file, $softComparison=false, $moduleBlock=false)
 

Detailed Description

Definition at line 14 of file ClassesTest.php.

Member Function Documentation

◆ _assertNonFactoryName()

_assertNonFactoryName (   $names,
  $file,
  $softComparison = false,
  $moduleBlock = false 
)
protected

Check whether specified classes or module names correspond to a file according PSR-1 Standard.

Suppressing "unused variable" because of the "catch" block

Parameters
array$names
bool$softComparison@SuppressWarnings(PHPMD.UnusedLocalVariable)

Definition at line 100 of file ClassesTest.php.

101  {
102  if (!$names) {
103  return;
104  }
105  $factoryNames = [];
106  foreach ($names as $name) {
107  try {
108  if ($softComparison) {
109  $this->assertNotRegExp('/\//', $name);
110  } elseif ($moduleBlock) {
111  $this->assertFalse(false === strpos($name, '_'));
112  $this->assertRegExp('/^([A-Z][A-Za-z\d_]+)+$/', $name);
113  } else {
114  if (strpos($name, 'Magento') === false) {
115  continue;
116  }
117  $this->assertFalse(false === strpos($name, '\\'));
118  $this->assertRegExp('/^([A-Z\\\\][A-Za-z\d\\\\]+)+$/', $name);
119  }
120  } catch (\PHPUnit\Framework\AssertionFailedError $e) {
121  $factoryNames[] = $name;
122  }
123  }
124  if ($factoryNames) {
125  $this->fail("Obsolete factory name(s) detected in {$file}:" . "\n" . implode("\n", $factoryNames));
126  }
127  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ testConfiguration()

testConfiguration ( )
Parameters
string$path

Definition at line 38 of file ClassesTest.php.

39  {
40  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
41  $invoker(
45  function ($path) {
46  $xml = simplexml_load_file($path);
47 
49  $this->_assertNonFactoryName($classes, $path);
50 
51  $modules = \Magento\Framework\App\Utility\Classes::getXmlAttributeValues($xml, '//@module', 'module');
52  $this->_assertNonFactoryName(array_unique($modules), $path, false, true);
53  },
54  Files::init()->getConfigFiles()
55  );
56  }
static collectClassesInConfig(\SimpleXMLElement $xml)
Definition: Classes.php:121
static getXmlAttributeValues(\SimpleXMLElement $xml, $xPath, $attributeName)
Definition: Classes.php:90
_assertNonFactoryName($names, $file, $softComparison=false, $moduleBlock=false)

◆ testLayouts()

testLayouts ( )
Parameters
string$path

Definition at line 58 of file ClassesTest.php.

59  {
60  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
61  $invoker(
65  function ($path) {
66  $xml = simplexml_load_file($path);
68  foreach (\Magento\Framework\App\Utility\Classes::getXmlAttributeValues(
69  $xml,
70  '/layout//@helper',
71  'helper'
72  ) as $class) {
74  }
75  $classes = array_merge(
76  $classes,
77  \Magento\Framework\App\Utility\Classes::getXmlAttributeValues($xml, '/layout//@module', 'module')
78  );
79  $this->_assertNonFactoryName(array_unique($classes), $path);
80 
82  $xml,
83  '/layout//action[@method="addTab"]/block'
84  );
85  $this->_assertNonFactoryName(array_unique($tabs), $path, true);
86  },
87  Files::init()->getLayoutFiles()
88  );
89  }
static getCallbackClass($callbackName)
Definition: Classes.php:109
static collectLayoutClasses(\SimpleXMLElement $xml)
Definition: Classes.php:160
$_option $_optionId $class
Definition: date.phtml:13
_assertNonFactoryName($names, $file, $softComparison=false, $moduleBlock=false)
static getXmlNodeValues(\SimpleXMLElement $xml, $xPath)
Definition: Classes.php:55

◆ testPhpCode()

testPhpCode ( )
Parameters
string$file

Definition at line 16 of file ClassesTest.php.

17  {
18  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
19  $invoker(
23  function ($file) {
25  $this->_assertNonFactoryName($classes, $file);
26  },
27  Files::init()->getPhpFiles(
34  )
35  );
36  }
static collectPhpCodeClasses($contents, &$classes=[])
Definition: Classes.php:294
_assertNonFactoryName($names, $file, $softComparison=false, $moduleBlock=false)

The documentation for this class was generated from the following file: