|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Bundle\Kris\TwitterBundle\Tests\DependencyInjection; |
| 4 | + |
| 5 | +use Bundle\Kris\TwitterBundle\DependencyInjection\TwitterExtension; |
| 6 | + |
| 7 | +class TwitterExtensionTest extends \PHPUnit_Framework_TestCase |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @covers Bundle\Kris\TwitterBundle\DependencyInjection\TwitterExtension::apiLoad |
| 11 | + */ |
| 12 | + public function testApiLoadLoadsDefaults() |
| 13 | + { |
| 14 | + $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); |
| 15 | + $container |
| 16 | + ->expects($this->once()) |
| 17 | + ->method('hasDefinition') |
| 18 | + ->with('kris.twitter') |
| 19 | + ->will($this->returnValue(false)); |
| 20 | + |
| 21 | + $extension = $this->getMockBuilder('Bundle\\Kris\\TwitterBundle\\DependencyInjection\\TwitterExtension') |
| 22 | + ->setMethods(array('loadDefaults')) |
| 23 | + ->getMock(); |
| 24 | + $extension |
| 25 | + ->expects($this->once()) |
| 26 | + ->method('loadDefaults') |
| 27 | + ->with($container); |
| 28 | + |
| 29 | + $extension->apiLoad(array(), $container); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @covers Bundle\Kris\TwitterBundle\DependencyInjection\TwitterExtension::apiLoad |
| 34 | + */ |
| 35 | + public function testApiLoadDoesNotReloadDefaults() |
| 36 | + { |
| 37 | + $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); |
| 38 | + $container |
| 39 | + ->expects($this->once()) |
| 40 | + ->method('hasDefinition') |
| 41 | + ->with('kris.twitter') |
| 42 | + ->will($this->returnValue(true)); |
| 43 | + |
| 44 | + $extension = $this->getMockBuilder('Bundle\\Kris\\TwitterBundle\\DependencyInjection\\TwitterExtension') |
| 45 | + ->setMethods(array('loadDefaults')) |
| 46 | + ->getMock(); |
| 47 | + $extension |
| 48 | + ->expects($this->never()) |
| 49 | + ->method('loadDefaults'); |
| 50 | + |
| 51 | + $extension->apiLoad(array(), $container); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @covers Bundle\Kris\TwitterBundle\DependencyInjection\TwitterExtension::apiLoad |
| 56 | + */ |
| 57 | + public function testApiLoadSetsAlias() |
| 58 | + { |
| 59 | + $alias = 'foo'; |
| 60 | + |
| 61 | + $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); |
| 62 | + $container |
| 63 | + ->expects($this->once()) |
| 64 | + ->method('hasDefinition') |
| 65 | + ->with('kris.twitter') |
| 66 | + ->will($this->returnValue(true)); |
| 67 | + $container |
| 68 | + ->expects($this->once()) |
| 69 | + ->method('setAlias') |
| 70 | + ->with($alias, 'kris.twitter'); |
| 71 | + |
| 72 | + $extension = new TwitterExtension(); |
| 73 | + $extension->apiLoad(array('alias' => $alias), $container); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @covers Bundle\Kris\TwitterBundle\DependencyInjection\TwitterExtension::apiLoad |
| 78 | + * @dataProvider parameterNames |
| 79 | + */ |
| 80 | + public function testApiLoadSetParameters($name) |
| 81 | + { |
| 82 | + $value = 'foo'; |
| 83 | + |
| 84 | + $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); |
| 85 | + $container |
| 86 | + ->expects($this->once()) |
| 87 | + ->method('hasDefinition') |
| 88 | + ->with('kris.twitter') |
| 89 | + ->will($this->returnValue(true)); |
| 90 | + $container |
| 91 | + ->expects($this->once()) |
| 92 | + ->method('setParameter') |
| 93 | + ->with('kris.twitter.'.$name, $value); |
| 94 | + |
| 95 | + $extension = new TwitterExtension(); |
| 96 | + $extension->apiLoad(array($name => $value), $container); |
| 97 | + } |
| 98 | + |
| 99 | + public function parameterNames() |
| 100 | + { |
| 101 | + return array( |
| 102 | + array('consumer_key'), |
| 103 | + array('consumer_secret'), |
| 104 | + ); |
| 105 | + } |
| 106 | +} |
0 commit comments