Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MethodAnnotationStructureSniffTest.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
11 class MethodAnnotationStructureSniffTest extends \PHPUnit\Framework\TestCase
12 {
16  public function processDataProvider()
17  {
18  return [
19  [
20  'MethodAnnotationFixture.php',
21  'method_annotation_errors.txt'
22  ]
23  ];
24  }
25 
32  private function copyFile($source, $destination): void
33  {
34  $sourcePath = $source;
35  $destinationPath = $destination;
36  $sourceDirectory = opendir($sourcePath);
37  while ($readFile = readdir($sourceDirectory)) {
38  if ($readFile != '.' && $readFile != '..') {
39  if (!file_exists($destinationPath . $readFile)) {
40  copy($sourcePath . $readFile, $destinationPath . $readFile);
41  }
42  }
43  }
44  closedir($sourceDirectory);
45  }
46 
52  public function testProcess($fileUnderTest, $expectedReportFile)
53  {
54  $reportFile = __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'phpcs_report.txt';
55  $this->copyFile(
56  __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR,
57  TESTS_TEMP_DIR
58  );
59  $codeSniffer = new \Magento\TestFramework\CodingStandard\Tool\CodeSniffer(
60  'Magento',
61  $reportFile,
62  new \Magento\TestFramework\CodingStandard\Tool\CodeSniffer\Wrapper()
63  );
64  $result = $codeSniffer->run(
65  [TESTS_TEMP_DIR . $fileUnderTest]
66  );
67  $actual = file_get_contents($reportFile);
68  $expected = file_get_contents(
69  TESTS_TEMP_DIR . $expectedReportFile
70  );
71  unlink($reportFile);
72  $this->assertEquals(2, $result);
73  $this->assertEquals($expected, $actual);
74  }
75 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$source
Definition: source.php:23