Drupal investigation

SplCasterTest.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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\VarDumperTestCase;
  12. /**
  13. * @author Grégoire Pineau <lyrixx@lyrixx.info>
  14. */
  15. class SplCasterTest extends VarDumperTestCase
  16. {
  17. public function getCastFileInfoTests()
  18. {
  19. return array(
  20. array(__FILE__, <<<'EOTXT'
  21. SplFileInfo {
  22. %Apath: "%sCaster"
  23. filename: "SplCasterTest.php"
  24. basename: "SplCasterTest.php"
  25. pathname: "%sSplCasterTest.php"
  26. extension: "php"
  27. realPath: "%sSplCasterTest.php"
  28. aTime: %s-%s-%d %d:%d:%d
  29. mTime: %s-%s-%d %d:%d:%d
  30. cTime: %s-%s-%d %d:%d:%d
  31. inode: %d
  32. size: %d
  33. perms: 0%d
  34. owner: %d
  35. group: %d
  36. type: "file"
  37. writable: true
  38. readable: true
  39. executable: false
  40. file: true
  41. dir: false
  42. link: false
  43. %A}
  44. EOTXT
  45. ),
  46. array('https://google.com/about', <<<'EOTXT'
  47. SplFileInfo {
  48. %Apath: "https://google.com"
  49. filename: "about"
  50. basename: "about"
  51. pathname: "https://google.com/about"
  52. extension: ""
  53. realPath: false
  54. %A}
  55. EOTXT
  56. ),
  57. );
  58. }
  59. /** @dataProvider getCastFileInfoTests */
  60. public function testCastFileInfo($file, $dump)
  61. {
  62. $this->assertDumpMatchesFormat($dump, new \SplFileInfo($file));
  63. }
  64. public function testCastFileObject()
  65. {
  66. $var = new \SplFileObject(__FILE__);
  67. $var->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
  68. $dump = <<<'EOTXT'
  69. SplFileObject {
  70. %Apath: "%sCaster"
  71. filename: "SplCasterTest.php"
  72. basename: "SplCasterTest.php"
  73. pathname: "%sSplCasterTest.php"
  74. extension: "php"
  75. realPath: "%sSplCasterTest.php"
  76. aTime: %s-%s-%d %d:%d:%d
  77. mTime: %s-%s-%d %d:%d:%d
  78. cTime: %s-%s-%d %d:%d:%d
  79. inode: %d
  80. size: %d
  81. perms: 0%d
  82. owner: %d
  83. group: %d
  84. type: "file"
  85. writable: true
  86. readable: true
  87. executable: false
  88. file: true
  89. dir: false
  90. link: false
  91. %AcsvControl: array:%d [
  92. 0 => ","
  93. 1 => """
  94. %A]
  95. flags: DROP_NEW_LINE|SKIP_EMPTY
  96. maxLineLen: 0
  97. fstat: array:26 [
  98. "dev" => %d
  99. "ino" => %d
  100. "nlink" => %d
  101. "rdev" => 0
  102. "blksize" => %i
  103. "blocks" => %i
  104. …20
  105. ]
  106. eof: false
  107. key: 0
  108. }
  109. EOTXT;
  110. $this->assertDumpMatchesFormat($dump, $var);
  111. }
  112. /**
  113. * @dataProvider provideCastSplDoublyLinkedList
  114. */
  115. public function testCastSplDoublyLinkedList($modeValue, $modeDump)
  116. {
  117. $var = new \SplDoublyLinkedList();
  118. $var->setIteratorMode($modeValue);
  119. $dump = <<<EOTXT
  120. SplDoublyLinkedList {
  121. %Amode: $modeDump
  122. dllist: []
  123. }
  124. EOTXT;
  125. $this->assertDumpMatchesFormat($dump, $var);
  126. }
  127. public function provideCastSplDoublyLinkedList()
  128. {
  129. return array(
  130. array(\SplDoublyLinkedList::IT_MODE_FIFO, 'IT_MODE_FIFO | IT_MODE_KEEP'),
  131. array(\SplDoublyLinkedList::IT_MODE_LIFO, 'IT_MODE_LIFO | IT_MODE_KEEP'),
  132. array(\SplDoublyLinkedList::IT_MODE_FIFO | \SplDoublyLinkedList::IT_MODE_DELETE, 'IT_MODE_FIFO | IT_MODE_DELETE'),
  133. array(\SplDoublyLinkedList::IT_MODE_LIFO | \SplDoublyLinkedList::IT_MODE_DELETE, 'IT_MODE_LIFO | IT_MODE_DELETE'),
  134. );
  135. }
  136. }