Skip to content

Commit

Permalink
Merge branch 'main' into readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon authored Apr 9, 2024
2 parents f8797ed + dd182b7 commit 89d064f
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint_test_pull_requests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
composer-command:
- name: PHP Code Style
command: 'style:php'
command: 'style:php:check'
- name: Composer normalize
command: 'normalize --dry-run'
- name: PHPStan
Expand Down
3 changes: 2 additions & 1 deletion extension-installer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"scripts": {
"analyze:php": "phpstan analyze",
"style:php": "ecs"
"style:php:check": "ecs",
"style:php:fix": "ecs --fix"
}
}
3 changes: 2 additions & 1 deletion fractor-xml/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
},
"scripts": {
"analyze:php": "phpstan analyze",
"style:php": "ecs",
"style:php:check": "ecs",
"style:php:fix": "ecs --fix",
"test:php": "phpunit tests/"
}
}
3 changes: 2 additions & 1 deletion fractor/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"scripts": {
"analyze:php": "phpstan analyze",
"style:php": "ecs",
"style:php:check": "ecs",
"style:php:fix": "ecs --fix",
"test:php": "phpunit tests/"
}
}
9 changes: 6 additions & 3 deletions fractor/src/FileSystem/FileFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ final class FileFinder
*/
public function findFiles(array $directories, array $fileExtensions): array
{
if ($directories === []) {
throw new \UnexpectedValueException('Directories must not be an empty array');
}

$finder = Finder::create()
->files()
// skip empty files
->size('> 0')
->in($directories);

if ($fileExtensions !== []) {
$pattern = sprintf('/(%s)/', implode('|', $fileExtensions));
$finder->name($pattern);
foreach ($fileExtensions as $fileExtension) {
$finder->name('*.' . $fileExtension);
}

$files = [];
Expand Down
39 changes: 39 additions & 0 deletions fractor/tests/FileSystem/FileFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace FileSystem;

use a9f\Fractor\FileSystem\FileFinder;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use UnexpectedValueException;

final class FileFinderTest extends TestCase
{
private FileFinder $subject;

protected function setUp(): void
{
$this->subject = new FileFinder();
}

#[Test]
public function anExceptionIsThrownWhenDirectoriesAreEmpty(): void
{
$this->expectException(UnexpectedValueException::class);
$this->subject->findFiles([], []);
}

#[Test]
public function findAllNonEmptyFilesInGivenDirectories(): void
{
self::assertCount(4, $this->subject->findFiles([__DIR__ . '/Fixture/DirectorToSearchIn'], []));
}

#[Test]
public function findAllNonEmptyFilesInGivenDirectoriesWithGivenExtensions(): void
{
self::assertCount(2, $this->subject->findFiles([__DIR__ . '/Fixture/DirectorToSearchIn'], ['txt', 'json']));
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
My file
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yaml:
test: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
My file
3 changes: 2 additions & 1 deletion typo3-fractor/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
},
"scripts": {
"analyze:php": "phpstan analyze",
"style:php": "ecs",
"style:php:check": "ecs",
"style:php:fix": "ecs --fix",
"test:php": "phpunit tests/"
}
}

0 comments on commit 89d064f

Please sign in to comment.