Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConstructorIntegrityTest.php
Go to the documentation of this file.
1 <?php
7 
8 require_once __DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Three/Test.php';
9 require_once __DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Two/Test.php';
10 require_once __DIR__ . '/../_files/app/code/Magento/SomeModule/Model/One/Test.php';
11 require_once __DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Four/Test.php';
12 require_once __DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Five/Test.php';
13 require_once __DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Six/Test.php';
14 require_once __DIR__ . '/_files/ClassesForConstructorIntegrity.php';
15 class ConstructorIntegrityTest extends \PHPUnit\Framework\TestCase
16 {
20  protected $_model;
21 
22  protected function setUp()
23  {
24  $this->_model = new \Magento\Framework\Code\Validator\ConstructorIntegrity();
25  }
26 
28  {
29  $this->assertEquals(true, $this->_model->validate(\Magento\SomeModule\Model\One\Test::class));
30  }
31 
33  {
34  $this->assertEquals(true, $this->_model->validate(\Magento\SomeModule\Model\Two\Test::class));
35  }
36 
38  {
39  $this->assertEquals(true, $this->_model->validate(\Magento\SomeModule\Model\Three\Test::class));
40  }
41 
43  {
44  $fileName = realpath(__DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Four/Test.php');
45  $fileName = str_replace('\\', '/', $fileName);
46  $this->expectException(\Magento\Framework\Exception\ValidatorException::class);
47  $this->expectExceptionMessage('Extra parameters passed to parent construct: $factory. File: ' . $fileName);
48  $this->_model->validate(\Magento\SomeModule\Model\Four\Test::class);
49  }
50 
52  {
53  $fileName = realpath(__DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Five/Test.php');
54  $fileName = str_replace('\\', '/', $fileName);
55  $this->expectException(\Magento\Framework\Exception\ValidatorException::class);
56  $this->expectExceptionMessage(
57  'Missed required argument factory in parent::__construct call. File: ' . $fileName
58  );
59  $this->_model->validate(\Magento\SomeModule\Model\Five\Test::class);
60  }
61 
63  {
64  $fileName = realpath(__DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Six/Test.php');
65  $fileName = str_replace('\\', '/', $fileName);
66  $this->expectException(\Magento\Framework\Exception\ValidatorException::class);
67  $this->expectExceptionMessage(
68  'Incompatible argument type: Required type: \Magento\SomeModule\Model\Proxy. ' .
69  'Actual type: \Magento\SomeModule\Model\ElementFactory; File: ' .
70  PHP_EOL .
71  $fileName
72  );
73  $this->_model->validate(\Magento\SomeModule\Model\Six\Test::class);
74  }
75 
77  {
78  $fileName = realpath(__DIR__) . '/_files/ClassesForConstructorIntegrity.php';
79  $fileName = str_replace('\\', '/', $fileName);
80  $this->expectException(\Magento\Framework\Exception\ValidatorException::class);
81  $this->expectExceptionMessage(
82  'Incompatible argument type: Required type: \Context. ' .
83  'Actual type: \ClassA; File: ' .
84  PHP_EOL .
85  $fileName
86  );
87  $this->_model->validate('ClassArgumentWrongOrderForParentArguments');
88  }
89 
91  {
92  $fileName = realpath(__DIR__) . '/_files/ClassesForConstructorIntegrity.php';
93  $fileName = str_replace('\\', '/', $fileName);
94  $this->expectException(\Magento\Framework\Exception\ValidatorException::class);
95  $this->expectExceptionMessage(
96  'Incompatible argument type: Required type: array. ' . 'Actual type: \ClassB; File: ' . PHP_EOL . $fileName
97  );
98  $this->_model->validate('ClassArgumentWithWrongParentArgumentsType');
99  }
100 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$fileName
Definition: translate.phtml:15