Skip to content

Commit

Permalink
Add tests for DirectoryScopeDeterminer and PhpFileFinder
Browse files Browse the repository at this point in the history
  • Loading branch information
navarr committed Jul 14, 2021
1 parent fea95cf commit 328c05a
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/Controller/WhyBlockCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

class WhyBlockCommandController extends Command
{
private const ALL_DEPS = 'include-all-dependencies';
private const ROOT_DEPS = 'include-root-dependencies';
private const LEGACY_ANNOTATION = 'include-legacy-annotations';
private const FAIL_ON_ERROR = 'fail-on-error';
private const OUTPUT_FORMAT = 'format';
Expand Down
44 changes: 44 additions & 0 deletions tests/ScopeDeterminer/DirectoryScopeDeterminerTest.php
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());
}
}
51 changes: 51 additions & 0 deletions tests/ScopeDeterminer/PhpFileFinderTest.php
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);
}
}
}
3 changes: 3 additions & 0 deletions tests/_data/phpFileFinder/file1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// a php file in the base directory searched
3 changes: 3 additions & 0 deletions tests/_data/phpFileFinder/recursion1/anotherFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// another file in the first directory deep
3 changes: 3 additions & 0 deletions tests/_data/phpFileFinder/recursion1/file4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// a file one directory deep
3 changes: 3 additions & 0 deletions tests/_data/phpFileFinder/recursion1/recursion2/file3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// a file two directories deep
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// a file several directories deep

0 comments on commit 328c05a

Please sign in to comment.