XMLTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /*
  3. * This file is part of the php-code-coverage package.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\CodeCoverage\Report\Xml;
  11. use SebastianBergmann\CodeCoverage\TestCase;
  12. class XmlTest extends TestCase
  13. {
  14. private static $TEST_REPORT_PATH_SOURCE;
  15. public static function setUpBeforeClass()
  16. {
  17. parent::setUpBeforeClass();
  18. self::$TEST_REPORT_PATH_SOURCE = TEST_FILES_PATH . 'Report' . DIRECTORY_SEPARATOR . 'XML';
  19. }
  20. protected function tearDown()
  21. {
  22. parent::tearDown();
  23. $tmpFilesIterator = new \FilesystemIterator(self::$TEST_TMP_PATH);
  24. foreach ($tmpFilesIterator as $path => $fileInfo) {
  25. /* @var \SplFileInfo $fileInfo */
  26. unlink($fileInfo->getPathname());
  27. }
  28. }
  29. public function testForBankAccountTest()
  30. {
  31. $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForBankAccount';
  32. $xml = new Facade('1.0.0');
  33. $xml->process($this->getCoverageForBankAccount(), self::$TEST_TMP_PATH);
  34. $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH);
  35. }
  36. public function testForFileWithIgnoredLines()
  37. {
  38. $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForFileWithIgnoredLines';
  39. $xml = new Facade('1.0.0');
  40. $xml->process($this->getCoverageForFileWithIgnoredLines(), self::$TEST_TMP_PATH);
  41. $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH);
  42. }
  43. public function testForClassWithAnonymousFunction()
  44. {
  45. $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForClassWithAnonymousFunction';
  46. $xml = new Facade('1.0.0');
  47. $xml->process($this->getCoverageForClassWithAnonymousFunction(), self::$TEST_TMP_PATH);
  48. $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH);
  49. }
  50. /**
  51. * @param string $expectedFilesPath
  52. * @param string $actualFilesPath
  53. */
  54. private function assertFilesEquals($expectedFilesPath, $actualFilesPath)
  55. {
  56. $expectedFilesIterator = new \FilesystemIterator($expectedFilesPath);
  57. $actualFilesIterator = new \FilesystemIterator($actualFilesPath);
  58. $this->assertEquals(
  59. iterator_count($expectedFilesIterator),
  60. iterator_count($actualFilesIterator),
  61. 'Generated files and expected files not match'
  62. );
  63. foreach ($expectedFilesIterator as $path => $fileInfo) {
  64. /* @var \SplFileInfo $fileInfo */
  65. $filename = $fileInfo->getFilename();
  66. $actualFile = $actualFilesPath . DIRECTORY_SEPARATOR . $filename;
  67. $this->assertFileExists($actualFile);
  68. $this->assertStringMatchesFormatFile(
  69. $fileInfo->getPathname(),
  70. file_get_contents($actualFile),
  71. "${filename} not match"
  72. );
  73. }
  74. }
  75. }