-
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.
- Loading branch information
1 parent
0b3a946
commit ff4ce29
Showing
3 changed files
with
163 additions
and
51 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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Nexus framework. | ||
* | ||
* (c) John Paul E. Balandan, CPA <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nexus\Tests\AutoReview; | ||
|
||
use PHPUnit\Framework\Attributes\CoversNothing; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Group; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[CoversNothing] | ||
#[Group('package-test')] | ||
final class PackageMetadataTest extends TestCase | ||
{ | ||
use PackageTrait; | ||
|
||
/** | ||
* @var list<string> | ||
*/ | ||
private const METADATA_FILES = [ | ||
'LICENSE', | ||
'README.md', | ||
]; | ||
|
||
#[DataProvider('provideMetadataFilesExistForPackageCases')] | ||
public function testMetadataFilesExistForPackage(string $package, string $metadata): void | ||
{ | ||
$metadataFile = $package.\DIRECTORY_SEPARATOR.$metadata; | ||
|
||
self::assertFileExists($metadataFile); | ||
self::assertFileIsReadable($metadataFile); | ||
self::assertFileIsWritable($metadataFile); | ||
} | ||
|
||
/** | ||
* @return iterable<string, array{string, string}> | ||
*/ | ||
public static function provideMetadataFilesExistForPackageCases(): iterable | ||
{ | ||
foreach (self::getPackageDirectories() as $package) { | ||
foreach (self::METADATA_FILES as $metadata) { | ||
yield $package.\DIRECTORY_SEPARATOR.$metadata => [$package, $metadata]; | ||
} | ||
} | ||
} | ||
} |
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,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Nexus framework. | ||
* | ||
* (c) John Paul E. Balandan, CPA <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nexus\Tests\AutoReview; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
trait PackageTrait | ||
{ | ||
/** | ||
* @var list<string> | ||
*/ | ||
private static array $packages = []; | ||
|
||
/** | ||
* @return list<string> | ||
*/ | ||
private static function getPackageDirectories(): array | ||
{ | ||
if ([] !== self::$packages) { | ||
return self::$packages; | ||
} | ||
|
||
$finder = new \RecursiveIteratorIterator( | ||
new \RecursiveDirectoryIterator( | ||
'src/Nexus', | ||
\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::UNIX_PATHS, | ||
), | ||
); | ||
$finder->setMaxDepth(3); | ||
|
||
/** | ||
* @var \SplFileInfo $splFileInfo | ||
*/ | ||
foreach ($finder as $file => $splFileInfo) { | ||
if ('composer.json' === $file) { | ||
self::$packages[] = \dirname($splFileInfo->getPathname()); | ||
} | ||
} | ||
|
||
return self::$packages; | ||
} | ||
|
||
private function getPackageName(string $package): string | ||
{ | ||
static $specialCases = [ | ||
'PHPStan' => 'phpstan-nexus', | ||
]; | ||
|
||
$package = basename($package); | ||
|
||
return \sprintf( | ||
'nexusphp/%s', | ||
$specialCases[$package] ?? strtolower(preg_replace( | ||
'/(?<!^)((?=[A-Z][^A-Z])|(?<![A-Z])(?=[A-Z]))/u', | ||
'_', | ||
$package, | ||
) ?? $package), | ||
); | ||
} | ||
} |