PimpleProviderTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Knp\Menu\Tests\Renderer;
  3. use Knp\Menu\Renderer\PimpleProvider;
  4. class PimpleProviderTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function setUp()
  7. {
  8. if (!class_exists('Pimple')) {
  9. $this->markTestSkipped('Pimple is not available');
  10. }
  11. }
  12. public function testHas()
  13. {
  14. $provider = new PimpleProvider(new \Pimple(), 'first', array('first' => 'first', 'second' => 'dummy'));
  15. $this->assertTrue($provider->has('first'));
  16. $this->assertTrue($provider->has('second'));
  17. $this->assertFalse($provider->has('third'));
  18. }
  19. public function testGetExistentRenderer()
  20. {
  21. $pimple = new \Pimple();
  22. $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
  23. $pimple['renderer'] = function() use ($renderer) {
  24. return $renderer;
  25. };
  26. $provider = new PimpleProvider($pimple, 'default', array('default' => 'renderer'));
  27. $this->assertSame($renderer, $provider->get('default'));
  28. }
  29. public function testGetDefaultRenderer()
  30. {
  31. $pimple = new \Pimple();
  32. $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
  33. $pimple['renderer'] = function() use ($renderer) {
  34. return $renderer;
  35. };
  36. $provider = new PimpleProvider($pimple, 'default', array('default' => 'renderer'));
  37. $this->assertSame($renderer, $provider->get());
  38. }
  39. /**
  40. * @expectedException InvalidArgumentException
  41. */
  42. public function testGetNonExistentRenderer()
  43. {
  44. $provider = new PimpleProvider(new \Pimple(), 'default', array());
  45. $provider->get('non-existent');
  46. }
  47. }