-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhpcpdRunner.php
74 lines (60 loc) · 1.84 KB
/
PhpcpdRunner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Test\Php;
use Magento\Framework\App\Utility\Files;
use Magento\TestFramework\CodingStandard\Tool\LiveCodePhpcpdRunner;
use PHPMD\TextUI\Command;
/**
* Set of tests for static code analysis, e.g. code style, code complexity, copy paste detecting, etc.
*/
class PhpcpdRunner extends \PHPUnit\Framework\TestCase
{
/**
* @var string
*/
protected static $reportDir = '';
/**
* @var string
*/
protected static $pathToSource = '';
/**
* Setup basics for all tests
*
* @return void
*/
public static function setUpBeforeClass(): void
{
self::$pathToSource = BP;
self::$reportDir = self::$pathToSource . '/dev/tests/static/report';
if (!is_dir(self::$reportDir)) {
mkdir(self::$reportDir);
}
}
/**
* Test code quality using phpcpd
*/
public function testCopyPaste()
{
$reportFile = self::$reportDir . '/phpcpd_report.xml';
$copyPasteDetector = new LiveCodePhpcpdRunner($reportFile);
if (!$copyPasteDetector->canRun()) {
$this->markTestSkipped('PHP Copy/Paste Detector is not available.');
}
$blackList = [];
foreach (glob(__DIR__ . '/_files/phpcpd/blacklist/*.txt') as $list) {
$blackList[] = file($list, FILE_IGNORE_NEW_LINES);
}
$blackList = array_merge([], ...$blackList);
$copyPasteDetector->setBlackList($blackList);
$result = $copyPasteDetector->run([]);
$output = file_exists($reportFile) ? file_get_contents($reportFile) : '';
$this->assertTrue(
$result,
"PHP Copy/Paste Detector has found error(s):" . PHP_EOL . $output
);
}
}