You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6KB

  1. <?php
  2. /*
  3. * This file is part of the Fxp Composer Asset Plugin package.
  4. *
  5. * (c) François Pluchino <francois.pluchino@gmail.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 Fxp\Composer\AssetPlugin\Tests\Repository\Vcs;
  11. use Fxp\Composer\AssetPlugin\Repository\Vcs\Util;
  12. use Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs\MockVcsDriver;
  13. /**
  14. * Tests of util.
  15. *
  16. * @author François Pluchino <francois.pluchino@gmail.com>
  17. */
  18. class UtilTest extends \PHPUnit_Framework_TestCase
  19. {
  20. public function getDataProvider()
  21. {
  22. return array(
  23. array('key'),
  24. array('key.subkey'),
  25. array('key.subkey.subsubkey'),
  26. );
  27. }
  28. /**
  29. * @dataProvider getDataProvider
  30. */
  31. public function testAddComposerTimeWithSimpleKey($resourceKey)
  32. {
  33. $composer = array(
  34. 'name' => 'test',
  35. );
  36. $driver = new MockVcsDriver();
  37. $value = null;
  38. $keys = explode('.', $resourceKey);
  39. $start = count($keys) - 1;
  40. for ($i = $start; $i >= 0; --$i) {
  41. if (null === $value) {
  42. $value = 'level '.$i;
  43. }
  44. $value = array($keys[$i] => $value);
  45. }
  46. $driver->contents = json_encode($value);
  47. $composerValid = array_merge($composer, array(
  48. 'time' => 'level '.(count($keys) - 1),
  49. ));
  50. $composer = Util::addComposerTime($composer, $resourceKey, 'http://example.tld', $driver);
  51. $this->assertSame($composerValid, $composer);
  52. }
  53. }