Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
InterfaceValidatorTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\Interception\Code\InterfaceValidator;
10 use \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\ItemPlugin\ValidPlugin;
11 use \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\ItemPlugin\IncompatibleInterface;
12 use \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\ItemPlugin\IncorrectSubject;
13 use \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\ItemPlugin\ExtraParameters;
14 use \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\ItemPlugin\InvalidProceed;
15 
16 class InterfaceValidatorTest extends \PHPUnit\Framework\TestCase
17 {
22 
26  protected $model;
27 
28  protected function setUp()
29  {
30  $this->argumentsReaderMock = $this->createMock(\Magento\Framework\Code\Reader\ArgumentsReader::class);
31 
32  $this->argumentsReaderMock->expects($this->any())->method('isCompatibleType')
33  ->will($this->returnCallback(function ($arg1, $arg2) {
34  return ltrim($arg1, '\\') == ltrim($arg2, '\\');
35  }));
36 
37  $this->model = new InterfaceValidator($this->argumentsReaderMock);
38  }
39 
48  public function testValidate()
49  {
50  $this->model->validate(
51  ValidPlugin::class,
52  \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\ItemWithArguments::class
53  );
54  }
55 
62  {
63  $this->model->validate(
64  IncompatibleInterface::class,
65  \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\Item::class
66  );
67  }
68 
75  {
76  $this->model->validate(
77  IncorrectSubject::class,
78  \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\Item::class
79  );
80  }
81 
89  {
90  $this->model->validate(
91  \Magento\Framework\Interception\Test\Unit\Custom\Module\Model::class .
92  '\InterfaceValidator\ItemPlugin\IncompatibleArgumentsCount',
93  \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\Item::class
94  );
95  }
96 
104  {
105  $this->model->validate(
106  \Magento\Framework\Interception\Test\Unit\Custom\Module\Model::class .
107  '\InterfaceValidator\ItemPlugin\IncompatibleArgumentsType',
108  \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\ItemWithArguments::class
109  );
110  }
111 
117  public function testValidateExtraParameters()
118  {
119  $this->model->validate(
120  ExtraParameters::class,
121  \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\Item::class
122  );
123  }
124 
130  public function testValidateInvalidProceed()
131  {
132  $this->model->validate(
133  InvalidProceed::class,
134  \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\InterfaceValidator\Item::class
135  );
136  }
137 }