Nenhuma descrição

HTMLTest.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\Html;
  11. use SebastianBergmann\CodeCoverage\TestCase;
  12. class HTMLTest 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 . 'HTML';
  19. }
  20. protected function tearDown()
  21. {
  22. parent::tearDown();
  23. $tmpFilesIterator = new \RecursiveIteratorIterator(
  24. new \RecursiveDirectoryIterator(self::$TEST_TMP_PATH, \RecursiveDirectoryIterator::SKIP_DOTS),
  25. \RecursiveIteratorIterator::CHILD_FIRST
  26. );
  27. foreach ($tmpFilesIterator as $path => $fileInfo) {
  28. /* @var \SplFileInfo $fileInfo */
  29. $pathname = $fileInfo->getPathname();
  30. $fileInfo->isDir() ? rmdir($pathname) : unlink($pathname);
  31. }
  32. }
  33. public function testForBankAccountTest()
  34. {
  35. $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForBankAccount';
  36. $report = new Facade;
  37. $report->process($this->getCoverageForBankAccount(), self::$TEST_TMP_PATH);
  38. $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH);
  39. }
  40. public function testForFileWithIgnoredLines()
  41. {
  42. $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForFileWithIgnoredLines';
  43. $report = new Facade;
  44. $report->process($this->getCoverageForFileWithIgnoredLines(), self::$TEST_TMP_PATH);
  45. $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH);
  46. }
  47. public function testForClassWithAnonymousFunction()
  48. {
  49. $expectedFilesPath =
  50. self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForClassWithAnonymousFunction';
  51. $report = new Facade;
  52. $report->process($this->getCoverageForClassWithAnonymousFunction(), self::$TEST_TMP_PATH);
  53. $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH);
  54. }
  55. /**
  56. * @param string $expectedFilesPath
  57. * @param string $actualFilesPath
  58. */
  59. private function assertFilesEquals($expectedFilesPath, $actualFilesPath)
  60. {
  61. $expectedFilesIterator = new \FilesystemIterator($expectedFilesPath);
  62. $actualFilesIterator = new \RegexIterator(new \FilesystemIterator($actualFilesPath), '/.html/');
  63. $this->assertEquals(
  64. iterator_count($expectedFilesIterator),
  65. iterator_count($actualFilesIterator),
  66. 'Generated files and expected files not match'
  67. );
  68. foreach ($expectedFilesIterator as $path => $fileInfo) {
  69. /* @var \SplFileInfo $fileInfo */
  70. $filename = $fileInfo->getFilename();
  71. $actualFile = $actualFilesPath . DIRECTORY_SEPARATOR . $filename;
  72. $this->assertFileExists($actualFile);
  73. $this->assertStringMatchesFormatFile(
  74. $fileInfo->getPathname(),
  75. str_replace(PHP_EOL, "\n", file_get_contents($actualFile)),
  76. "${filename} not match"
  77. );
  78. }
  79. }
  80. }