Skip to content

Commit 5156255

Browse files
committed
Added unit test for Finder and several small corrections in specifications
1 parent f96c372 commit 5156255

File tree

12 files changed

+142
-25
lines changed

12 files changed

+142
-25
lines changed

src/Finder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function getMethod()
3838
* Set the Filesystem object.
3939
*
4040
* @param FilesystemInterface $filesystem
41+
* @return void
4142
*/
4243
public function setFilesystem(FilesystemInterface $filesystem)
4344
{
@@ -57,7 +58,7 @@ public function handle(SpecificationInterface $specification)
5758

5859
/**
5960
* @param SpecificationInterface $specification
60-
* @param $path
61+
* @param string $path
6162
* @return Generator
6263
*/
6364
private function yieldFilesInPath(SpecificationInterface $specification, $path)

src/Specification/AndSpecification.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ public function __construct(CompositeSpecification $one, CompositeSpecification
3737
$this->other = $other;
3838
}
3939

40-
4140
/**
4241
* Checks if the value meets the specification
4342
*
44-
* @param $value
43+
* @param mixed[] $value
4544
* @return bool
4645
*/
47-
public function isSatisfiedBy($value)
46+
public function isSatisfiedBy(array $value)
4847
{
4948
return $this->one->isSatisfiedBy($value) && $this->other->isSatisfiedBy($value);
5049
}

src/Specification/HasExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public function __construct($extensions)
3636
/**
3737
* Checks if the value meets the specification
3838
*
39-
* @param $value
39+
* @param mixed[] $value
4040
* @return bool
4141
*/
42-
public function isSatisfiedBy($value)
42+
public function isSatisfiedBy(array $value)
4343
{
4444
return isset($value['extension']) && in_array($value['extension'], $this->extensions) ? true : false;
4545
}

src/Specification/InPath.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121
class InPath extends CompositeSpecification implements SpecificationInterface
2222
{
23-
2423
/**
2524
* @var Path
2625
*/
@@ -38,10 +37,10 @@ public function __construct(Path $path)
3837
/**
3938
* Checks if the value meets the specification
4039
*
41-
* @param $value
40+
* @param mixed[] $value
4241
* @return bool
4342
*/
44-
public function isSatisfiedBy($value)
43+
public function isSatisfiedBy(array $value)
4544
{
4645
return isset($value['dirname']) && $value['dirname'] === (string)$this->path ? true : false;
4746
}

src/Specification/IsHidden.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class IsHidden extends CompositeSpecification implements SpecificationInterface
2121
/**
2222
* Checks if the value meets the specification
2323
*
24-
* @param $value
24+
* @param mixed[] $value
2525
* @return bool
2626
*/
27-
public function isSatisfiedBy($value)
27+
public function isSatisfiedBy(array $value)
2828
{
29-
return substr($value['basename'], 0, 1) === '.' ? true : false;
29+
return isset($value['basename']) && substr($value['basename'], 0, 1) === '.' ? true : false;
3030
}
3131
}

src/Specification/NotSpecification.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ public function __construct(CompositeSpecification $wrapped)
3030
$this->wrapped = $wrapped;
3131
}
3232

33-
3433
/**
3534
* Checks if the value meets the specification
3635
*
37-
* @param $value
36+
* @param mixed[] $value
3837
* @return bool
3938
*/
40-
public function isSatisfiedBy($value)
39+
public function isSatisfiedBy(array $value)
4140
{
4241
return ! $this->wrapped->isSatisfiedBy($value);
4342
}

src/Specification/OrSpecification.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public function __construct(CompositeSpecification $one, CompositeSpecification
4040
/**
4141
* Checks if the value meets the specification
4242
*
43-
* @param $value
43+
* @param mixed[] $value
4444
* @return bool
4545
*/
46-
public function isSatisfiedBy($value)
46+
public function isSatisfiedBy(array $value)
4747
{
4848
return $this->one->isSatisfiedBy($value) || $this->other->isSatisfiedBy($value);
4949
}

src/Specification/SpecificationInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ interface SpecificationInterface
2020
/**
2121
* Checks if the value meets the specification
2222
*
23-
* @param $value
23+
* @param mixed[] $value
2424
* @return bool
2525
*/
26-
public function isSatisfiedBy($value);
26+
public function isSatisfiedBy(array $value);
2727
}

tests/unit/FinderTest.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
}

tests/unit/Specification/AndSpecificationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testIfSpecificationIsSatisfied()
5050
$this->hasExtension->shouldReceive('isSatisfiedBy')->once()->andReturn(true);
5151
$this->isHidden->shouldReceive('isSatisfiedBy')->once()->andReturn(true);
5252

53-
$this->assertTrue($this->fixture->isSatisfiedBy('test'));
53+
$this->assertTrue($this->fixture->isSatisfiedBy(['test']));
5454
}
5555

5656
/**
@@ -62,6 +62,6 @@ public function testIfSpecificationIsNotSatisfied()
6262
$this->hasExtension->shouldReceive('isSatisfiedBy')->once()->andReturn(true);
6363
$this->isHidden->shouldReceive('isSatisfiedBy')->once()->andReturn(false);
6464

65-
$this->assertFalse($this->fixture->isSatisfiedBy('test'));
65+
$this->assertFalse($this->fixture->isSatisfiedBy(['test']));
6666
}
6767
}

0 commit comments

Comments
 (0)