|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of the SVN-Buddy library. |
| 4 | + * For the full copyright and license information, please view |
| 5 | + * the LICENSE file that was distributed with this source code. |
| 6 | + * |
| 7 | + * @copyright Alexander Obuhovich <aik.bold@gmail.com> |
| 8 | + * @link https://github.com/aik099/svn-buddy |
| 9 | + */ |
| 10 | + |
| 11 | +namespace Tests\aik099\SVNBuddy\Repository\Connector; |
| 12 | + |
| 13 | + |
| 14 | +use aik099\SVNBuddy\Repository\Connector\Command; |
| 15 | +use Prophecy\Prophecy\ObjectProphecy; |
| 16 | + |
| 17 | +class CommandTest extends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + |
| 20 | + /** |
| 21 | + * Process. |
| 22 | + * |
| 23 | + * @var ObjectProphecy |
| 24 | + */ |
| 25 | + private $_process; |
| 26 | + |
| 27 | + /** |
| 28 | + * Console IO. |
| 29 | + * |
| 30 | + * @var ObjectProphecy |
| 31 | + */ |
| 32 | + private $_io; |
| 33 | + |
| 34 | + /** |
| 35 | + * Cache manager. |
| 36 | + * |
| 37 | + * @var ObjectProphecy |
| 38 | + */ |
| 39 | + private $_cacheManager; |
| 40 | + |
| 41 | + /** |
| 42 | + * Command. |
| 43 | + * |
| 44 | + * @var Command |
| 45 | + */ |
| 46 | + private $_command; |
| 47 | + |
| 48 | + protected function setUp() |
| 49 | + { |
| 50 | + parent::setUp(); |
| 51 | + |
| 52 | + $this->_process = $this->prophesize('Symfony\\Component\\Process\\Process'); |
| 53 | + $this->_io = $this->prophesize('aik099\\SVNBuddy\\ConsoleIO'); |
| 54 | + $this->_cacheManager = $this->prophesize('aik099\\SVNBuddy\\Cache\\CacheManager'); |
| 55 | + |
| 56 | + $this->_command = $this->_createCommand(); |
| 57 | + } |
| 58 | + |
| 59 | + public function testRunWithoutCallback() |
| 60 | + { |
| 61 | + $this->_process->getCommandLine()->willReturn('svn log --limit 5')->shouldBeCalled(); |
| 62 | + $this->_process->setInput('')->shouldBeCalled(); |
| 63 | + $this->_process->mustRun(null)->shouldBeCalled(); |
| 64 | + $this->_process->getOutput()->willReturn('OK')->shouldBeCalled(); |
| 65 | + |
| 66 | + $this->_io->isVerbose()->willReturn(false); |
| 67 | + |
| 68 | + $this->_process |
| 69 | + ->setCommandLine('svn --non-interactive log --limit 5') |
| 70 | + ->will(function ($args, $process) { |
| 71 | + $process->getCommandLine()->willReturn($args[0])->shouldBeCalled(); |
| 72 | + }) |
| 73 | + ->shouldBeCalled(); |
| 74 | + |
| 75 | + $this->assertEquals('OK', $this->_command->run()); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Creates command. |
| 80 | + * |
| 81 | + * @return Command |
| 82 | + */ |
| 83 | + private function _createCommand() |
| 84 | + { |
| 85 | + return new Command($this->_process->reveal(), $this->_io->reveal(), $this->_cacheManager->reveal()); |
| 86 | + } |
| 87 | + |
| 88 | +} |
0 commit comments