Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ClassAnnotationStructureSniffTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
8 
9 class ClassAnnotationStructureSniffTest extends \PHPUnit\Framework\TestCase
10 {
14  public function processDataProvider()
15  {
16  return [
17  [
18  'ClassAnnotationFixture.php',
19  'class_annotation_errors.txt',
20  ],
21  [
22  'AbstractClassAnnotationFixture.php',
23  'abstract_class_annotation_errors.txt',
24  ],
25  [
26  'ClassAnnotationNoShortDescriptionFixture.php',
27  'class_annotation_noshortdescription_errors.txt',
28  ],
29  [
30  'ClassAnnotationNoSpacingBetweenLinesFixture.php',
31  'class_annotation_nospacingbetweenLines_errors.txt',
32  ]
33  ];
34  }
35 
42  private function copyFile($source, $destination) : void
43  {
44  $sourcePath = $source;
45  $destinationPath = $destination;
46  $sourceDirectory = opendir($sourcePath);
47  while ($readFile = readdir($sourceDirectory)) {
48  if ($readFile != '.' && $readFile != '..') {
49  if (!file_exists($destinationPath . $readFile)) {
50  copy($sourcePath . $readFile, $destinationPath . $readFile);
51  }
52  }
53  }
54  closedir($sourceDirectory);
55  }
56 
62  public function testProcess($fileUnderTest, $expectedReportFile)
63  {
64  $reportFile = __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'phpcs_report.txt';
65  $this->copyFile(
66  __DIR__ . DIRECTORY_SEPARATOR . '_files'. DIRECTORY_SEPARATOR,
67  TESTS_TEMP_DIR
68  );
69  $codeSniffer = new \Magento\TestFramework\CodingStandard\Tool\CodeSniffer(
70  'Magento',
71  $reportFile,
72  new \Magento\TestFramework\CodingStandard\Tool\CodeSniffer\Wrapper()
73  );
74  $result = $codeSniffer->run(
75  [TESTS_TEMP_DIR . $fileUnderTest]
76  );
77  $actual = file_get_contents($reportFile);
78  $expected = file_get_contents(
79  TESTS_TEMP_DIR . $expectedReportFile
80  );
81  unlink($reportFile);
82  $this->assertEquals(2, $result);
83  $this->assertEquals($expected, $actual);
84  }
85 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$source
Definition: source.php:23