|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the SpBowerBundle package. |
| 5 | + * |
| 6 | + * (c) Martin Parsiegla <martin.parsiegla@gmail.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Sp\BowerBundle\Tests\Command; |
| 13 | + |
| 14 | +use Sp\BowerBundle\Command\UpdateCommand; |
| 15 | +use Sp\BowerBundle\Bower\Configuration; |
| 16 | +use Symfony\Component\Console\Input\InputOption; |
| 17 | +use Symfony\Component\Console\Output\NullOutput; |
| 18 | +use Symfony\Component\Console\Input\ArrayInput; |
| 19 | + |
| 20 | +/** |
| 21 | + * @author Martin Parsiegla <martin.parsiegla@gmail.com> |
| 22 | + */ |
| 23 | +class UpdateCommandTest extends \PHPUnit_Framework_TestCase |
| 24 | +{ |
| 25 | + private $application; |
| 26 | + private $definition; |
| 27 | + private $kernel; |
| 28 | + private $container; |
| 29 | + private $command; |
| 30 | + private $bower; |
| 31 | + private $bm; |
| 32 | + private $helperSet; |
| 33 | + |
| 34 | + /** |
| 35 | + * Sets up the fixture, for example, opens a network connection. |
| 36 | + * This method is called before a test is executed. |
| 37 | + */ |
| 38 | + protected function setUp() |
| 39 | + { |
| 40 | + $this->application = $this->getMockBuilder('Symfony\\Bundle\\FrameworkBundle\\Console\\Application') |
| 41 | + ->disableOriginalConstructor() |
| 42 | + ->getMock(); |
| 43 | + $this->definition = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputDefinition') |
| 44 | + ->disableOriginalConstructor() |
| 45 | + ->getMock(); |
| 46 | + $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface'); |
| 47 | + $this->helperSet = $this->getMock('Symfony\\Component\\Console\\Helper\\HelperSet'); |
| 48 | + $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); |
| 49 | + $this->bm = $this->getMockBuilder('Sp\\BowerBundle\\Bower\\BowerManager') |
| 50 | + ->disableOriginalConstructor() |
| 51 | + ->getMock(); |
| 52 | + $this->bower = $this->getMockBuilder('Sp\\BowerBundle\\Bower\\Bower') |
| 53 | + ->disableOriginalConstructor() |
| 54 | + ->getMock(); |
| 55 | + |
| 56 | + $this->application->expects($this->any()) |
| 57 | + ->method('getDefinition') |
| 58 | + ->will($this->returnValue($this->definition)); |
| 59 | + $this->definition->expects($this->any()) |
| 60 | + ->method('getArguments') |
| 61 | + ->will($this->returnValue(array())); |
| 62 | + $this->definition->expects($this->any()) |
| 63 | + ->method('getOptions') |
| 64 | + ->will($this->returnValue(array( |
| 65 | + new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'), |
| 66 | + new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'), |
| 67 | + new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'), |
| 68 | + ))); |
| 69 | + |
| 70 | + $this->application->expects($this->any()) |
| 71 | + ->method('getKernel') |
| 72 | + ->will($this->returnValue($this->kernel)); |
| 73 | + |
| 74 | + $this->application->expects($this->once()) |
| 75 | + ->method('getHelperSet') |
| 76 | + ->will($this->returnValue($this->helperSet)); |
| 77 | + |
| 78 | + $this->kernel->expects($this->any()) |
| 79 | + ->method('getContainer') |
| 80 | + ->will($this->returnValue($this->container)); |
| 81 | + |
| 82 | + $this->container->expects($this->at(0)) |
| 83 | + ->method('get') |
| 84 | + ->with('sp_bower.bower_manager') |
| 85 | + ->will($this->returnValue($this->bm)); |
| 86 | + |
| 87 | + $this->container->expects($this->at(1)) |
| 88 | + ->method('get') |
| 89 | + ->with('sp_bower.bower') |
| 90 | + ->will($this->returnValue($this->bower)); |
| 91 | + |
| 92 | + $this->command = new UpdateCommand(); |
| 93 | + $this->command->setApplication($this->application); |
| 94 | + } |
| 95 | + |
| 96 | + public function testEmptyBowerManager() |
| 97 | + { |
| 98 | + $this->bm->expects($this->once()) |
| 99 | + ->method('getBundles') |
| 100 | + ->will($this->returnValue(array())); |
| 101 | + |
| 102 | + $this->command->run(new ArrayInput(array()), new NullOutput()); |
| 103 | + } |
| 104 | + |
| 105 | + public function testUpdate() |
| 106 | + { |
| 107 | + $configuration = new Configuration('/foo'); |
| 108 | + $configuration->setAssetDirectory('/test'); |
| 109 | + $configuration->setJsonFile('foo.json'); |
| 110 | + |
| 111 | + $barConfig = new Configuration('/bar'); |
| 112 | + $bundles = array( |
| 113 | + 'DemoBundle' => $configuration, |
| 114 | + 'AcmeBundle' => $barConfig |
| 115 | + ); |
| 116 | + |
| 117 | + $this->bower->expects($this->at(0))->method('update')->with($this->equalTo($configuration)); |
| 118 | + |
| 119 | + $this->bower->expects($this->at(1))->method('update')->with($this->equalTo($barConfig)); |
| 120 | + |
| 121 | + |
| 122 | + $this->bm->expects($this->once()) |
| 123 | + ->method('getBundles') |
| 124 | + ->will($this->returnValue($bundles)); |
| 125 | + |
| 126 | + $this->command->run(new ArrayInput(array()), new NullOutput()); |
| 127 | + } |
| 128 | +} |
0 commit comments