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 =
  46. self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForClassWithAnonymousFunction';
  47. $xml = new Facade('1.0.0');
  48. $xml->process($this->getCoverageForClassWithAnonymousFunction(), self::$TEST_TMP_PATH);
  49. $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH);
  50. }
  51. /**
  52. * @param string $expectedFilesPath
  53. * @param string $actualFilesPath
  54. */
  55. private function assertFilesEquals($expectedFilesPath, $actualFilesPath)
  56. {
  57. $expectedFilesIterator = new \FilesystemIterator($expectedFilesPath);
  58. $actualFilesIterator = new \FilesystemIterator($actualFilesPath);
  59. $this->assertEquals(
  60. iterator_count($expectedFilesIterator),
  61. iterator_count($actualFilesIterator),
  62. 'Generated files and expected files not match'
  63. );
  64. foreach ($expectedFilesIterator as $path => $fileInfo) {
  65. /* @var \SplFileInfo $fileInfo */
  66. $filename = $fileInfo->getFilename();
  67. $actualFile = $actualFilesPath . DIRECTORY_SEPARATOR . $filename;
  68. $this->assertFileExists($actualFile);
  69. $this->assertStringMatchesFormatFile(
  70. $fileInfo->getPathname(),
  71. file_get_contents($actualFile),
  72. "${filename} not match"
  73. );
  74. }
  75. }
  76. }