/php/sdk/third_party/vfsstream/vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/vfsStreamWrapperTestCase.php

https://github.com/theosp/google_appengine · PHP · 783 lines · 489 code · 57 blank · 237 comment · 15 complexity · 419ccbf6a881c0556d0e2f16b7b76260 MD5 · raw file

  1. <?php
  2. /**
  3. * This file is part of vfsStream.
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @package org\bovigo\vfs
  9. */
  10. namespace org\bovigo\vfs;
  11. require_once __DIR__ . '/vfsStreamWrapperBaseTestCase.php';
  12. /**
  13. * Test for org\bovigo\vfs\vfsStreamWrapper.
  14. */
  15. class vfsStreamWrapperTestCase extends vfsStreamWrapperBaseTestCase
  16. {
  17. /**
  18. * ensure that a call to vfsStreamWrapper::register() resets the stream
  19. *
  20. * Implemented after a request by David Zülke.
  21. *
  22. * @test
  23. */
  24. public function resetByRegister()
  25. {
  26. $this->assertSame($this->foo, vfsStreamWrapper::getRoot());
  27. vfsStreamWrapper::register();
  28. $this->assertNull(vfsStreamWrapper::getRoot());
  29. }
  30. /**
  31. * @test
  32. * @since 0.11.0
  33. */
  34. public function setRootReturnsRoot()
  35. {
  36. vfsStreamWrapper::register();
  37. $root = vfsStream::newDirectory('root');
  38. $this->assertSame($root, vfsStreamWrapper::setRoot($root));
  39. }
  40. /**
  41. * assure that filesize is returned correct
  42. *
  43. * @test
  44. */
  45. public function filesize()
  46. {
  47. $this->assertEquals(0, filesize($this->fooURL));
  48. $this->assertEquals(0, filesize($this->fooURL . '/.'));
  49. $this->assertEquals(0, filesize($this->barURL));
  50. $this->assertEquals(0, filesize($this->barURL . '/.'));
  51. $this->assertEquals(4, filesize($this->baz2URL));
  52. $this->assertEquals(5, filesize($this->baz1URL));
  53. }
  54. /**
  55. * assert that file_exists() delivers correct result
  56. *
  57. * @test
  58. */
  59. public function file_exists()
  60. {
  61. $this->assertTrue(file_exists($this->fooURL));
  62. $this->assertTrue(file_exists($this->fooURL . '/.'));
  63. $this->assertTrue(file_exists($this->barURL));
  64. $this->assertTrue(file_exists($this->barURL . '/.'));
  65. $this->assertTrue(file_exists($this->baz1URL));
  66. $this->assertTrue(file_exists($this->baz2URL));
  67. $this->assertFalse(file_exists($this->fooURL . '/another'));
  68. $this->assertFalse(file_exists(vfsStream::url('another')));
  69. }
  70. /**
  71. * assert that filemtime() delivers correct result
  72. *
  73. * @test
  74. */
  75. public function filemtime()
  76. {
  77. $this->assertEquals(100, filemtime($this->fooURL));
  78. $this->assertEquals(100, filemtime($this->fooURL . '/.'));
  79. $this->assertEquals(200, filemtime($this->barURL));
  80. $this->assertEquals(200, filemtime($this->barURL . '/.'));
  81. $this->assertEquals(300, filemtime($this->baz1URL));
  82. $this->assertEquals(400, filemtime($this->baz2URL));
  83. }
  84. /**
  85. * @test
  86. * @group issue_23
  87. */
  88. public function unlinkRemovesFilesOnly()
  89. {
  90. $this->assertTrue(unlink($this->baz2URL));
  91. $this->assertFalse(file_exists($this->baz2URL)); // make sure statcache was cleared
  92. $this->assertEquals(array($this->bar), $this->foo->getChildren());
  93. $this->assertFalse(unlink($this->fooURL . '/another'));
  94. $this->assertFalse(unlink(vfsStream::url('another')));
  95. $this->assertEquals(array($this->bar), $this->foo->getChildren());
  96. }
  97. /**
  98. * @test
  99. * @group issue_49
  100. */
  101. public function unlinkReturnsFalseWhenFileDoesNotExist()
  102. {
  103. vfsStream::setup()->addChild(vfsStream::newFile('foo.blubb'));
  104. $this->assertFalse(unlink(vfsStream::url('foo.blubb2')));
  105. }
  106. /**
  107. * @test
  108. * @group issue_49
  109. */
  110. public function unlinkReturnsFalseWhenFileDoesNotExistAndFileWithSameNameExistsInRoot()
  111. {
  112. vfsStream::setup()->addChild(vfsStream::newFile('foo.blubb'));
  113. $this->assertFalse(unlink(vfsStream::url('foo.blubb')));
  114. }
  115. /**
  116. * assert dirname() returns correct directory name
  117. *
  118. * @test
  119. */
  120. public function dirname()
  121. {
  122. $this->assertEquals($this->fooURL, dirname($this->barURL));
  123. $this->assertEquals($this->barURL, dirname($this->baz1URL));
  124. # returns "vfs:" instead of "."
  125. # however this seems not to be fixable because dirname() does not
  126. # call the stream wrapper
  127. #$this->assertEquals(dirname(vfsStream::url('doesNotExist')), '.');
  128. }
  129. /**
  130. * assert basename() returns correct file name
  131. *
  132. * @test
  133. */
  134. public function basename()
  135. {
  136. $this->assertEquals('bar', basename($this->barURL));
  137. $this->assertEquals('baz1', basename($this->baz1URL));
  138. $this->assertEquals('doesNotExist', basename(vfsStream::url('doesNotExist')));
  139. }
  140. /**
  141. * assert is_readable() works correct
  142. *
  143. * @test
  144. */
  145. public function is_readable()
  146. {
  147. $this->assertTrue(is_readable($this->fooURL));
  148. $this->assertTrue(is_readable($this->fooURL . '/.'));
  149. $this->assertTrue(is_readable($this->barURL));
  150. $this->assertTrue(is_readable($this->barURL . '/.'));
  151. $this->assertTrue(is_readable($this->baz1URL));
  152. $this->assertTrue(is_readable($this->baz2URL));
  153. $this->assertFalse(is_readable($this->fooURL . '/another'));
  154. $this->assertFalse(is_readable(vfsStream::url('another')));
  155. $this->foo->chmod(0222);
  156. $this->assertFalse(is_readable($this->fooURL));
  157. $this->baz1->chmod(0222);
  158. $this->assertFalse(is_readable($this->baz1URL));
  159. }
  160. /**
  161. * assert is_writable() works correct
  162. *
  163. * @test
  164. */
  165. public function is_writable()
  166. {
  167. $this->assertTrue(is_writable($this->fooURL));
  168. $this->assertTrue(is_writable($this->fooURL . '/.'));
  169. $this->assertTrue(is_writable($this->barURL));
  170. $this->assertTrue(is_writable($this->barURL . '/.'));
  171. $this->assertTrue(is_writable($this->baz1URL));
  172. $this->assertTrue(is_writable($this->baz2URL));
  173. $this->assertFalse(is_writable($this->fooURL . '/another'));
  174. $this->assertFalse(is_writable(vfsStream::url('another')));
  175. $this->foo->chmod(0444);
  176. $this->assertFalse(is_writable($this->fooURL));
  177. $this->baz1->chmod(0444);
  178. $this->assertFalse(is_writable($this->baz1URL));
  179. }
  180. /**
  181. * assert is_executable() works correct
  182. *
  183. * @test
  184. */
  185. public function is_executable()
  186. {
  187. $this->assertFalse(is_executable($this->baz1URL));
  188. $this->baz1->chmod(0766);
  189. $this->assertTrue(is_executable($this->baz1URL));
  190. $this->assertFalse(is_executable($this->baz2URL));
  191. }
  192. /**
  193. * assert is_executable() works correct
  194. *
  195. * @test
  196. */
  197. public function directoriesAndNonExistingFilesAreNeverExecutable()
  198. {
  199. $this->assertFalse(is_executable($this->fooURL));
  200. $this->assertFalse(is_executable($this->fooURL . '/.'));
  201. $this->assertFalse(is_executable($this->barURL));
  202. $this->assertFalse(is_executable($this->barURL . '/.'));
  203. $this->assertFalse(is_executable($this->fooURL . '/another'));
  204. $this->assertFalse(is_executable(vfsStream::url('another')));
  205. }
  206. /**
  207. * file permissions
  208. *
  209. * @test
  210. * @group permissions
  211. */
  212. public function chmod()
  213. {
  214. $this->assertEquals(40777, decoct(fileperms($this->fooURL)));
  215. $this->assertEquals(40777, decoct(fileperms($this->fooURL . '/.')));
  216. $this->assertEquals(40777, decoct(fileperms($this->barURL)));
  217. $this->assertEquals(40777, decoct(fileperms($this->barURL . '/.')));
  218. $this->assertEquals(100666, decoct(fileperms($this->baz1URL)));
  219. $this->assertEquals(100666, decoct(fileperms($this->baz2URL)));
  220. $this->foo->chmod(0755);
  221. $this->bar->chmod(0700);
  222. $this->baz1->chmod(0644);
  223. $this->baz2->chmod(0600);
  224. $this->assertEquals(40755, decoct(fileperms($this->fooURL)));
  225. $this->assertEquals(40755, decoct(fileperms($this->fooURL . '/.')));
  226. $this->assertEquals(40700, decoct(fileperms($this->barURL)));
  227. $this->assertEquals(40700, decoct(fileperms($this->barURL . '/.')));
  228. $this->assertEquals(100644, decoct(fileperms($this->baz1URL)));
  229. $this->assertEquals(100600, decoct(fileperms($this->baz2URL)));
  230. }
  231. /**
  232. * @test
  233. * @group issue_11
  234. * @group permissions
  235. */
  236. public function chmodModifiesPermissions()
  237. {
  238. if (version_compare(phpversion(), '5.4.0', '<')) {
  239. $this->assertFalse(@chmod($this->fooURL, 0755));
  240. $this->assertFalse(@chmod($this->barURL, 0711));
  241. $this->assertFalse(@chmod($this->baz1URL, 0644));
  242. $this->assertFalse(@chmod($this->baz2URL, 0664));
  243. $this->assertEquals(40777, decoct(fileperms($this->fooURL)));
  244. $this->assertEquals(40777, decoct(fileperms($this->barURL)));
  245. $this->assertEquals(100666, decoct(fileperms($this->baz1URL)));
  246. $this->assertEquals(100666, decoct(fileperms($this->baz2URL)));
  247. } else {
  248. $this->assertTrue(chmod($this->fooURL, 0755));
  249. $this->assertTrue(chmod($this->barURL, 0711));
  250. $this->assertTrue(chmod($this->baz1URL, 0644));
  251. $this->assertTrue(chmod($this->baz2URL, 0664));
  252. $this->assertEquals(40755, decoct(fileperms($this->fooURL)));
  253. $this->assertEquals(40711, decoct(fileperms($this->barURL)));
  254. $this->assertEquals(100644, decoct(fileperms($this->baz1URL)));
  255. $this->assertEquals(100664, decoct(fileperms($this->baz2URL)));
  256. }
  257. }
  258. /**
  259. * @test
  260. * @group permissions
  261. */
  262. public function fileownerIsCurrentUserByDefault()
  263. {
  264. $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->fooURL));
  265. $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->fooURL . '/.'));
  266. $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->barURL));
  267. $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->barURL . '/.'));
  268. $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->baz1URL));
  269. $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->baz2URL));
  270. }
  271. /**
  272. * @test
  273. * @group issue_11
  274. * @group permissions
  275. */
  276. public function chownChangesUser()
  277. {
  278. if (version_compare(phpversion(), '5.4.0', '<')) {
  279. $this->foo->chown(vfsStream::OWNER_USER_1);
  280. $this->bar->chown(vfsStream::OWNER_USER_1);
  281. $this->baz1->chown(vfsStream::OWNER_USER_2);
  282. $this->baz2->chown(vfsStream::OWNER_USER_2);
  283. } else {
  284. chown($this->fooURL, vfsStream::OWNER_USER_1);
  285. chown($this->barURL, vfsStream::OWNER_USER_1);
  286. chown($this->baz1URL, vfsStream::OWNER_USER_2);
  287. chown($this->baz2URL, vfsStream::OWNER_USER_2);
  288. }
  289. $this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->fooURL));
  290. $this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->fooURL . '/.'));
  291. $this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->barURL));
  292. $this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->barURL . '/.'));
  293. $this->assertEquals(vfsStream::OWNER_USER_2, fileowner($this->baz1URL));
  294. $this->assertEquals(vfsStream::OWNER_USER_2, fileowner($this->baz2URL));
  295. }
  296. /**
  297. * @test
  298. * @group issue_11
  299. * @group permissions
  300. */
  301. public function chownDoesNotWorkOnVfsStreamUrls()
  302. {
  303. if (version_compare(phpversion(), '5.4.0', '<')) {
  304. $this->assertFalse(@chown($this->fooURL, vfsStream::OWNER_USER_2));
  305. $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->fooURL));
  306. }
  307. }
  308. /**
  309. * @test
  310. * @group issue_11
  311. * @group permissions
  312. */
  313. public function groupIsCurrentGroupByDefault()
  314. {
  315. $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->fooURL));
  316. $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->fooURL . '/.'));
  317. $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->barURL));
  318. $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->barURL . '/.'));
  319. $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->baz1URL));
  320. $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->baz2URL));
  321. }
  322. /**
  323. * @test
  324. * @group issue_11
  325. * @group permissions
  326. */
  327. public function chgrp()
  328. {
  329. if (version_compare(phpversion(), '5.4.0', '<')) {
  330. $this->foo->chgrp(vfsStream::GROUP_USER_1);
  331. $this->bar->chgrp(vfsStream::GROUP_USER_1);
  332. $this->baz1->chgrp(vfsStream::GROUP_USER_2);
  333. $this->baz2->chgrp(vfsStream::GROUP_USER_2);
  334. } else {
  335. chgrp($this->fooURL, vfsStream::GROUP_USER_1);
  336. chgrp($this->barURL, vfsStream::GROUP_USER_1);
  337. chgrp($this->baz1URL, vfsStream::GROUP_USER_2);
  338. chgrp($this->baz2URL, vfsStream::GROUP_USER_2);
  339. }
  340. $this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->fooURL));
  341. $this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->fooURL . '/.'));
  342. $this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->barURL));
  343. $this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->barURL . '/.'));
  344. $this->assertEquals(vfsStream::GROUP_USER_2, filegroup($this->baz1URL));
  345. $this->assertEquals(vfsStream::GROUP_USER_2, filegroup($this->baz2URL));
  346. }
  347. /**
  348. * @test
  349. * @group issue_11
  350. * @group permissions
  351. */
  352. public function chgrpDoesNotWorkOnVfsStreamUrls()
  353. {
  354. if (version_compare(phpversion(), '5.4.0', '<')) {
  355. $this->assertFalse(@chgrp($this->fooURL, vfsStream::GROUP_USER_2));
  356. $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->fooURL));
  357. }
  358. }
  359. /**
  360. * @test
  361. * @author Benoit Aubuchon
  362. */
  363. public function renameDirectory()
  364. {
  365. // move foo/bar to foo/baz3
  366. $baz3URL = vfsStream::url('foo/baz3');
  367. $this->assertTrue(rename($this->barURL, $baz3URL));
  368. $this->assertFileExists($baz3URL);
  369. $this->assertFileNotExists($this->barURL);
  370. }
  371. /**
  372. * @test
  373. */
  374. public function renameDirectoryWithDots()
  375. {
  376. // move foo/bar to foo/baz3
  377. $baz3URL = vfsStream::url('foo/baz3');
  378. $this->assertTrue(rename($this->barURL . '/.', $baz3URL));
  379. $this->assertFileExists($baz3URL);
  380. $this->assertFileNotExists($this->barURL);
  381. }
  382. /**
  383. * @test
  384. * @group issue_9
  385. * @since 0.9.0
  386. */
  387. public function renameDirectoryWithDotsInTarget()
  388. {
  389. // move foo/bar to foo/baz3
  390. $baz3URL = vfsStream::url('foo/../foo/baz3/.');
  391. $this->assertTrue(rename($this->barURL . '/.', $baz3URL));
  392. $this->assertFileExists($baz3URL);
  393. $this->assertFileNotExists($this->barURL);
  394. }
  395. /**
  396. * @test
  397. * @author Benoit Aubuchon
  398. */
  399. public function renameDirectoryOverwritingExistingFile()
  400. {
  401. // move foo/bar to foo/baz2
  402. $this->assertTrue(rename($this->barURL, $this->baz2URL));
  403. $this->assertFileExists(vfsStream::url('foo/baz2/baz1'));
  404. $this->assertFileNotExists($this->barURL);
  405. }
  406. /**
  407. * @test
  408. * @expectedException PHPUnit_Framework_Error
  409. */
  410. public function renameFileIntoFile()
  411. {
  412. // foo/baz2 is a file, so it can not be turned into a directory
  413. $baz3URL = vfsStream::url('foo/baz2/baz3');
  414. $this->assertTrue(rename($this->baz1URL, $baz3URL));
  415. $this->assertFileExists($baz3URL);
  416. $this->assertFileNotExists($this->baz1URL);
  417. }
  418. /**
  419. * @test
  420. * @author Benoit Aubuchon
  421. */
  422. public function renameFileToDirectory()
  423. {
  424. // move foo/bar/baz1 to foo/baz3
  425. $baz3URL = vfsStream::url('foo/baz3');
  426. $this->assertTrue(rename($this->baz1URL, $baz3URL));
  427. $this->assertFileExists($this->barURL);
  428. $this->assertFileExists($baz3URL);
  429. $this->assertFileNotExists($this->baz1URL);
  430. }
  431. /**
  432. * assert that trying to rename from a non existing file trigger a warning
  433. *
  434. * @expectedException PHPUnit_Framework_Error
  435. * @test
  436. */
  437. public function renameOnSourceFileNotFound()
  438. {
  439. rename(vfsStream::url('notfound'), $this->baz1URL);
  440. }
  441. /**
  442. * assert that trying to rename to a directory that is not found trigger a warning
  443. * @expectedException PHPUnit_Framework_Error
  444. * @test
  445. */
  446. public function renameOnDestinationDirectoryFileNotFound()
  447. {
  448. rename($this->baz1URL, vfsStream::url('foo/notfound/file2'));
  449. }
  450. /**
  451. * stat() and fstat() should return the same result
  452. *
  453. * @test
  454. */
  455. public function statAndFstatReturnSameResult()
  456. {
  457. $fp = fopen($this->baz2URL, 'r');
  458. $this->assertEquals(stat($this->baz2URL),
  459. fstat($fp)
  460. );
  461. fclose($fp);
  462. }
  463. /**
  464. * stat() returns full data
  465. *
  466. * @test
  467. */
  468. public function statReturnsFullDataForFiles()
  469. {
  470. $this->assertEquals(array(0 => 0,
  471. 1 => 0,
  472. 2 => 0100666,
  473. 3 => 0,
  474. 4 => vfsStream::getCurrentUser(),
  475. 5 => vfsStream::getCurrentGroup(),
  476. 6 => 0,
  477. 7 => 4,
  478. 8 => 400,
  479. 9 => 400,
  480. 10 => 400,
  481. 11 => -1,
  482. 12 => -1,
  483. 'dev' => 0,
  484. 'ino' => 0,
  485. 'mode' => 0100666,
  486. 'nlink' => 0,
  487. 'uid' => vfsStream::getCurrentUser(),
  488. 'gid' => vfsStream::getCurrentGroup(),
  489. 'rdev' => 0,
  490. 'size' => 4,
  491. 'atime' => 400,
  492. 'mtime' => 400,
  493. 'ctime' => 400,
  494. 'blksize' => -1,
  495. 'blocks' => -1
  496. ),
  497. stat($this->baz2URL)
  498. );
  499. }
  500. /**
  501. * @test
  502. */
  503. public function statReturnsFullDataForDirectories()
  504. {
  505. $this->assertEquals(array(0 => 0,
  506. 1 => 0,
  507. 2 => 0040777,
  508. 3 => 0,
  509. 4 => vfsStream::getCurrentUser(),
  510. 5 => vfsStream::getCurrentGroup(),
  511. 6 => 0,
  512. 7 => 0,
  513. 8 => 100,
  514. 9 => 100,
  515. 10 => 100,
  516. 11 => -1,
  517. 12 => -1,
  518. 'dev' => 0,
  519. 'ino' => 0,
  520. 'mode' => 0040777,
  521. 'nlink' => 0,
  522. 'uid' => vfsStream::getCurrentUser(),
  523. 'gid' => vfsStream::getCurrentGroup(),
  524. 'rdev' => 0,
  525. 'size' => 0,
  526. 'atime' => 100,
  527. 'mtime' => 100,
  528. 'ctime' => 100,
  529. 'blksize' => -1,
  530. 'blocks' => -1
  531. ),
  532. stat($this->fooURL)
  533. );
  534. }
  535. /**
  536. * @test
  537. */
  538. public function statReturnsFullDataForDirectoriesWithDot()
  539. {
  540. $this->assertEquals(array(0 => 0,
  541. 1 => 0,
  542. 2 => 0040777,
  543. 3 => 0,
  544. 4 => vfsStream::getCurrentUser(),
  545. 5 => vfsStream::getCurrentGroup(),
  546. 6 => 0,
  547. 7 => 0,
  548. 8 => 100,
  549. 9 => 100,
  550. 10 => 100,
  551. 11 => -1,
  552. 12 => -1,
  553. 'dev' => 0,
  554. 'ino' => 0,
  555. 'mode' => 0040777,
  556. 'nlink' => 0,
  557. 'uid' => vfsStream::getCurrentUser(),
  558. 'gid' => vfsStream::getCurrentGroup(),
  559. 'rdev' => 0,
  560. 'size' => 0,
  561. 'atime' => 100,
  562. 'mtime' => 100,
  563. 'ctime' => 100,
  564. 'blksize' => -1,
  565. 'blocks' => -1
  566. ),
  567. stat($this->fooURL . '/.')
  568. );
  569. }
  570. /**
  571. * @test
  572. * @expectedException PHPUnit_Framework_Error
  573. */
  574. public function openFileWithoutDirectory()
  575. {
  576. vfsStreamWrapper::register();
  577. $this->assertFalse(file_get_contents(vfsStream::url('file.txt')));
  578. }
  579. /**
  580. * @test
  581. * @group issue_33
  582. * @since 1.1.0
  583. */
  584. public function truncateRemovesSuperflouosContent()
  585. {
  586. if (version_compare(PHP_VERSION, '5.4.0', '<')) {
  587. $this->markTestSkipped('Requires PHP 5.4');
  588. }
  589. $handle = fopen($this->baz1URL, "r+");
  590. $this->assertTrue(ftruncate($handle, 0));
  591. $this->assertEquals(0, filesize($this->baz1URL));
  592. $this->assertEquals('', file_get_contents($this->baz1URL));
  593. fclose($handle);
  594. }
  595. /**
  596. * @test
  597. * @group issue_33
  598. * @since 1.1.0
  599. */
  600. public function truncateToGreaterSizeAddsZeroBytes()
  601. {
  602. if (version_compare(PHP_VERSION, '5.4.0', '<')) {
  603. $this->markTestSkipped('Requires PHP 5.4');
  604. }
  605. $handle = fopen($this->baz1URL, "r+");
  606. $this->assertTrue(ftruncate($handle, 25));
  607. $this->assertEquals(25, filesize($this->baz1URL));
  608. $this->assertEquals("baz 1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
  609. file_get_contents($this->baz1URL));
  610. fclose($handle);
  611. }
  612. /**
  613. * @test
  614. * @group issue_11
  615. */
  616. public function touchCreatesNonExistingFile()
  617. {
  618. if (version_compare(PHP_VERSION, '5.4.0', '<')) {
  619. $this->markTestSkipped('Requires PHP 5.4');
  620. }
  621. $this->assertTrue(touch($this->fooURL . '/new.txt'));
  622. $this->assertTrue($this->foo->hasChild('new.txt'));
  623. }
  624. /**
  625. * @test
  626. * @group issue_11
  627. */
  628. public function touchChangesAccessAndModificationTimeForFile()
  629. {
  630. if (version_compare(PHP_VERSION, '5.4.0', '<')) {
  631. $this->markTestSkipped('Requires PHP 5.4');
  632. }
  633. $this->assertTrue(touch($this->baz1URL, 303, 313));
  634. $this->assertEquals(303, $this->baz1->filemtime());
  635. $this->assertEquals(313, $this->baz1->fileatime());
  636. }
  637. /**
  638. * @test
  639. * @group issue_11
  640. */
  641. public function touchDoesNotChangeTimesWhenNoTimesGiven()
  642. {
  643. if (version_compare(PHP_VERSION, '5.4.0', '<')) {
  644. $this->markTestSkipped('Requires PHP 5.4');
  645. }
  646. $this->assertTrue(touch($this->baz1URL));
  647. $this->assertEquals(300, $this->baz1->filemtime());
  648. $this->assertEquals(300, $this->baz1->fileatime());
  649. }
  650. /**
  651. * @test
  652. * @group issue_11
  653. */
  654. public function touchWithModifiedTimeChangesAccessAndModifiedTime()
  655. {
  656. if (version_compare(PHP_VERSION, '5.4.0', '<')) {
  657. $this->markTestSkipped('Requires PHP 5.4');
  658. }
  659. $this->assertTrue(touch($this->baz1URL, 303));
  660. $this->assertEquals(303, $this->baz1->filemtime());
  661. $this->assertEquals(303, $this->baz1->fileatime());
  662. }
  663. /**
  664. * @test
  665. * @group issue_11
  666. */
  667. public function touchChangesAccessAndModificationTimeForDirectory()
  668. {
  669. if (version_compare(PHP_VERSION, '5.4.0', '<')) {
  670. $this->markTestSkipped('Requires PHP 5.4');
  671. }
  672. $this->assertTrue(touch($this->fooURL, 303, 313));
  673. $this->assertEquals(303, $this->foo->filemtime());
  674. $this->assertEquals(313, $this->foo->fileatime());
  675. }
  676. /**
  677. * @test
  678. * @group issue_34
  679. * @since 1.2.0
  680. */
  681. public function pathesAreCorrectlySet()
  682. {
  683. $this->assertEquals(vfsStream::path($this->fooURL), $this->foo->path());
  684. $this->assertEquals(vfsStream::path($this->barURL), $this->bar->path());
  685. $this->assertEquals(vfsStream::path($this->baz1URL), $this->baz1->path());
  686. $this->assertEquals(vfsStream::path($this->baz2URL), $this->baz2->path());
  687. }
  688. /**
  689. * @test
  690. * @group issue_34
  691. * @since 1.2.0
  692. */
  693. public function urlsAreCorrectlySet()
  694. {
  695. $this->assertEquals($this->fooURL, $this->foo->url());
  696. $this->assertEquals($this->barURL, $this->bar->url());
  697. $this->assertEquals($this->baz1URL, $this->baz1->url());
  698. $this->assertEquals($this->baz2URL, $this->baz2->url());
  699. }
  700. /**
  701. * @test
  702. * @group issue_34
  703. * @since 1.2.0
  704. */
  705. public function pathIsUpdatedAfterMove()
  706. {
  707. // move foo/bar/baz1 to foo/baz3
  708. $baz3URL = vfsStream::url('foo/baz3');
  709. $this->assertTrue(rename($this->baz1URL, $baz3URL));
  710. $this->assertEquals(vfsStream::path($baz3URL), $this->baz1->path());
  711. }
  712. /**
  713. * @test
  714. * @group issue_34
  715. * @since 1.2.0
  716. */
  717. public function urlIsUpdatedAfterMove()
  718. {
  719. // move foo/bar/baz1 to foo/baz3
  720. $baz3URL = vfsStream::url('foo/baz3');
  721. $this->assertTrue(rename($this->baz1URL, $baz3URL));
  722. $this->assertEquals($baz3URL, $this->baz1->url());
  723. }
  724. }
  725. ?>