-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for DirectoryScopeDeterminer and PhpFileFinder
- Loading branch information
Showing
8 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright 2021 Navarr Barnier. All Rights Reserved. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Navarr\Depends\Test\ScopeDeterminer; | ||
|
||
use Navarr\Depends\ScopeDeterminer\DirectoryScopeDeterminer; | ||
use Navarr\Depends\ScopeDeterminer\PhpFileFinder; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DirectoryScopeDeterminerTest extends TestCase | ||
{ | ||
public function testDirectoryIsGivenToPhpFileFinder(): void | ||
{ | ||
$dir = uniqid(); | ||
$finder = $this->createMock(PhpFileFinder::class); | ||
$finder->expects($this->once()) | ||
->method('findAll') | ||
->with($dir) | ||
->willReturn([]); | ||
|
||
$determiner = new DirectoryScopeDeterminer($finder, $dir); | ||
$determiner->getFiles(); | ||
} | ||
|
||
public function testResultOfPhpFileFinderIsProvidedBack(): void | ||
{ | ||
$results = [ | ||
uniqid(), | ||
uniqid() | ||
]; | ||
|
||
$finder = $this->createMock(PhpFileFinder::class); | ||
$finder->method('findAll') | ||
->willReturn($results); | ||
|
||
$determiner = new DirectoryScopeDeterminer($finder, uniqid()); | ||
$this->assertEquals($results, $determiner->getFiles()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright 2021 Navarr Barnier. All Rights Reserved. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Navarr\Depends\Test\ScopeDeterminer; | ||
|
||
use DI\Container; | ||
use Navarr\Depends\ScopeDeterminer\PhpFileFinder; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PhpFileFinderTest extends TestCase | ||
{ | ||
public function testFindAll() | ||
{ | ||
$directory = implode( | ||
DIRECTORY_SEPARATOR, | ||
[ | ||
__DIR__, | ||
'..', | ||
'_data', | ||
'phpFileFinder', | ||
] | ||
); | ||
|
||
$files = array_map( | ||
'realpath', | ||
[ | ||
$directory . DIRECTORY_SEPARATOR . 'file1.php', | ||
$directory . DIRECTORY_SEPARATOR . 'recursion1/file4.php', | ||
$directory . DIRECTORY_SEPARATOR . 'recursion1/anotherFile.php', | ||
$directory . DIRECTORY_SEPARATOR . 'recursion1/recursion2/file3.php', | ||
$directory . DIRECTORY_SEPARATOR . 'recursion1/recursion2/recursion3/file2.php', | ||
] | ||
); | ||
|
||
$container = new Container(); | ||
$finder = $container->get(PhpFileFinder::class); | ||
$results = $finder->findAll($directory); | ||
|
||
$this->assertIsArray($results); | ||
$this->assertCount(5, $results); | ||
|
||
foreach ($files as $file) { | ||
$this->assertContains($file, $results); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
// a php file in the base directory searched |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
// another file in the first directory deep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
// a file one directory deep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
// a file two directories deep |
3 changes: 3 additions & 0 deletions
3
tests/_data/phpFileFinder/recursion1/recursion2/recursion3/file2.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
// a file several directories deep |