refactor: Cleanup git state - commit all staged changes

Major refactoring cleanup:
- Add new controller architecture (class-controller-*.php)
- Add new settings-v2 UI (views/settings-v2/)
- Add new CSS architecture (agentic-sidebar.css, tokens)
- Add esbuild build pipeline (scripts/build.js, package.json)
- Add composer dependencies (vendor/)
- Add frontend src directory (assets/js/src/index.jsx)
- Add documentation files
- Remove old/obsolete files (class-settings.php, old CSS)

This commits all pending changes from previous refactoring efforts.
This commit is contained in:
Dwindi Ramadhana
2026-06-17 05:27:58 +07:00
parent d3f142222c
commit 690991c526
7963 changed files with 941566 additions and 67372 deletions

View File

@@ -0,0 +1,468 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace Flyfinder;
use Flyfinder\Specification\Glob;
use Flyfinder\Specification\HasExtension;
use Flyfinder\Specification\InPath;
use Flyfinder\Specification\IsHidden;
use Generator;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use function array_map;
use function array_values;
use function iterator_to_array;
use function pathinfo;
use function sort;
use function substr;
use function trim;
/**
* Test case for Finder
*
* @coversDefaultClass Flyfinder\Finder
*/
class FinderTest extends TestCase
{
/** @var Finder */
private $fixture;
/**
* Initializes the fixture for this test.
*/
public function setUp() : void
{
$this->fixture = new Finder();
}
public function tearDown() : void
{
m::close();
}
/**
* @covers ::getMethod
*/
public function testGetMethod() : void
{
$this->assertSame('find', $this->fixture->getMethod());
}
public function testIfNotHiddenLetsSubpathsThrough() : void
{
$files = [ 'foo/bar/.hidden/baz/not-hidden.txt' ];
$this->fixture->setFilesystem($this->mockFileSystem($files));
$notHidden = (new IsHidden())->notSpecification();
$this->assertEquals(
$files,
$this->generatorToFileList($this->fixture->handle($notHidden))
);
}
public function testIfDoubleNotHiddenLetsSubpathsThrough() : void
{
$files = [ '.foo/.bar/not-hidden/.baz/.hidden.txt' ];
$this->fixture->setFilesystem($this->mockFileSystem($files));
$notHidden = (new IsHidden())->notSpecification()->notSpecification();
$this->assertEquals(
$files,
$this->generatorToFileList($this->fixture->handle($notHidden))
);
}
public function testIfNeitherHiddenNorExtLetsSubpathsThrough() : void
{
$files = [ 'foo/bar/.hidden/baz.ext/neither-hidden-nor.ext.zzz' ];
$this->fixture->setFilesystem($this->mockFileSystem($files));
$neitherHiddenNorExt =
(new IsHidden())->notSpecification()
->andSpecification((new HasExtension(['ext']))->notSpecification());
$this->assertEquals(
$files,
$this->generatorToFileList($this->fixture->handle($neitherHiddenNorExt))
);
$neitherHiddenNorExtDeMorgan = (new IsHidden())->orSpecification(new HasExtension(['ext']))->notSpecification();
$this->assertEquals(
$files,
$this->generatorToFileList($this->fixture->handle($neitherHiddenNorExtDeMorgan))
);
}
public function testIfNegatedOrCullsExactMatches() : void
{
$files = [
'foo/bar/baz/whatever.txt',
'foo/gen/pics/bottle.jpg',
'foo/lou/time.txt',
];
$this->fixture->setFilesystem($this->mockFileSystem($files, ['foo/bar', 'foo/gen']));
$negatedOr =
(new InPath(new Path('foo/gen')))
->orSpecification(new InPath(new Path('foo/bar')))
->notSpecification();
$this->assertEquals(
['foo/lou/time.txt'],
$this->generatorToFileList($this->fixture->handle($negatedOr))
);
$negatedOrDeMorgan =
(new InPath(new Path('foo/gen')))->notSpecification()
->andSpecification((new InPath(new Path('foo/bar')))->notSpecification());
$this->assertEquals(
['foo/lou/time.txt'],
$this->generatorToFileList($this->fixture->handle($negatedOrDeMorgan))
);
}
public function testIfNegatedAndCullsExactMatches() : void
{
$files = [
'foo/bar/baz/whatever.txt',
'foo/gen/pics/bottle.jpg',
'foo/lou/time.txt',
];
$expected = [
'foo/gen/pics/bottle.jpg',
'foo/lou/time.txt',
];
$this->fixture->setFilesystem($this->mockFileSystem($files, ['foo/bar']));
$negatedAnd =
(new InPath(new Path('foo/*')))
->andSpecification(new InPath(new Path('*/bar')))
->notSpecification();
$this->assertEquals(
$expected,
$this->generatorToFileList($this->fixture->handle($negatedAnd))
);
$negatedAndDeMorgan =
(new InPath(new Path('foo/*')))->notSpecification()
->orSpecification((new InPath(new Path('*/bar')))->notSpecification());
$this->assertEquals(
$expected,
$this->generatorToFileList($this->fixture->handle($negatedAndDeMorgan))
);
}
/**
* @covers ::handle
* @covers ::setFilesystem
* @covers ::<private>
*/
public function testIfCorrectFilesAreBeingYielded() : void
{
$isHidden = m::mock(IsHidden::class);
$filesystem = m::mock(Filesystem::class);
$listContents1 = [
0 => [
'type' => 'dir',
'path' => '.hiddendir',
'dirname' => '',
'basename' => '.hiddendir',
'filename' => '.hiddendir',
],
1 => [
'type' => 'file',
'path' => 'test.txt',
'basename' => 'test.txt',
],
];
$listContents2 = [
0 => [
'type' => 'file',
'path' => '.hiddendir/.test.txt',
'dirname' => '.hiddendir',
'basename' => '.test.txt',
'filename' => '.test',
'extension' => 'txt',
],
];
$filesystem->shouldReceive('listContents')
->with('')
->andReturn($listContents1);
$filesystem->shouldReceive('listContents')
->with('.hiddendir')
->andReturn($listContents2);
$isHidden->shouldReceive('isSatisfiedBy')
->with($listContents1[0])
->andReturn(true);
$isHidden->shouldReceive('canBeSatisfiedBySomethingBelow')
->with($listContents1[0])
->andReturn(true);
$isHidden->shouldReceive('isSatisfiedBy')
->with($listContents1[1])
->andReturn(false);
$isHidden->shouldReceive('isSatisfiedBy')
->with($listContents2[0])
->andReturn(true);
$this->fixture->setFilesystem($filesystem);
$generator = $this->fixture->handle($isHidden);
$result = [];
foreach ($generator as $value) {
$result[] = $value;
}
$expected = [
0 => [
'type' => 'file',
'path' => '.hiddendir/.test.txt',
'dirname' => '.hiddendir',
'basename' => '.test.txt',
'filename' => '.test',
'extension' => 'txt',
],
];
$this->assertSame($expected, $result);
}
public function testSubtreePruningOptimization() : void
{
$filesystem = $this->mockFileSystem(
[
'foo/bar/baz/file.txt',
'foo/bar/baz/file2.txt',
'foo/bar/baz/excluded/excluded.txt',
'foo/bar/baz/excluded/culled/culled.txt',
'foo/bar/baz/excluded/important/reincluded.txt',
'foo/bar/file3.txt',
'foo/lou/someSubdir/file4.txt',
'foo/irrelevant1/',
'irrelevant2/irrelevant3/irrelevantFile.txt',
],
[
'foo/irrelevant1',
'irrelevant2',
'foo/bar/baz/excluded/culled',
]
);
$inFooBar = new InPath(new Path('foo/bar'));
$inFooLou = new InPath(new Path('foo/lou'));
$inExcl = new InPath(new Path('foo/bar/baz/excl*'));
$inReincl = new InPath(new Path('foo/bar/baz/*/important'));
$spec =
$inFooBar
->orSpecification($inFooLou)
->andSpecification($inExcl->notSpecification())
->orSpecification($inReincl);
$finder = $this->fixture;
$finder->setFilesystem($filesystem);
$generator = $finder->handle($spec);
$expected = [
'foo/bar/baz/file.txt',
'foo/bar/baz/file2.txt',
'foo/bar/file3.txt',
'foo/bar/baz/excluded/important/reincluded.txt',
'foo/lou/someSubdir/file4.txt',
];
sort($expected);
$this->assertEquals($expected, $this->generatorToFileList($generator));
}
public function testGlobSubtreePruning() : void
{
$filesystem = $this->mockFileSystem(
[
'foo/bar/baz/file.txt',
'foo/bar/baz/file2.txt',
'foo/bar/baz/excluded/excluded.txt',
'foo/bar/baz/excluded/culled/culled.txt',
'foo/bar/baz/excluded/important/reincluded.txt',
'foo/bar/file3.txt',
'foo/lou/someSubdir/file4.txt',
'foo/irrelevant1/',
'irrelevant2/irrelevant3/irrelevantFile.txt',
],
[
'foo/irrelevant1',
'irrelevant2',
'foo/bar/baz/excluded/culled',
]
);
$txtInFooBar = new Glob('/foo/bar/**/*.txt');
$inFooLou = new Glob('/foo/lou/**/*');
$inExcl = new Glob('/foo/bar/baz/excl*/**/*');
$inReincl = new Glob('/foo/bar/baz/*/important/**/*');
$spec = $txtInFooBar
->orSpecification($inFooLou)
->andSpecification($inExcl->notSpecification())
->orSpecification($inReincl);
$finder = $this->fixture;
$finder->setFilesystem($filesystem);
$generator = $finder->handle($spec);
$expected = [
'foo/bar/baz/file.txt',
'foo/bar/baz/file2.txt',
'foo/bar/file3.txt',
'foo/bar/baz/excluded/important/reincluded.txt',
'foo/lou/someSubdir/file4.txt',
];
sort($expected);
$this->assertEquals($expected, $this->generatorToFileList($generator));
}
/**
* @return string[]
*/
protected function generatorToFileList(Generator $generator) : array
{
$actual = array_values(array_map(static function ($v) {
return $v['path'];
}, iterator_to_array($generator)));
sort($actual);
return $actual;
}
/**
* @param string[] $pathList
*
* @return mixed[]
*/
protected function mockFileTree(array $pathList) : array
{
$result = [
'.' => [
'type' => 'dir',
'path' => '',
'dirname' => '.',
'basename' => '.',
'filename' => '.',
'contents' => [],
],
];
foreach ($pathList as $path) {
$isFile = substr($path, -1) !== '/';
$child = null;
while (true) {
$info = pathinfo($path);
if ($isFile) {
$isFile = false;
$result[$path] = [
'type' => 'file',
'path' => $path,
'dirname' => $info['dirname'],
'basename' => $info['basename'],
'filename' => $info['filename'],
'extension' => $info['extension'],
];
} else {
$existed = true;
if (!isset($result[$path])) {
$existed = false;
$result[$path] = [
'type' => 'dir',
'path' => $path,
'basename' => $info['basename'],
'filename' => $info['filename'],
'contents' => [],
];
}
if ($child!==null) {
$result[$path]['contents'][] = $child;
}
if ($existed) {
break;
}
}
$child = $info['basename'];
$path = $info['dirname'];
}
}
return $result;
}
/**
* @param mixed[] $fileTreeMock
*
* @return mixed[]
*/
protected function mockListContents(array $fileTreeMock, string $path) : array
{
$path = trim($path, '/');
if (substr($path . ' ', 0, 2)==='./') {
$path = substr($path, 2);
}
if ($path==='') {
$path = '.';
}
if (!isset($fileTreeMock[$path]) || $fileTreeMock[$path]['type'] === 'file') {
return [];
}
$result = [];
foreach ($fileTreeMock[$path]['contents'] as $basename) {
$childPath = ($path==='.' ? '' : $path . '/') . $basename;
if (!isset($fileTreeMock[$childPath])) {
continue;
}
$result[$basename] = $fileTreeMock[$childPath];
}
return $result;
}
/**
* @param string[] $paths
* @param string[] $pathsThatShouldNotBeListed
*/
protected function mockFileSystem(array $paths, array $pathsThatShouldNotBeListed = []) : FilesystemInterface
{
$fsData = $this->mockFileTree($paths);
$filesystem = m::mock(Filesystem::class);
$filesystem->shouldReceive('listContents')
->zeroOrMoreTimes()
->andReturnUsing(function (string $path) use ($fsData, $pathsThatShouldNotBeListed) : array {
$this->assertNotContains($path, $pathsThatShouldNotBeListed);
return array_values($this->mockListContents($fsData, $path));
});
return $filesystem;
}
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace Flyfinder;
use PHPUnit\Framework\TestCase;
/**
* Test case for Path
*
* @coversDefaultClass Flyfinder\Path
*/
class PathTest extends TestCase
{
/**
* @covers ::__construct
* @covers ::__toString
*/
public function testToString() : void
{
$path = new Path('/my/Path');
$this->assertSame('/my/Path', (string) $path);
}
}

View File

@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace Flyfinder\Specification;
use Mockery as m;
use PHPUnit\Framework\TestCase;
/**
* Test case for AndSpecification
*
* @coversDefaultClass \Flyfinder\Specification\AndSpecification
*/
class AndSpecificationTest extends TestCase
{
/** @var m\MockInterface|HasExtension */
private $hasExtension;
/** @var m\MockInterface|IsHidden */
private $isHidden;
/** @var AndSpecification */
private $fixture;
/**
* Initializes the fixture for this test.
*/
public function setUp() : void
{
$this->hasExtension = m::mock(HasExtension::class);
$this->isHidden = m::mock(IsHidden::class);
$this->fixture = new AndSpecification($this->hasExtension, $this->isHidden);
}
public function tearDown() : void
{
m::close();
}
/**
* @covers ::__construct
* @covers ::isSatisfiedBy
*/
public function testIfSpecificationIsSatisfied() : void
{
$this->hasExtension->shouldReceive('isSatisfiedBy')->once()->andReturn(true);
$this->isHidden->shouldReceive('isSatisfiedBy')->once()->andReturn(true);
$this->assertTrue($this->fixture->isSatisfiedBy(['test']));
}
/**
* @covers ::__construct
* @covers ::isSatisfiedBy
*/
public function testIfSpecificationIsNotSatisfied() : void
{
$this->hasExtension->shouldReceive('isSatisfiedBy')->once()->andReturn(true);
$this->isHidden->shouldReceive('isSatisfiedBy')->once()->andReturn(false);
$this->assertFalse($this->fixture->isSatisfiedBy(['test']));
}
}

View File

@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace Flyfinder\Specification;
use Mockery as m;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
* Test case for CompositeSpecification
*
* @coversDefaultClass Flyfinder\Specification\CompositeSpecification
*/
class CompositeSpecificationTest extends TestCase
{
/** @var m\MockInterface|HasExtension */
private $hasExtension;
/** @var CompositeSpecification|MockObject */
private $fixture;
/**
* Initializes the fixture for this test.
*/
public function setUp() : void
{
$this->hasExtension = m::mock(HasExtension::class);
$this->fixture = $this->getMockForAbstractClass(CompositeSpecification::class);
}
public function tearDown() : void
{
m::close();
}
/**
* @uses \Flyfinder\Specification\AndSpecification
*
* @covers ::andSpecification
*/
public function testAndSpecification() : void
{
$this->assertInstanceOf(
AndSpecification::class,
$this->fixture->andSpecification($this->hasExtension)
);
}
/**
* @uses \Flyfinder\Specification\OrSpecification
*
* @covers ::orSpecification
*/
public function testOrSpecification() : void
{
$this->assertInstanceOf(
OrSpecification::class,
$this->fixture->orSpecification($this->hasExtension)
);
}
/**
* @uses \Flyfinder\Specification\NotSpecification
*
* @covers ::notSpecification
*/
public function testNotSpecification() : void
{
$this->assertInstanceOf(
NotSpecification::class,
$this->fixture->notSpecification()
);
}
}

View File

@@ -0,0 +1,179 @@
<?php
declare(strict_types=1);
namespace Flyfinder\Specification;
use Generator;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use function is_array;
use function sprintf;
/**
* @coversDefaultClass \Flyfinder\Specification\Glob
* @covers ::<private>
* @covers ::isSatisfiedBy
* @covers ::__construct
*/
final class GlobTest extends TestCase
{
/**
* @param mixed[] $file
*
* @dataProvider matchingPatternFileProvider
* @dataProvider matchingPatternFileWithEscapeCharProvider
*
* @psalm-param array{basename: string, path: string, stream: resource, dirname: string, type: string, extension: string} $file
*/
public function testGlobIsMatching(string $pattern, array $file) : void
{
$glob = new Glob($pattern);
$this->assertTrue(
$glob->isSatisfiedBy($file),
sprintf('Failed: %s to match %s', $pattern, $file['path'])
);
}
/**
* @param mixed[] $file
*
* @dataProvider notMatchingPatternFileProvider
* @psalm-param array{basename: string, path: string, stream: resource, dirname: string, type: string, extension: string} $file
*/
public function testGlobIsNotMatching(string $pattern, array $file) : void
{
$glob = new Glob($pattern);
$this->assertFalse(
$glob->isSatisfiedBy($file),
sprintf('Failed: %s to match %s', $pattern, $file['path'])
);
}
/**
* @dataProvider invalidPatternProvider
*/
public function testInvalidGlobThrows(string $pattern) : void
{
$this->expectException(InvalidArgumentException::class);
new Glob($pattern);
}
/**
* @covers ::canBeSatisfiedBySomethingBelow
*/
public function testCanBeSatisfiedBySomethingBelow() : void
{
$glob = new Glob('/**/*');
$this->assertTrue($glob->canBeSatisfiedBySomethingBelow(['path' => 'src']));
}
public function invalidPatternProvider() : Generator
{
$invalidPatterns = [
'[aaa',
'{aaa',
'{a,{b}',
'aaaa', //path must be absolute
];
foreach ($invalidPatterns as $pattern) {
yield $pattern => [$pattern];
}
}
public function matchingPatternFileProvider() : Generator
{
$input = [
'/*.php' => 'test.php',
'/src/*' => 'src/test.php',
'/src/**/*.php' => 'src/subdir/test.php',
'/src/**/*' => 'src/subdir/second/test.php',
'/src/{subdir,other}/*' => [
'src/subdir/test.php',
'src/other/test.php',
],
'/src/subdir/test-[a-c].php' => [
'src/subdir/test-a.php',
'src/subdir/test-b.php',
'src/subdir/test-c.php',
],
'/src/subdir/test-[^a-c].php' => 'src/subdir/test-d.php',
'/src/subdir/test-?.php' => [
'src/subdir/test-a.php',
'src/subdir/test-b.php',
'src/subdir/test-c.php',
'src/subdir/test-~.php',
],
'/src/subdir/test-}.php' => 'src/subdir/test-}.php',
];
yield from $this->toTestData($input);
}
public function matchingPatternFileWithEscapeCharProvider() : Generator
{
$escapeChars = [
'*',
'?',
'{',
'}',
'[',
']',
'-',
'^',
'$',
'~',
'\\',
'\\\\',
];
foreach ($escapeChars as $char) {
$file = sprintf('/src/test\\%s.php', $char);
yield $file => [
$file,
['path' => sprintf('src/test%s.php', $char)],
];
}
}
public function notMatchingPatternFileProvider() : Generator
{
$input = [
'/*.php' => 'test.css',
'/src/*' => 'src/subdir/test.php',
'/src/**/*.php' => 'src/subdir/test.css',
'/src/subdir/test-[a-c].php' => 'src/subdir/test-d.php',
'/src/subdir/test-[^a-c].php' => [
'src/subdir/test-a.php',
'src/subdir/test-b.php',
'src/subdir/test-c.php',
],
'/src' => 'test/file.php',
];
yield from $this->toTestData($input);
}
/**
* @param mixed[] $input
*/
private function toTestData(array $input) : Generator
{
foreach ($input as $glob => $path) {
if (!is_array($path)) {
$path = [$path];
}
foreach ($path as $key => $item) {
yield ($key !== 0 ? $key . ' - ' : '') . $glob => [
$glob,
['path' => $item],
];
}
}
}
}

View File

@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace Flyfinder\Specification;
use Mockery as m;
use PHPUnit\Framework\TestCase;
/**
* Test case for HasExtension
*
* @coversDefaultClass Flyfinder\Specification\HasExtension
*/
class HasExtensionTest extends TestCase
{
/** @var HasExtension */
private $fixture;
/**
* Initializes the fixture for this test.
*/
public function setUp() : void
{
$this->fixture = new HasExtension(['txt']);
}
public function tearDown() : void
{
m::close();
}
/**
* @covers ::__construct
* @covers ::isSatisfiedBy
*/
public function testIfSpecificationIsSatisfied() : void
{
$this->assertTrue($this->fixture->isSatisfiedBy(['extension' => 'txt']));
}
/**
* @covers ::__construct
* @covers ::isSatisfiedBy
*/
public function testIfSpecificationIsNotSatisfied() : void
{
$this->assertFalse($this->fixture->isSatisfiedBy(['extension' => 'php']));
}
}

View File

@@ -0,0 +1,167 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace Flyfinder\Specification;
use Flyfinder\Path;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use function dirname;
/**
* Test case for InPath
*
* @coversDefaultClass \Flyfinder\Specification\InPath
* @covers ::<private>
*/
class InPathTest extends TestCase
{
/** @var InPath */
private $fixture;
public function tearDown() : void
{
m::close();
}
/**
* @uses \Flyfinder\Path
*
* @covers ::__construct
* @covers ::isSatisfiedBy
* @dataProvider validDirnames
*/
public function testExactMatch() : void
{
$absolutePath = 'absolute/path/to/file.txt';
$spec = new InPath(new Path($absolutePath));
$this->assertTrue($spec->isSatisfiedBy([
'type' => 'file',
'path' => $absolutePath,
'dirname' => $absolutePath,
'filename' => 'file',
'extension' => 'txt',
'basename' => 'file.txt',
]));
}
private function useWildcardPath() : void
{
$this->fixture = new InPath(new Path('*dden?ir/n'));
}
/**
* @uses \Flyfinder\Path
*
* @covers ::__construct
* @covers ::isSatisfiedBy
* @dataProvider validDirnames
*/
public function testIfSpecificationIsSatisfied(string $dirname) : void
{
$this->useWildcardPath();
$this->assertTrue($this->fixture->isSatisfiedBy(['dirname' => $dirname]));
}
/**
* @uses \Flyfinder\Path
*
* @covers ::__construct
* @covers ::isSatisfiedBy
* @dataProvider validDirnames
*/
public function testWithSingleDotSpec(string $dirname) : void
{
$spec = new InPath(new Path('.'));
$this->assertTrue($spec->isSatisfiedBy(['dirname' => $dirname]));
}
/**
* @uses \Flyfinder\Path
*
* @covers ::__construct
* @covers ::isSatisfiedBy
* @dataProvider validDirnames
*/
public function testWithCurrentDirSpec(string $dirname) : void
{
$spec = new InPath(new Path('./'));
$this->assertTrue($spec->isSatisfiedBy(['dirname' => $dirname]));
}
/**
* Data provider for testIfSpecificationIsSatisfied. Contains a few valid directory names
*
* @return string[][]
*/
public function validDirnames() : array
{
return [
['.hiddendir/n'],
['.hiddendir/n/'],
['.hiddendir/n/somedir'],
['.hiddendir/n/somedir.txt'],
['ddenxir/n'],
];
}
/**
* @uses \Flyfinder\Path
*
* @covers ::__construct
* @covers ::isSatisfiedBy
* @dataProvider invalidDirnames
*/
public function testIfSpecificationIsNotSatisfied(string $dirname) : void
{
$this->useWildcardPath();
$this->assertFalse($this->fixture->isSatisfiedBy(['dirname' => $dirname]));
}
/**
* Data provider for testIfSpecificationIsNotSatisfied. Contains a few invalid directory names
*
* @return string[][]
*/
public function invalidDirnames() : array
{
return [
['/hiddendir/n'],
['.hiddendir/normaldir'],
['.hiddendir.ext/n'],
['.hiddenxxir/n'],
['.hiddenir/n'],
];
}
/**
* @uses \Flyfinder\Path
*
* @covers ::__construct
* @covers ::isSatisfiedBy
*/
public function testNoFalsePositiveWithLongerDirName() : void
{
$prefixDir = 'absolute/path';
$absolutePath = 'absolute/pathMOAR/to/file.txt';
$spec = new InPath(new Path($prefixDir));
$this->assertFalse($spec->isSatisfiedBy([
'type' => 'file',
'path' => $absolutePath,
'dirname' => dirname($absolutePath),
'filename' => 'file',
'extension' => 'txt',
'basename' => 'file.txt',
]));
}
}

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace Flyfinder\Specification;
use Mockery as m;
use PHPUnit\Framework\TestCase;
/**
* Test case for IsHidden
*
* @coversDefaultClass Flyfinder\Specification\IsHidden
*/
class IsHiddenTest extends TestCase
{
/** @var IsHidden */
private $fixture;
/**
* Initializes the fixture for this test.
*/
public function setUp() : void
{
$this->fixture = new IsHidden();
}
public function tearDown() : void
{
m::close();
}
/**
* @covers ::isSatisfiedBy
*/
public function testIfSpecificationIsSatisfied() : void
{
$this->assertTrue($this->fixture->isSatisfiedBy(['basename' => '.test']));
}
/**
* @covers ::isSatisfiedBy
*/
public function testIfSpecificationIsNotSatisfied() : void
{
$this->assertFalse($this->fixture->isSatisfiedBy(['basename' => 'test']));
}
}

View File

@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace Flyfinder\Specification;
use Mockery as m;
use PHPUnit\Framework\TestCase;
/**
* Test case for NotSpecification
*
* @coversDefaultClass Flyfinder\Specification\NotSpecification
*/
class NotSpecificationTest extends TestCase
{
/** @var m\MockInterface|HasExtension */
private $hasExtension;
/** @var NotSpecification */
private $fixture;
/**
* Initializes the fixture for this test.
*/
public function setUp() : void
{
$this->hasExtension = m::mock(HasExtension::class);
$this->fixture = new NotSpecification($this->hasExtension);
}
public function tearDown() : void
{
m::close();
}
/**
* @covers ::__construct
* @covers ::isSatisfiedBy
*/
public function testIfSpecificationIsSatisfied() : void
{
$this->hasExtension->shouldReceive('isSatisfiedBy')->once()->andReturn(false);
$this->assertTrue($this->fixture->isSatisfiedBy(['test']));
}
/**
* @covers ::__construct
* @covers ::isSatisfiedBy
*/
public function testIfSpecificationIsNotSatisfied() : void
{
$this->hasExtension->shouldReceive('isSatisfiedBy')->once()->andReturn(true);
$this->assertFalse($this->fixture->isSatisfiedBy(['test']));
}
}

View File

@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace Flyfinder\Specification;
use Mockery as m;
use PHPUnit\Framework\TestCase;
/**
* Test case for OrSpecification
*
* @coversDefaultClass Flyfinder\Specification\OrSpecification
*/
class OrSpecificationTest extends TestCase
{
/** @var m\MockInterface|HasExtension */
private $hasExtension;
/** @var m\MockInterface|IsHidden */
private $isHidden;
/** @var OrSpecification */
private $fixture;
/**
* Initializes the fixture for this test.
*/
public function setUp() : void
{
$this->hasExtension = m::mock(HasExtension::class);
$this->isHidden = m::mock(IsHidden::class);
$this->fixture = new OrSpecification($this->hasExtension, $this->isHidden);
}
public function tearDown() : void
{
m::close();
}
/**
* @covers ::__construct
* @covers ::isSatisfiedBy
*/
public function testIfSpecificationIsSatisfied() : void
{
$this->hasExtension->shouldReceive('isSatisfiedBy')->once()->andReturn(false);
$this->isHidden->shouldReceive('isSatisfiedBy')->once()->andReturn(true);
$this->assertTrue($this->fixture->isSatisfiedBy(['test']));
}
/**
* @covers ::__construct
* @covers ::isSatisfiedBy
*/
public function testIfSpecificationIsNotSatisfied() : void
{
$this->hasExtension->shouldReceive('isSatisfiedBy')->once()->andReturn(false);
$this->isHidden->shouldReceive('isSatisfiedBy')->once()->andReturn(false);
$this->assertFalse($this->fixture->isSatisfiedBy(['test']));
}
}