SplCasterTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Component\VarDumper\Tests\Caster;
  11. use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
  12. /**
  13. * @author Grégoire Pineau <lyrixx@lyrixx.info>
  14. */
  15. class SplCasterTest extends \PHPUnit_Framework_TestCase
  16. {
  17. use VarDumperTestTrait;
  18. public function getCastFileInfoTests()
  19. {
  20. return array(
  21. array(__FILE__, <<<'EOTXT'
  22. SplFileInfo {
  23. %Apath: "%sCaster"
  24. filename: "SplCasterTest.php"
  25. basename: "SplCasterTest.php"
  26. pathname: "%sSplCasterTest.php"
  27. extension: "php"
  28. realPath: "%sSplCasterTest.php"
  29. aTime: %s-%s-%d %d:%d:%d
  30. mTime: %s-%s-%d %d:%d:%d
  31. cTime: %s-%s-%d %d:%d:%d
  32. inode: %d
  33. size: %d
  34. perms: 0%d
  35. owner: %d
  36. group: %d
  37. type: "file"
  38. writable: true
  39. readable: true
  40. executable: false
  41. file: true
  42. dir: false
  43. link: false
  44. %A}
  45. EOTXT
  46. ),
  47. array('https://google.com/about', <<<'EOTXT'
  48. SplFileInfo {
  49. %Apath: "https://google.com"
  50. filename: "about"
  51. basename: "about"
  52. pathname: "https://google.com/about"
  53. extension: ""
  54. realPath: false
  55. %A}
  56. EOTXT
  57. ),
  58. );
  59. }
  60. /** @dataProvider getCastFileInfoTests */
  61. public function testCastFileInfo($file, $dump)
  62. {
  63. $this->assertDumpMatchesFormat($dump, new \SplFileInfo($file));
  64. }
  65. public function testCastFileObject()
  66. {
  67. $var = new \SplFileObject(__FILE__);
  68. $var->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
  69. $dump = <<<'EOTXT'
  70. SplFileObject {
  71. %Apath: "%sCaster"
  72. filename: "SplCasterTest.php"
  73. basename: "SplCasterTest.php"
  74. pathname: "%sSplCasterTest.php"
  75. extension: "php"
  76. realPath: "%sSplCasterTest.php"
  77. aTime: %s-%s-%d %d:%d:%d
  78. mTime: %s-%s-%d %d:%d:%d
  79. cTime: %s-%s-%d %d:%d:%d
  80. inode: %d
  81. size: %d
  82. perms: 0%d
  83. owner: %d
  84. group: %d
  85. type: "file"
  86. writable: true
  87. readable: true
  88. executable: false
  89. file: true
  90. dir: false
  91. link: false
  92. %AcsvControl: array:2 [
  93. 0 => ","
  94. 1 => """
  95. ]
  96. flags: DROP_NEW_LINE|SKIP_EMPTY
  97. maxLineLen: 0
  98. fstat: array:26 [
  99. "dev" => %d
  100. "ino" => %d
  101. "nlink" => %d
  102. "rdev" => 0
  103. "blksize" => %i
  104. "blocks" => %i
  105. …20
  106. ]
  107. eof: false
  108. key: 0
  109. }
  110. EOTXT;
  111. $this->assertDumpMatchesFormat($dump, $var);
  112. }
  113. }