|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of phpDocumentor. |
| 4 | + * |
| 5 | + * For the full copyright and license information, please view the LICENSE |
| 6 | + * file that was distributed with this source code. |
| 7 | + * |
| 8 | + * @copyright 2010-2015 Mike van Riel<[email protected]> |
| 9 | + * @license http://www.opensource.org/licenses/mit-license.php MIT |
| 10 | + * @link http://phpdoc.org |
| 11 | + */ |
| 12 | + |
| 13 | +namespace Flyfinder; |
| 14 | + |
| 15 | +use Mockery as m; |
| 16 | +use Flyfinder\Specification\IsHidden; |
| 17 | +use League\Flysystem\Filesystem; |
| 18 | + |
| 19 | +/** |
| 20 | + * Test case for Finder |
| 21 | + * @coversDefaultClass Flyfinder\Finder |
| 22 | + */ |
| 23 | +class FinderTest extends \PHPUnit_Framework_TestCase |
| 24 | +{ |
| 25 | + /** @var Finder */ |
| 26 | + private $fixture; |
| 27 | + |
| 28 | + /** |
| 29 | + * Initializes the fixture for this test. |
| 30 | + */ |
| 31 | + public function setUp() |
| 32 | + { |
| 33 | + $this->fixture = new Finder(); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @covers ::getMethod |
| 38 | + */ |
| 39 | + public function testGetMethod() |
| 40 | + { |
| 41 | + $this->assertEquals('find', $this->fixture->getMethod()); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @covers ::handle |
| 46 | + * @covers ::setFilesystem |
| 47 | + * @covers ::<private> |
| 48 | + */ |
| 49 | + public function testIfCorrectFilesAreBeingYielded() |
| 50 | + { |
| 51 | + $isHidden = m::mock('Flyfinder\Specification\IsHidden'); |
| 52 | + $filesystem = m::mock('League\Flysystem\Filesystem'); |
| 53 | + |
| 54 | + $listContents1 = [ |
| 55 | + 0 => [ |
| 56 | + "type" => "dir", |
| 57 | + "path" => ".hiddendir", |
| 58 | + "basename" => ".hiddendir" |
| 59 | + ], |
| 60 | + 1 => [ |
| 61 | + "type" => "file", |
| 62 | + "path" => "test.txt", |
| 63 | + "basename" => "test.txt" |
| 64 | + ] |
| 65 | + ]; |
| 66 | + |
| 67 | + $listContents2 = [ |
| 68 | + 0 => [ |
| 69 | + "type" => "file", |
| 70 | + "path" => ".hiddendir/.test.txt", |
| 71 | + "basename" => ".test.txt" |
| 72 | + ] |
| 73 | + ]; |
| 74 | + |
| 75 | + $filesystem->shouldReceive('listContents') |
| 76 | + ->with('') |
| 77 | + ->andReturn($listContents1); |
| 78 | + |
| 79 | + $filesystem->shouldReceive('listContents') |
| 80 | + ->with('.hiddendir') |
| 81 | + ->andReturn($listContents2); |
| 82 | + |
| 83 | + $isHidden->shouldReceive('isSatisfiedBy') |
| 84 | + ->with($listContents1[0]) |
| 85 | + ->andReturn(true); |
| 86 | + |
| 87 | + $isHidden->shouldReceive('isSatisfiedBy') |
| 88 | + ->with($listContents1[1]) |
| 89 | + ->andReturn(false); |
| 90 | + |
| 91 | + $isHidden->shouldReceive('isSatisfiedBy') |
| 92 | + ->with($listContents2[0]) |
| 93 | + ->andReturn(true); |
| 94 | + |
| 95 | + $this->fixture->setFilesystem($filesystem); |
| 96 | + $generator = $this->fixture->handle($isHidden); |
| 97 | + |
| 98 | + $result = []; |
| 99 | + |
| 100 | + foreach ($generator as $value) { |
| 101 | + $result[] = $value; |
| 102 | + } |
| 103 | + |
| 104 | + $expected = [ |
| 105 | + 0 => [ |
| 106 | + "type" => "dir", |
| 107 | + "path" => ".hiddendir", |
| 108 | + "basename" => ".hiddendir" |
| 109 | + ], |
| 110 | + 1 => [ |
| 111 | + "type" => "file", |
| 112 | + "path" => ".hiddendir/.test.txt", |
| 113 | + "basename" => ".test.txt" |
| 114 | + ] |
| 115 | + ]; |
| 116 | + |
| 117 | + $this->assertEquals($expected, $result); |
| 118 | + } |
| 119 | +} |
0 commit comments