FilesystemTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Repository;
  12. use Composer\Downloader\Util\Filesystem;
  13. use Composer\Test\TestCase;
  14. class FilesystemTest extends TestCase
  15. {
  16. /**
  17. * @dataProvider providePathCouplesAsCode
  18. */
  19. public function testFindShortestPathCode($a, $b, $expected)
  20. {
  21. $fs = new Filesystem;
  22. $this->assertEquals($expected, $fs->findShortestPathCode($a, $b));
  23. }
  24. public function providePathCouplesAsCode()
  25. {
  26. return array(
  27. array('/foo/bar', '/foo/bar', "__FILE__"),
  28. array('/foo/bar', '/foo/baz', "__DIR__.'/baz'"),
  29. array('/foo/bin/run', '/foo/vendor/acme/bin/run', "dirname(__DIR__).'/vendor/acme/bin/run'"),
  30. array('/foo/bin/run', '/foo/vendor/acme/bin/run', "dirname(__DIR__).'/vendor/acme/bin/run'"),
  31. array('/foo/bin/run', '/bar/bin/run', "'/bar/bin/run'"),
  32. array('c:/bin/run', 'c:/vendor/acme/bin/run', "dirname(__DIR__).'/vendor/acme/bin/run'"),
  33. array('c:\\bin\\run', 'c:/vendor/acme/bin/run', "dirname(__DIR__).'/vendor/acme/bin/run'"),
  34. array('c:/bin/run', 'd:/vendor/acme/bin/run', "'d:/vendor/acme/bin/run'"),
  35. array('c:\\bin\\run', 'd:/vendor/acme/bin/run', "'d:/vendor/acme/bin/run'"),
  36. );
  37. }
  38. /**
  39. * @dataProvider providePathCouples
  40. */
  41. public function testFindShortestPath($a, $b, $expected)
  42. {
  43. $fs = new Filesystem;
  44. $this->assertEquals($expected, $fs->findShortestPath($a, $b));
  45. }
  46. public function providePathCouples()
  47. {
  48. return array(
  49. array('/foo/bar', '/foo/bar', "./bar"),
  50. array('/foo/bar', '/foo/baz', "./baz"),
  51. array('/foo/bin/run', '/foo/vendor/acme/bin/run', "../vendor/acme/bin/run"),
  52. array('/foo/bin/run', '/foo/vendor/acme/bin/run', "../vendor/acme/bin/run"),
  53. array('/foo/bin/run', '/bar/bin/run', "/bar/bin/run"),
  54. array('c:/bin/run', 'c:/vendor/acme/bin/run', "../vendor/acme/bin/run"),
  55. array('c:\\bin\\run', 'c:/vendor/acme/bin/run', "../vendor/acme/bin/run"),
  56. array('c:/bin/run', 'd:/vendor/acme/bin/run', "d:/vendor/acme/bin/run"),
  57. array('c:\\bin\\run', 'd:/vendor/acme/bin/run', "d:/vendor/acme/bin/run"),
  58. );
  59. }
  60. }