|
| 1 | +<?php |
| 2 | +use SebastianBergmann\PHPCPD\CodeClone; |
| 3 | +use SebastianBergmann\PHPCPD\CodeCloneFile; |
| 4 | +use SebastianBergmann\PHPCPD\CodeCloneMap; |
| 5 | +use SebastianBergmann\PHPCPD\Log\PMD; |
| 6 | + |
| 7 | +class PHPCPD_Log_PMDTest extends PHPUnit_Framework_TestCase |
| 8 | +{ |
| 9 | + /** @var string */ |
| 10 | + private $testFile1; |
| 11 | + /** @var @var string */ |
| 12 | + private $testFile2; |
| 13 | + /** @var string */ |
| 14 | + private $pmdLogFile; |
| 15 | + /** @var string */ |
| 16 | + private $expectedPmdLogFile; |
| 17 | + /** @var \SebastianBergmann\PHPCPD\Log\PMD */ |
| 18 | + private $pmdLogger; |
| 19 | + |
| 20 | + protected function setUp() |
| 21 | + { |
| 22 | + $this->testFile1 = __DIR__ . '/_files/with_ascii_escape.php'; |
| 23 | + $this->testFile2 = __DIR__ . '/_files/with_ascii_escape2.php'; |
| 24 | + |
| 25 | + $this->pmdLogFile = tempnam(sys_get_temp_dir(), 'pmd'); |
| 26 | + |
| 27 | + $this->expectedPmdLogFile = tempnam(sys_get_temp_dir(), 'pmd'); |
| 28 | + $expectedPmdLogTemplate = __DIR__ . '/_files/pmd_expected.xml'; |
| 29 | + $expectedPmdLogContents = strtr( |
| 30 | + file_get_contents($expectedPmdLogTemplate), |
| 31 | + array( |
| 32 | + '%file1%' => $this->testFile1, |
| 33 | + '%file2%' => $this->testFile2 |
| 34 | + ) |
| 35 | + ); |
| 36 | + file_put_contents($this->expectedPmdLogFile, $expectedPmdLogContents); |
| 37 | + |
| 38 | + $this->pmdLogger = new PMD($this->pmdLogFile); |
| 39 | + } |
| 40 | + |
| 41 | + protected function tearDown() |
| 42 | + { |
| 43 | + if (file_exists($this->pmdLogFile)) { |
| 44 | + unlink($this->pmdLogFile); |
| 45 | + } |
| 46 | + if (file_exists($this->expectedPmdLogFile)) { |
| 47 | + unlink($this->expectedPmdLogFile); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @covers SebastianBergmann\PHPCPD\Log\PMD |
| 53 | + * @covers SebastianBergmann\PHPCPD\Log\AbstractXmlLogger |
| 54 | + */ |
| 55 | + public function testSubstitutesDisallowedCharacters() |
| 56 | + { |
| 57 | + $file1 = new CodeCloneFile($this->testFile1, 8); |
| 58 | + $file2 = new CodeCloneFile($this->testFile2, 8); |
| 59 | + $clone = new CodeClone($file1, $file2, 4, 4); |
| 60 | + $cloneMap = new CodeCloneMap(); |
| 61 | + $cloneMap->addClone($clone); |
| 62 | + |
| 63 | + $this->pmdLogger->processClones($cloneMap); |
| 64 | + |
| 65 | + $this->assertXmlFileEqualsXmlFile( |
| 66 | + $this->expectedPmdLogFile, |
| 67 | + $this->pmdLogFile |
| 68 | + ); |
| 69 | + } |
| 70 | +} |
0 commit comments