Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TypeDuplicationTest.php
Go to the documentation of this file.
1 <?php
7 
8 require_once '_files/ClassesForTypeDuplication.php';
9 class TypeDuplicationTest extends \PHPUnit\Framework\TestCase
10 {
14  protected $_validator;
15 
19  protected $_fixturePath;
20 
21  protected function setUp()
22  {
23  $path = realpath(__DIR__) . '/' . '_files' . '/' . 'ClassesForTypeDuplication.php';
24  $this->_fixturePath = str_replace('\\', '/', $path);
25  $this->_validator = new \Magento\Framework\Code\Validator\TypeDuplication();
26  }
27 
32  public function testValidClasses($className)
33  {
34  $this->assertTrue($this->_validator->validate($className));
35  }
36 
40  public function validClassesDataProvider()
41  {
42  return [
43  'Duplicated interface injection' => ['\TypeDuplication\ValidClassWithTheSameInterfaceTypeArguments'],
44  'Class with sub type arguments' => ['\TypeDuplication\ValidClassWithSubTypeArguments'],
45  'Class with SuppressWarnings' => ['\TypeDuplication\ValidClassWithSuppressWarnings']
46  ];
47  }
48 
49  public function testInvalidClass()
50  {
51  $message = 'Argument type duplication in class TypeDuplication\InvalidClassWithDuplicatedTypes in ' .
52  $this->_fixturePath .
53  PHP_EOL .
54  'Multiple type injection [\TypeDuplication\ArgumentBaseClass]';
55  $this->expectException(\Magento\Framework\Exception\ValidatorException::class);
56  $this->expectExceptionMessage($message);
57  $this->_validator->validate('\TypeDuplication\InvalidClassWithDuplicatedTypes');
58  }
59 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$message
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31