PimpleProviderTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Knp\Menu\Tests\Provider;
  3. use Knp\Menu\Provider\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(), 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 testGetExistentMenu()
  20. {
  21. $pimple = new \Pimple();
  22. $menu = $this->getMock('Knp\Menu\ItemInterface');
  23. $pimple['menu'] = function() use ($menu) {
  24. return $menu;
  25. };
  26. $provider = new PimpleProvider($pimple, array('default' => 'menu'));
  27. $this->assertSame($menu, $provider->get('default'));
  28. }
  29. public function testGetMenuAsClosure()
  30. {
  31. $pimple = new \Pimple();
  32. $menu = $this->getMock('Knp\Menu\ItemInterface');
  33. $pimple['menu'] = $pimple->protect(function($options, $c) use ($menu) {
  34. $c['options'] = $options;
  35. return $menu;
  36. });
  37. $provider = new PimpleProvider($pimple, array('default' => 'menu'));
  38. $this->assertSame($menu, $provider->get('default', array('foo' => 'bar')));
  39. $this->assertEquals(array('foo' => 'bar'), $pimple['options']);
  40. }
  41. /**
  42. * @expectedException InvalidArgumentException
  43. */
  44. public function testGetNonExistentMenu()
  45. {
  46. $provider = new PimpleProvider(new \Pimple());
  47. $provider->get('non-existent');
  48. }
  49. }