Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
CodeSnifferTest.php
Go to the documentation of this file.
1 <?php
7 
8 use PHP_CodeSniffer\Runner;
9 
10 class CodeSnifferTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_tool;
16 
20  protected $_wrapper;
21 
25  const RULE_SET = 'some/ruleset/directory';
26 
30  const REPORT_FILE = 'some/report/file.xml';
31 
32  protected function setUp()
33  {
34  $this->_wrapper = $this->createMock(\Magento\TestFramework\CodingStandard\Tool\CodeSniffer\Wrapper::class);
35  $this->_tool = new \Magento\TestFramework\CodingStandard\Tool\CodeSniffer(
36  self::RULE_SET,
37  self::REPORT_FILE,
38  $this->_wrapper
39  );
40  }
41 
42  public function testRun()
43  {
44  $whiteList = ['test' . rand(), 'test' . rand()];
45  $extensions = ['test' . rand(), 'test' . rand()];
46 
47  $expectedCliEmulation = [
48  'files' => $whiteList,
49  'standards' => [self::RULE_SET],
50  'extensions' => $extensions,
51  'warningSeverity' => 0,
52  'reports' => ['full' => self::REPORT_FILE],
53  ];
54 
55  $this->_tool->setExtensions($extensions);
56 
57  $this->_wrapper->expects($this->once())
58  ->method('setSettings')
59  ->with($this->equalTo($expectedCliEmulation));
60 
61  $this->_wrapper->expects($this->once())
62  ->method('runPHPCS');
63 
64  $this->_tool->run($whiteList);
65  }
66 }