Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CodeCheckTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class CodeCheckTest extends \PHPUnit\Framework\TestCase
11 {
15  private $codeCheck;
16 
17  protected function setUp()
18  {
19  $this->codeCheck = new CodeCheck();
20  }
21 
27  public function testIsClassUsed($fileContent, $isClassUsed)
28  {
29  $this->assertEquals(
30  $isClassUsed,
31  $this->codeCheck->isClassUsed('MyClass', $fileContent)
32  );
33  }
34 
38  public function isClassUsedDataProvider()
39  {
40  return [
41  [file_get_contents(__DIR__ . '/_files/create_new_instance.txt'), true],
42  [file_get_contents(__DIR__ . '/_files/create_new_instance2.txt'), true],
43  [file_get_contents(__DIR__ . '/_files/create_new_instance3.txt'), true],
44  [file_get_contents(__DIR__ . '/_files/class_name_in_namespace_and_variable_name.txt'), false],
45  [file_get_contents(__DIR__ . '/_files/extends.txt'), true],
46  [file_get_contents(__DIR__ . '/_files/extends2.txt'), true],
47  [file_get_contents(__DIR__ . '/_files/use.txt'), true],
48  [file_get_contents(__DIR__ . '/_files/use2.txt'), true]
49  ];
50  }
51 
57  public function testIsDirectDescendant($fileContent, $isDirectDescendant)
58  {
59  $this->assertEquals(
60  $isDirectDescendant,
61  $this->codeCheck->isDirectDescendant($fileContent, 'MyClass')
62  );
63  }
64 
69  {
70  return [
71  [file_get_contents(__DIR__ . '/_files/extends.txt'), true],
72  [file_get_contents(__DIR__ . '/_files/extends2.txt'), true],
73  [file_get_contents(__DIR__ . '/_files/implements.txt'), true],
74  [file_get_contents(__DIR__ . '/_files/implements2.txt'), true]
75  ];
76  }
77 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
testIsClassUsed($fileContent, $isClassUsed)
testIsDirectDescendant($fileContent, $isDirectDescendant)