PackagesTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Asset\Tests;
  11. use Symfony\Component\Asset\Package;
  12. use Symfony\Component\Asset\Packages;
  13. use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
  14. class PackagesTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testGetterSetters()
  17. {
  18. $packages = new Packages();
  19. $packages->setDefaultPackage($default = $this->getMock('Symfony\Component\Asset\PackageInterface'));
  20. $packages->addPackage('a', $a = $this->getMock('Symfony\Component\Asset\PackageInterface'));
  21. $this->assertEquals($default, $packages->getPackage());
  22. $this->assertEquals($a, $packages->getPackage('a'));
  23. $packages = new Packages($default, array('a' => $a));
  24. $this->assertEquals($default, $packages->getPackage());
  25. $this->assertEquals($a, $packages->getPackage('a'));
  26. }
  27. public function testGetVersion()
  28. {
  29. $packages = new Packages(
  30. new Package(new StaticVersionStrategy('default')),
  31. array('a' => new Package(new StaticVersionStrategy('a')))
  32. );
  33. $this->assertEquals('default', $packages->getVersion('/foo'));
  34. $this->assertEquals('a', $packages->getVersion('/foo', 'a'));
  35. }
  36. public function testGetUrl()
  37. {
  38. $packages = new Packages(
  39. new Package(new StaticVersionStrategy('default')),
  40. array('a' => new Package(new StaticVersionStrategy('a')))
  41. );
  42. $this->assertEquals('/foo?default', $packages->getUrl('/foo'));
  43. $this->assertEquals('/foo?a', $packages->getUrl('/foo', 'a'));
  44. }
  45. /**
  46. * @expectedException \Symfony\Component\Asset\Exception\LogicException
  47. */
  48. public function testNoDefaultPackage()
  49. {
  50. $packages = new Packages();
  51. $packages->getPackage();
  52. }
  53. /**
  54. * @expectedException \Symfony\Component\Asset\Exception\InvalidArgumentException
  55. */
  56. public function testUndefinedPackage()
  57. {
  58. $packages = new Packages();
  59. $packages->getPackage('a');
  60. }
  61. }