diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 0688d67..5cd87b3 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -18,10 +18,11 @@ jobs: - "8.3" - "8.4" - "8.5" + - "8.6" steps: - name: Checkout - uses: actions/checkout@v5 + uses: actions/checkout@v7 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -35,7 +36,7 @@ jobs: run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - name: Cache dependencies installed with composer - uses: actions/cache@v3 + uses: actions/cache@v6 with: path: ${{ env.COMPOSER_CACHE_DIR }} key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} @@ -48,6 +49,6 @@ jobs: run: vendor/bin/phpunit --colors=always --coverage-clover clover.xml - name: Send code coverage report to Codecov.io - uses: codecov/codecov-action@v5 + uses: codecov/codecov-action@v7 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 63e06de..2763b9c 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -18,10 +18,11 @@ jobs: - "8.3" - "8.4" - "8.5" + - "8.6" steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -35,7 +36,7 @@ jobs: run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - name: Cache dependencies installed with composer - uses: actions/cache@v4 + uses: actions/cache@v6 with: path: ${{ env.COMPOSER_CACHE_DIR }} key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/README.md b/README.md index c51faba..c69a3ab 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ Documentation is available at: https://docs.dotkernel.org/dot-maker/. [![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-maker)](https://github.com/dotkernel/dot-maker/stargazers) [![GitHub license](https://img.shields.io/github/license/dotkernel/dot-maker)](https://github.com/dotkernel/dot-maker/blob/2.0/LICENSE) -[![Build Static](https://github.com/dotkernel/dot-maker/actions/workflows/continuous-integration.yml/badge.svg?branch=2.0)](https://github.com/dotkernel/dot-maker/actions/workflows/continuous-integration.yml) +[![Build Static](https://github.com/dotkernel/dot-maker/actions/workflows/continuous-integration.yml/badge.svg?branch=2.x)](https://github.com/dotkernel/dot-maker/actions/workflows/continuous-integration.yml) [![codecov](https://codecov.io/gh/dotkernel/dot-maker/graph/badge.svg?token=KT9UA402B4)](https://codecov.io/gh/dotkernel/dot-maker) -[![PHPStan](https://github.com/dotkernel/dot-maker/actions/workflows/static-analysis.yml/badge.svg?branch=2.0)](https://github.com/dotkernel/dot-maker/actions/workflows/static-analysis.yml) +[![PHPStan](https://github.com/dotkernel/dot-maker/actions/workflows/static-analysis.yml/badge.svg?branch=2.x)](https://github.com/dotkernel/dot-maker/actions/workflows/static-analysis.yml) ## Installation diff --git a/composer.json b/composer.json index 7250728..3acaa1c 100644 --- a/composer.json +++ b/composer.json @@ -28,15 +28,14 @@ } }, "require": { - "php": "~8.3.0 || ~8.4.0 || ~8.5.0" + "php": "~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0" }, "require-dev": { "boundwize/structarmed": "^0.19", "laminas/laminas-coding-standard": "^3.1.0", - "mikey179/vfsstream": "^1.6.12", "phpstan/phpstan": "^2.1.33", "phpstan/phpstan-phpunit": "^2.0.10", - "phpunit/phpunit": "^10.5.60" + "phpunit/phpunit": "^12.5.22" }, "scripts": { "check": [ diff --git a/docs/book/v2/overview.md b/docs/book/v2/overview.md index f6b9c2e..68ac60f 100644 --- a/docs/book/v2/overview.md +++ b/docs/book/v2/overview.md @@ -12,9 +12,9 @@ Programmatically generate Dotkernel project files and directories. [![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-maker)](https://github.com/dotkernel/dot-maker/stargazers) [![GitHub license](https://img.shields.io/github/license/dotkernel/dot-maker)](https://github.com/dotkernel/dot-maker/blob/2.0/LICENSE) -[![Build Static](https://github.com/dotkernel/dot-maker/actions/workflows/continuous-integration.yml/badge.svg?branch=2.0)](https://github.com/dotkernel/dot-maker/actions/workflows/continuous-integration.yml) +[![Build Static](https://github.com/dotkernel/dot-maker/actions/workflows/continuous-integration.yml/badge.svg?branch=2.x)](https://github.com/dotkernel/dot-maker/actions/workflows/continuous-integration.yml) [![codecov](https://codecov.io/gh/dotkernel/dot-maker/graph/badge.svg?token=KT9UA402B4)](https://codecov.io/gh/dotkernel/dot-maker) -[![PHPStan](https://github.com/dotkernel/dot-maker/actions/workflows/static-analysis.yml/badge.svg?branch=2.0)](https://github.com/dotkernel/dot-maker/actions/workflows/static-analysis.yml) +[![PHPStan](https://github.com/dotkernel/dot-maker/actions/workflows/static-analysis.yml/badge.svg?branch=2.x)](https://github.com/dotkernel/dot-maker/actions/workflows/static-analysis.yml) Make sure you run through our guides on using the [inputs](./io/input.md) and the [outputs](./io/output.md). diff --git a/phpstan.neon b/phpstan.neon index 701a4a2..349be25 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,7 +6,3 @@ parameters: - src - test treatPhpDocTypesAsCertain: false - ignoreErrors: - - - message: '#Call to an undefined method org\\bovigo\\vfs\\vfsStreamContent::getChild\(\).#' - path: %currentWorkingDirectory%/test/FileSystem/FileTest.php diff --git a/phpunit.xml b/phpunit.xml index 52cc404..f70f3a1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ diff --git a/test/Component/CoreImportTest.php b/test/Component/CoreImportTest.php index c0895cd..a92bc06 100644 --- a/test/Component/CoreImportTest.php +++ b/test/Component/CoreImportTest.php @@ -6,7 +6,7 @@ use Dot\Maker\Component\Import; use Dot\Maker\Context; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; class CoreImportTest extends TestCase @@ -15,7 +15,7 @@ class CoreImportTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -26,7 +26,7 @@ protected function setUp(): void }', ]); - $this->context = new Context($root->url()); + $this->context = new Context($root); } public function testWillGetAbstractFormFqcn(): void diff --git a/test/Component/ImportTest.php b/test/Component/ImportTest.php index 7fe8bd0..3dca35c 100644 --- a/test/Component/ImportTest.php +++ b/test/Component/ImportTest.php @@ -6,7 +6,7 @@ use Dot\Maker\Component\Import; use Dot\Maker\Context; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; class ImportTest extends TestCase @@ -15,7 +15,7 @@ class ImportTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -25,7 +25,7 @@ protected function setUp(): void }', ]); - $this->context = new Context($root->url()); + $this->context = new Context($root); } public function testWillGetAbstractFormFqcn(): void diff --git a/test/ConfigTest.php b/test/ConfigTest.php index f0b3f32..5bf00bd 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -5,7 +5,7 @@ namespace DotTest\Maker; use Dot\Maker\Config; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function sprintf; @@ -20,7 +20,7 @@ public function testWillInstantiateWithoutConfigFile(): void public function testConfigFileWithoutMakerKeyWillThrowError(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'config' => [ 'autoload' => [ 'maker.local.php' => <<expectExceptionMessage( - sprintf('%s/%s: key "Maker::class" not found', $fileSystem->url(), Config::CONFIG_FILE) + sprintf('%s/%s: key "Maker::class" not found', $fileSystem, Config::CONFIG_FILE) ); - $config = new Config($fileSystem->url()); + $config = new Config($fileSystem); $this->assertContainsOnlyInstancesOf(Config::class, [$config]); } } diff --git a/test/ContextTest.php b/test/ContextTest.php index 6c21984..3a610fe 100644 --- a/test/ContextTest.php +++ b/test/ContextTest.php @@ -5,7 +5,7 @@ namespace DotTest\Maker; use Dot\Maker\Context; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function sprintf; @@ -22,39 +22,39 @@ public function testWillNotInstantiateWithoutComposerJson(): void public function testWillNotInstantiateWithInvalidComposerJson(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'composer.json' => '', ]); - $this->expectExceptionMessage(sprintf('%s/composer.json: invalid JSON', $fileSystem->url())); + $this->expectExceptionMessage(sprintf('%s/composer.json: invalid JSON', $fileSystem)); - new Context($fileSystem->url()); + new Context($fileSystem); } public function testWillNotInstantiateWithoutComposerJsonAutoload(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'composer.json' => '{}', ]); - $this->expectExceptionMessage(sprintf('%s/composer.json: key "autoload" not found', $fileSystem->url())); + $this->expectExceptionMessage(sprintf('%s/composer.json: key "autoload" not found', $fileSystem)); - new Context($fileSystem->url()); + new Context($fileSystem); } public function testWillNotInstantiateWithoutComposerJsonAutoloadPSR4(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'composer.json' => '{"autoload":[]}', ]); $this->expectExceptionMessage( - sprintf('%s/composer.json: key "autoload"."psr-4" not found', $fileSystem->url()) + sprintf('%s/composer.json: key "autoload"."psr-4" not found', $fileSystem) ); - new Context($fileSystem->url()); + new Context($fileSystem); } public function testWillDetectCoreArchitectureWhenUsed(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -65,13 +65,13 @@ public function testWillDetectCoreArchitectureWhenUsed(): void }', ]); - $context = new Context($fileSystem->url()); + $context = new Context($fileSystem); $this->assertTrue($context->hasCore()); } public function testWillDetectCoreArchitectureWhenNotUsed(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -82,13 +82,13 @@ public function testWillDetectCoreArchitectureWhenNotUsed(): void }', ]); - $context = new Context($fileSystem->url()); + $context = new Context($fileSystem); $this->assertFalse($context->hasCore()); } public function testWillDetectProjectTypeAdmin(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -99,7 +99,7 @@ public function testWillDetectProjectTypeAdmin(): void }', ]); - $context = new Context($fileSystem->url()); + $context = new Context($fileSystem); $this->assertTrue($context->isAdmin()); $this->assertFalse($context->isApi()); $this->assertFalse($context->isFrontend()); @@ -110,7 +110,7 @@ public function testWillDetectProjectTypeAdmin(): void public function testWillDetectProjectTypeApi(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -121,7 +121,7 @@ public function testWillDetectProjectTypeApi(): void }', ]); - $context = new Context($fileSystem->url()); + $context = new Context($fileSystem); $this->assertFalse($context->isAdmin()); $this->assertTrue($context->isApi()); $this->assertFalse($context->isFrontend()); @@ -132,7 +132,7 @@ public function testWillDetectProjectTypeApi(): void public function testWillDetectProjectTypeFrontend(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -143,7 +143,7 @@ public function testWillDetectProjectTypeFrontend(): void }', ]); - $context = new Context($fileSystem->url()); + $context = new Context($fileSystem); $this->assertFalse($context->isAdmin()); $this->assertFalse($context->isApi()); $this->assertTrue($context->isFrontend()); @@ -154,7 +154,7 @@ public function testWillDetectProjectTypeFrontend(): void public function testWillDetectProjectTypeLight(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -165,7 +165,7 @@ public function testWillDetectProjectTypeLight(): void }', ]); - $context = new Context($fileSystem->url()); + $context = new Context($fileSystem); $this->assertFalse($context->isAdmin()); $this->assertFalse($context->isApi()); $this->assertFalse($context->isFrontend()); @@ -176,7 +176,7 @@ public function testWillDetectProjectTypeLight(): void public function testWillDetectProjectTypeQueue(): void { - $fileSystem = vfsStream::setup('root', 0644, [ + $fileSystem = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -187,7 +187,7 @@ public function testWillDetectProjectTypeQueue(): void }', ]); - $context = new Context($fileSystem->url()); + $context = new Context($fileSystem); $this->assertFalse($context->isAdmin()); $this->assertFalse($context->isApi()); $this->assertFalse($context->isFrontend()); diff --git a/test/FileSystem/DirectoryTest.php b/test/FileSystem/DirectoryTest.php index b3f4b77..63ce2c6 100644 --- a/test/FileSystem/DirectoryTest.php +++ b/test/FileSystem/DirectoryTest.php @@ -6,63 +6,62 @@ use Dot\Maker\Component; use Dot\Maker\FileSystem\Directory; -use org\bovigo\vfs\vfsStream; -use org\bovigo\vfs\vfsStreamDirectory; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; class DirectoryTest extends TestCase { - private vfsStreamDirectory $root; + private string $root; protected function setUp(): void { - $this->root = vfsStream::setup('root', 0644, [ + $this->root = TemporaryDirectory::create([ 'Existing' => [], ]); } public function testWillInstantiate(): void { - $directory = new Directory('any', $this->root->url()); + $directory = new Directory('any', $this->root); $this->assertContainsOnlyInstancesOf(Directory::class, [$directory]); } public function testWillCreate(): void { - $this->assertFalse($this->root->hasChild('New')); - $directory = new Directory('New', $this->root->url()); + $this->assertDirectoryDoesNotExist($this->root . '/New'); + $directory = new Directory('New', $this->root); $directory->create(); - $this->assertTrue($this->root->hasChild('New')); + $this->assertDirectoryExists($this->root . '/New'); } public function testWillDetectExistingDirectory(): void { - $directory = new Directory('Existing', $this->root->url()); + $directory = new Directory('Existing', $this->root); $this->assertTrue($directory->exists()); } public function testWillGetComponent(): void { - $directory = new Directory('Existing', $this->root->url()); + $directory = new Directory('Existing', $this->root); $this->assertContainsOnlyInstancesOf(Component::class, [$directory->getComponent()]); } public function testWillGetName(): void { - $directory = new Directory('Existing', $this->root->url()); + $directory = new Directory('Existing', $this->root); $this->assertSame('Existing', $directory->getName()); } public function testWillGetPath(): void { - $directory = new Directory('Existing', $this->root->url()); - $this->assertSame($this->root->getChild('Existing')->url(), $directory->getPath()); + $directory = new Directory('Existing', $this->root); + $this->assertSame($this->root . '/Existing', $directory->getPath()); } public function testWillGetParentDirectory(): void { - $directory = new Directory('Existing', $this->root->url()); - $this->assertSame($this->root->url(), $directory->getParentDirectory()); + $directory = new Directory('Existing', $this->root); + $this->assertSame($this->root, $directory->getParentDirectory()); } } diff --git a/test/FileSystem/FileTest.php b/test/FileSystem/FileTest.php index 2d186a7..c00cb59 100644 --- a/test/FileSystem/FileTest.php +++ b/test/FileSystem/FileTest.php @@ -7,23 +7,24 @@ use Dot\Maker\Component; use Dot\Maker\FileSystem\Directory; use Dot\Maker\FileSystem\File; -use org\bovigo\vfs\vfsStream; -use org\bovigo\vfs\vfsStreamContent; -use org\bovigo\vfs\vfsStreamDirectory; +use DotTest\Maker\Fixture\TemporaryDirectory; +use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; use PHPUnit\Framework\TestCase; +use function file_put_contents; +use function restore_error_handler; +use function set_error_handler; use function sprintf; -/** - * @method vfsStreamContent getChild(string $name) - */ +use const E_WARNING; + class FileTest extends TestCase { - private vfsStreamDirectory $root; + private string $root; protected function setUp(): void { - $this->root = vfsStream::setup('root', 0644, [ + $this->root = TemporaryDirectory::create([ 'src' => [ 'App' => [ 'src' => [ @@ -37,7 +38,7 @@ protected function setUp(): void public function testWillInstantiate(): void { $file = new File( - new Directory('Test', $this->root->url()), + new Directory('Test', $this->root), 'Test', 'Test' ); @@ -45,12 +46,13 @@ public function testWillInstantiate(): void $this->assertContainsOnlyInstancesOf(File::class, [$file]); } + #[AllowMockObjectsWithoutExpectations] public function testFailingToCreateWillThrowAnError(): void { $file = $this->getMockBuilder(File::class) ->onlyMethods(['write']) ->setConstructorArgs([ - new Directory('src', $this->root->getChild('src')->getChild('App')->url()), + new Directory('src', $this->root . '/src/App'), 'Api\\App', 'ConfigProvider', ]) @@ -69,7 +71,7 @@ public function testFailingToCreateWillThrowAnError(): void public function testWillCreate(): void { $file = new File( - new Directory('src', $this->root->getChild('src')->getChild('App')->url()), + new Directory('src', $this->root . '/src/App'), 'Api\\App', 'ConfigProvider' ); @@ -83,8 +85,11 @@ public function testWillCreate(): void public function testWillThrowAnErrorIfCannotCreateParentDirectory(): void { + $blocker = $this->root . '/blocker'; + file_put_contents($blocker, 'not a directory'); + $file = new File( - new Directory('Nonexistent', $this->root->chmod(0000)->url()), + new Directory('Nonexistent', $blocker), 'Test', 'Test' ); @@ -92,13 +97,20 @@ public function testWillThrowAnErrorIfCannotCreateParentDirectory(): void $this->expectExceptionMessage( sprintf('Could not create parent directory "%s"', $file->getParentDirectory()->getPath()) ); - $file->ensureParentDirectoryExists(); + + // mkdir() reports the expected failure as a warning. Keep it out of the test output. + set_error_handler(static fn (): bool => true, E_WARNING); + try { + $file->ensureParentDirectoryExists(); + } finally { + restore_error_handler(); + } } public function testWillDetectExistingFile(): void { $file = new File( - new Directory('src', $this->root->getChild('src')->getChild('App')->url()), + new Directory('src', $this->root . '/src/App'), 'Api\\App', 'Existing' ); @@ -108,17 +120,17 @@ public function testWillDetectExistingFile(): void public function testWillGetParentDirectory(): void { $file = new File( - new Directory('src', $this->root->url()), + new Directory('src', $this->root), 'Test', 'Test' ); - $this->assertSame($this->root->getChild('src')->url(), $file->getParentDirectory()->getPath()); + $this->assertSame($this->root . '/src', $file->getParentDirectory()->getPath()); } public function testWillGetComponent(): void { $file = new File( - new Directory('src', $this->root->url()), + new Directory('src', $this->root), 'Test', 'Test' ); @@ -128,7 +140,7 @@ public function testWillGetComponent(): void public function testWillGetName(): void { $file = new File( - new Directory('src', $this->root->url()), + new Directory('src', $this->root), 'Namespace', 'Test' ); @@ -138,12 +150,12 @@ public function testWillGetName(): void public function testWillGetPath(): void { $file = new File( - new Directory('src', $this->root->getChild('src')->getChild('App')->url()), + new Directory('src', $this->root . '/src/App'), 'Api\\App', 'Existing' ); $this->assertSame( - $this->root->getChild('src')->getChild('App')->getChild('src')->getChild('Existing.php')->url(), + $this->root . '/src/App/src/Existing.php', $file->getPath() ); } diff --git a/test/Fixture/TemporaryDirectory.php b/test/Fixture/TemporaryDirectory.php new file mode 100644 index 0000000..16f8cf0 --- /dev/null +++ b/test/Fixture/TemporaryDirectory.php @@ -0,0 +1,115 @@ + */ + private static array $paths = []; + + private static bool $registered = false; + + /** + * Create a temporary directory and fill it with the given structure. + * + * A string value becomes a file. An array value becomes a directory. + * + * @param array $structure + * @throws RuntimeException + */ + public static function create(array $structure = []): string + { + $path = sprintf('%s/%s', sys_get_temp_dir(), uniqid('dot-maker-test-', true)); + if (! mkdir($path, 0o777, true)) { + throw new RuntimeException(sprintf('Cannot create "%s".', $path)); + } + + self::$paths[] = $path; + if (! self::$registered) { + self::$registered = true; + register_shutdown_function(static function (): void { + self::removeAll(); + }); + } + + self::fill($path, $structure); + + return $path; + } + + public static function remove(string $path): void + { + if (! is_dir($path)) { + return; + } + + $items = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST + ); + + /** @var SplFileInfo $item */ + foreach ($items as $item) { + if ($item->isDir() && ! $item->isLink()) { + rmdir($item->getPathname()); + } else { + unlink($item->getPathname()); + } + } + + rmdir($path); + } + + public static function removeAll(): void + { + foreach (self::$paths as $path) { + self::remove($path); + } + + self::$paths = []; + } + + /** + * @param array $structure + * @throws RuntimeException + */ + private static function fill(string $path, array $structure): void + { + foreach ($structure as $name => $value) { + $target = sprintf('%s/%s', $path, $name); + if (is_array($value)) { + if (! is_dir($target) && ! mkdir($target, 0o777, true)) { + throw new RuntimeException(sprintf('Cannot create "%s".', $target)); + } + self::fill($target, $value); + continue; + } + + if (file_put_contents($target, (string) $value) === false) { + throw new RuntimeException(sprintf('Cannot write "%s".', $target)); + } + } + } +} diff --git a/test/IO/InputTest.php b/test/IO/InputTest.php index dbe83e7..8777721 100644 --- a/test/IO/InputTest.php +++ b/test/IO/InputTest.php @@ -6,6 +6,7 @@ use Dot\Maker\IO\Input; use Dot\Maker\IO\Output; +use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use function fclose; @@ -60,13 +61,11 @@ public function testPromptWillOutputMessageAndReadInput(): void fclose($outputStream); } - /** - * @testWith [""] - * ["y"] - * ["yes"] - * ["Y"] - * ["Yes"] - */ + #[TestWith([''])] + #[TestWith(['y'])] + #[TestWith(['yes'])] + #[TestWith(['Y'])] + #[TestWith(['Yes'])] public function testConfirmWillOutputMessageAndReadPositiveAnswer(string $input): void { $outputStream = fopen('php://memory', 'w+'); @@ -86,13 +85,11 @@ public function testConfirmWillOutputMessageAndReadPositiveAnswer(string $input) fclose($outputStream); } - /** - * @testWith [""] - * ["n"] - * ["no"] - * ["N"] - * ["No"] - */ + #[TestWith([''])] + #[TestWith(['n'])] + #[TestWith(['no'])] + #[TestWith(['N'])] + #[TestWith(['No'])] public function testConfirmWillOutputMessageAndReadNegativeAnswer(string $input): void { $outputStream = fopen('php://memory', 'w+'); diff --git a/test/MakerTest.php b/test/MakerTest.php index 194df4f..af16cad 100644 --- a/test/MakerTest.php +++ b/test/MakerTest.php @@ -8,7 +8,8 @@ use Dot\Maker\IO\Input; use Dot\Maker\IO\Output; use Dot\Maker\Maker; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; +use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; use PHPUnit\Framework\TestCase; use function fclose; @@ -19,6 +20,7 @@ use const PHP_EOL; +#[AllowMockObjectsWithoutExpectations] class MakerTest extends TestCase { /** @var resource $outputStream */ @@ -72,7 +74,7 @@ public function testCallingInvokeWillOutputErrorWhenNotInCliMode(): void public function testCallingInvokeWillOutputErrorWhenInvalidComponent(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -85,7 +87,7 @@ public function testCallingInvokeWillOutputErrorWhenInvalidComponent(): void $maker = $this->getMockBuilder(Maker::class) ->onlyMethods(['isCli']) - ->setConstructorArgs([$root->url()]) + ->setConstructorArgs([$root]) ->getMock(); $maker->method('isCli')->willReturn(true); $maker(['', 'invalid-component']); @@ -101,7 +103,7 @@ public function testCallingInvokeWillOutputErrorWhenInvalidComponent(): void public function testCallingInvokeWithoutArgsWillOutputHelpText(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -114,7 +116,7 @@ public function testCallingInvokeWithoutArgsWillOutputHelpText(): void $maker = $this->getMockBuilder(Maker::class) ->onlyMethods(['isCli']) - ->setConstructorArgs([$root->url()]) + ->setConstructorArgs([$root]) ->getMock(); $maker->method('isCli')->willReturn(true); $maker(['', '']); @@ -130,7 +132,7 @@ public function testCallingInvokeWithoutArgsWillOutputHelpText(): void public function testCallingInvokeWithArgsModuleWillOutputDebugInfo(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -145,7 +147,7 @@ public function testCallingInvokeWithArgsModuleWillOutputDebugInfo(): void $maker = $this->getMockBuilder(Maker::class) ->onlyMethods(['isCli']) - ->setConstructorArgs([$root->url()]) + ->setConstructorArgs([$root]) ->getMock(); $maker->method('isCli')->willReturn(true); $maker(['', 'module']); @@ -165,7 +167,7 @@ public function testCallingInvokeWithArgsModuleWillOutputDebugInfo(): void public function testCallingInvokeWithValidComponentIdentifierWillSucceed(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -185,7 +187,7 @@ public function testCallingInvokeWithValidComponentIdentifierWillSucceed(): void $maker = $this->getMockBuilder(Maker::class) ->onlyMethods(['isCli']) - ->setConstructorArgs([$root->url()]) + ->setConstructorArgs([$root]) ->getMock(); $maker->method('isCli')->willReturn(true); $maker(['', 'command']); diff --git a/test/Type/CollectionTest.php b/test/Type/CollectionTest.php index bb0addd..13223fe 100644 --- a/test/Type/CollectionTest.php +++ b/test/Type/CollectionTest.php @@ -12,7 +12,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Collection; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -43,7 +43,7 @@ class CollectionTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -53,8 +53,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -113,7 +113,7 @@ public function testCallToCreateWillFailWhenAlreadyExists(): void public function testCallToInvokeWillOutputErrorAndWillNotCreateFileWhenProjectTypeIsNotAPI(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -123,7 +123,7 @@ public function testCallToInvokeWillOutputErrorAndWillNotCreateFileWhenProjectTy }', ]); - $this->context = new Context($root->url()); + $this->context = new Context($root); $file = $this->fileSystem->collection($this->resourceName); $this->assertFileDoesNotExist($file->getPath()); diff --git a/test/Type/CommandTest.php b/test/Type/CommandTest.php index 15ad72f..924709a 100644 --- a/test/Type/CommandTest.php +++ b/test/Type/CommandTest.php @@ -13,7 +13,8 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Command; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function fclose; @@ -44,7 +45,7 @@ class CommandTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -54,8 +55,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -147,9 +148,7 @@ public function testCallToInvokeWillOutputErrorAndWillNotCreateFileWhenNameIsInv $this->assertFileDoesNotExist($file->getPath()); } - /** - * @dataProvider dataProviderWithoutService - */ + #[DataProvider('dataProviderWithoutService')] public function testCallToInvokeWithoutServiceWillSucceedWhenNameIsValid(string $expected): void { $file = $this->fileSystem->command($this->resourceName); @@ -191,9 +190,7 @@ public function testCallToInvokeWithServiceWillSucceedWhenNameIsValid(): void $this->assertSame($this->dataProviderWithService($serviceInterface), $file->read()); } - /** - * @dataProvider dataProviderWithoutService - */ + #[DataProvider('dataProviderWithoutService')] public function testCallToCreateWithoutServiceWillSucceedWhenNameIsValid(string $expected): void { $file = $this->fileSystem->command($this->resourceName); diff --git a/test/Type/ConfigProviderTest.php b/test/Type/ConfigProviderTest.php index 523b5f2..635ba32 100644 --- a/test/Type/ConfigProviderTest.php +++ b/test/Type/ConfigProviderTest.php @@ -11,12 +11,13 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\ConfigProvider; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; use function fopen; use function rewind; +use function sprintf; use function stream_get_contents; use const PHP_EOL; @@ -45,7 +46,7 @@ protected function tearDown(): void public function testWillCreateFileWhenProjectTypeIsApiAndUsesCore(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -56,8 +57,8 @@ public function testWillCreateFileWhenProjectTypeIsApiAndUsesCore(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -73,7 +74,7 @@ public function testWillCreateFileWhenProjectTypeIsApiAndUsesCore(): void $this->assertTrue($file->exists()); $this->assertSame( ColorEnum::colorize( - 'Created ConfigProvider: vfs://root/src/ModuleName/src/ConfigProvider.php', + sprintf('Created ConfigProvider: %s/src/ModuleName/src/ConfigProvider.php', $root), ColorEnum::ForegroundBrightGreen ) . PHP_EOL, stream_get_contents($this->outputStream) @@ -83,7 +84,7 @@ public function testWillCreateFileWhenProjectTypeIsApiAndUsesCore(): void public function testWillCreateFileWhenProjectTypeIsNotApiAndUsesCore(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -94,8 +95,8 @@ public function testWillCreateFileWhenProjectTypeIsNotApiAndUsesCore(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -111,7 +112,7 @@ public function testWillCreateFileWhenProjectTypeIsNotApiAndUsesCore(): void $this->assertTrue($file->exists()); $this->assertSame( ColorEnum::colorize( - 'Created ConfigProvider: vfs://root/src/ModuleName/src/ConfigProvider.php', + sprintf('Created ConfigProvider: %s/src/ModuleName/src/ConfigProvider.php', $root), ColorEnum::ForegroundBrightGreen ) . PHP_EOL, stream_get_contents($this->outputStream) @@ -121,7 +122,7 @@ public function testWillCreateFileWhenProjectTypeIsNotApiAndUsesCore(): void public function testWillCreateFileWhenProjectTypeIsApiAndDoesNotUseCore(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -131,8 +132,8 @@ public function testWillCreateFileWhenProjectTypeIsApiAndDoesNotUseCore(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -148,7 +149,7 @@ public function testWillCreateFileWhenProjectTypeIsApiAndDoesNotUseCore(): void $this->assertTrue($file->exists()); $this->assertSame( ColorEnum::colorize( - 'Created ConfigProvider: vfs://root/src/ModuleName/src/ConfigProvider.php', + sprintf('Created ConfigProvider: %s/src/ModuleName/src/ConfigProvider.php', $root), ColorEnum::ForegroundBrightGreen ) . PHP_EOL, stream_get_contents($this->outputStream) @@ -158,7 +159,7 @@ public function testWillCreateFileWhenProjectTypeIsApiAndDoesNotUseCore(): void public function testWillCreateFileWhenProjectTypeIsNotApiAndDoesNotUseCore(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -168,8 +169,8 @@ public function testWillCreateFileWhenProjectTypeIsNotApiAndDoesNotUseCore(): vo }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -185,7 +186,7 @@ public function testWillCreateFileWhenProjectTypeIsNotApiAndDoesNotUseCore(): vo $this->assertTrue($file->exists()); $this->assertSame( ColorEnum::colorize( - 'Created ConfigProvider: vfs://root/src/ModuleName/src/ConfigProvider.php', + sprintf('Created ConfigProvider: %s/src/ModuleName/src/ConfigProvider.php', $root), ColorEnum::ForegroundBrightGreen ) . PHP_EOL, stream_get_contents($this->outputStream) diff --git a/test/Type/CoreConfigProviderTest.php b/test/Type/CoreConfigProviderTest.php index a2e8bc8..048329c 100644 --- a/test/Type/CoreConfigProviderTest.php +++ b/test/Type/CoreConfigProviderTest.php @@ -11,12 +11,13 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\CoreConfigProvider; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; use function fopen; use function rewind; +use function sprintf; use function stream_get_contents; use const PHP_EOL; @@ -45,7 +46,7 @@ protected function tearDown(): void public function testWillThrowErrorAndNotCreateFileWhenProjectTypeIsApiAndCoreIsNotUsed(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -55,8 +56,8 @@ public function testWillThrowErrorAndNotCreateFileWhenProjectTypeIsApiAndCoreIsN }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -70,7 +71,7 @@ public function testWillThrowErrorAndNotCreateFileWhenProjectTypeIsApiAndCoreIsN public function testWillThrowErrorAndNotCreateFileWhenProjectTypeIsNotApiAndCoreIsNotUsed(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -80,8 +81,8 @@ public function testWillThrowErrorAndNotCreateFileWhenProjectTypeIsNotApiAndCore }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -95,7 +96,7 @@ public function testWillThrowErrorAndNotCreateFileWhenProjectTypeIsNotApiAndCore public function testWillCreateFileWhenProjectTypeIsApi(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -106,8 +107,8 @@ public function testWillCreateFileWhenProjectTypeIsApi(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -123,7 +124,7 @@ public function testWillCreateFileWhenProjectTypeIsApi(): void $this->assertTrue($file->exists()); $this->assertSame( ColorEnum::colorize( - 'Created Core ConfigProvider: vfs://root/src/Core/src/ModuleName/src/ConfigProvider.php', + sprintf('Created Core ConfigProvider: %s/src/Core/src/ModuleName/src/ConfigProvider.php', $root), ColorEnum::ForegroundBrightGreen ) . PHP_EOL, stream_get_contents($this->outputStream) @@ -133,7 +134,7 @@ public function testWillCreateFileWhenProjectTypeIsApi(): void public function testWillCreateFileWhenProjectTypeIsNotApi(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -144,8 +145,8 @@ public function testWillCreateFileWhenProjectTypeIsNotApi(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -161,7 +162,7 @@ public function testWillCreateFileWhenProjectTypeIsNotApi(): void $this->assertTrue($file->exists()); $this->assertSame( ColorEnum::colorize( - 'Created Core ConfigProvider: vfs://root/src/Core/src/ModuleName/src/ConfigProvider.php', + sprintf('Created Core ConfigProvider: %s/src/Core/src/ModuleName/src/ConfigProvider.php', $root), ColorEnum::ForegroundBrightGreen ) . PHP_EOL, stream_get_contents($this->outputStream) diff --git a/test/Type/EntityTest.php b/test/Type/EntityTest.php index da9077f..5b7b3b0 100644 --- a/test/Type/EntityTest.php +++ b/test/Type/EntityTest.php @@ -11,7 +11,8 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Entity; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function fclose; @@ -41,7 +42,7 @@ class EntityTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -52,8 +53,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -145,9 +146,7 @@ public function testCallToInvokeWillOutputErrorAndWillNotCreateFileWhenNameIsInv $this->assertFileDoesNotExist($file->getPath()); } - /** - * @dataProvider dataProvider - */ + #[DataProvider('dataProvider')] public function testCallToInvokeWillSucceedWhenNameIsValid(string $expected): void { $file = $this->fileSystem->entity($this->resourceName); @@ -166,9 +165,7 @@ public function testCallToInvokeWillSucceedWhenNameIsValid(string $expected): vo $this->assertSame($expected, $file->read()); } - /** - * @dataProvider dataProvider - */ + #[DataProvider('dataProvider')] public function testCallToCreateWillSucceedWhenNameIsValid(string $expected): void { $file = $this->fileSystem->entity($this->resourceName); diff --git a/test/Type/FormTest.php b/test/Type/FormTest.php index 255b4e5..45ef20e 100644 --- a/test/Type/FormTest.php +++ b/test/Type/FormTest.php @@ -13,7 +13,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Form; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -45,7 +45,7 @@ class FormTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -55,8 +55,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -80,7 +80,7 @@ protected function tearDown(): void public function testCallToInvokeWillEarlyReturnWhenProjectTypeIsApi(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -90,8 +90,8 @@ public function testCallToInvokeWillEarlyReturnWhenProjectTypeIsApi(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); diff --git a/test/Type/Handler/ApiHandlerTest.php b/test/Type/Handler/ApiHandlerTest.php index 03d280f..9fa356b 100644 --- a/test/Type/Handler/ApiHandlerTest.php +++ b/test/Type/Handler/ApiHandlerTest.php @@ -12,7 +12,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Handler; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -44,7 +44,7 @@ class ApiHandlerTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -54,8 +54,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); diff --git a/test/Type/HandlerTest.php b/test/Type/HandlerTest.php index 1135bac..52659bc 100644 --- a/test/Type/HandlerTest.php +++ b/test/Type/HandlerTest.php @@ -12,7 +12,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Handler; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -44,7 +44,7 @@ class HandlerTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -54,8 +54,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); diff --git a/test/Type/HelpTest.php b/test/Type/HelpTest.php index 2c92cf5..9c3db1f 100644 --- a/test/Type/HelpTest.php +++ b/test/Type/HelpTest.php @@ -9,8 +9,8 @@ use Dot\Maker\FileSystem; use Dot\Maker\IO\Output; use Dot\Maker\Type\Help; +use DotTest\Maker\Fixture\TemporaryDirectory; use DotTest\Maker\Helper; -use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; use function fclose; @@ -26,7 +26,7 @@ class HelpTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -36,8 +36,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = new FileSystem($this->context); } diff --git a/test/Type/InputFilter/ApiInputFilterTest.php b/test/Type/InputFilter/ApiInputFilterTest.php index 2abdd41..174996d 100644 --- a/test/Type/InputFilter/ApiInputFilterTest.php +++ b/test/Type/InputFilter/ApiInputFilterTest.php @@ -12,7 +12,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\InputFilter; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -42,7 +42,7 @@ class ApiInputFilterTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -53,8 +53,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); diff --git a/test/Type/InputFilterTest.php b/test/Type/InputFilterTest.php index b49728f..9a55d4a 100644 --- a/test/Type/InputFilterTest.php +++ b/test/Type/InputFilterTest.php @@ -12,7 +12,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\InputFilter; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -42,7 +42,7 @@ class InputFilterTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -53,8 +53,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); diff --git a/test/Type/InputTest.php b/test/Type/InputTest.php index b7f9614..63af0dc 100644 --- a/test/Type/InputTest.php +++ b/test/Type/InputTest.php @@ -12,7 +12,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Input as InputType; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -44,7 +44,7 @@ class InputTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -54,8 +54,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); diff --git a/test/Type/MiddlewareTest.php b/test/Type/MiddlewareTest.php index ec4dc9f..c5694c8 100644 --- a/test/Type/MiddlewareTest.php +++ b/test/Type/MiddlewareTest.php @@ -13,7 +13,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Middleware; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -44,7 +44,7 @@ class MiddlewareTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -54,8 +54,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); diff --git a/test/Type/ModuleTest.php b/test/Type/ModuleTest.php index 8886614..83dc492 100644 --- a/test/Type/ModuleTest.php +++ b/test/Type/ModuleTest.php @@ -12,15 +12,19 @@ use Dot\Maker\IO\Output; use Dot\Maker\Message; use Dot\Maker\Type\Module; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; use function fopen; use function fwrite; +use function restore_error_handler; use function rewind; +use function set_error_handler; +use function sprintf; use function stream_get_contents; +use const E_WARNING; use const PHP_EOL; class ModuleTest extends TestCase @@ -59,7 +63,7 @@ protected function tearDown(): void public function testWillCallAccessors(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -69,8 +73,8 @@ public function testWillCallAccessors(): void }', ]); - $config = new Config($root->url()); - $context = new Context($root->url()); + $config = new Config($root); + $context = new Context($root); $fileSystem = (new FileSystem($context))->setModuleName($this->moduleName); fwrite($this->inputStream, PHP_EOL); @@ -88,8 +92,8 @@ public function testWillCallAccessors(): void $this->assertContainsOnlyInstancesOf(Module::class, [$module->getModule()]); $this->assertTrue($module->hasModule()); - $module->setConfig(new Config($root->url())); - $module->setContext(new Context($root->url())); + $module->setConfig(new Config($root)); + $module->setContext(new Context($root)); $module->setFileSystem((new FileSystem($context))->setModuleName($this->moduleName)); $this->assertContainsOnlyInstancesOf(Config::class, [$module->getConfig()]); $this->assertContainsOnlyInstancesOf(Context::class, [$module->getContext()]); @@ -98,7 +102,7 @@ public function testWillCallAccessors(): void public function testCallToInvokeWillEarlyReturnOnEmptyInput(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -108,8 +112,8 @@ public function testCallToInvokeWillEarlyReturnOnEmptyInput(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); fwrite($this->inputStream, PHP_EOL); @@ -127,7 +131,7 @@ public function testCallToInvokeWillEarlyReturnOnEmptyInput(): void public function testCallToInvokeWillFailWhenNameIsInvalid(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -137,8 +141,8 @@ public function testCallToInvokeWillFailWhenNameIsInvalid(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); fwrite($this->inputStream, '.' . PHP_EOL); @@ -157,7 +161,7 @@ public function testCallToInvokeWillFailWhenNameIsInvalid(): void public function testCallToInvokeWillFailWhenModuleAlreadyExists(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -170,8 +174,8 @@ public function testCallToInvokeWillFailWhenModuleAlreadyExists(): void ], ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); fwrite($this->inputStream, 'App' . PHP_EOL); @@ -184,7 +188,7 @@ public function testCallToInvokeWillFailWhenModuleAlreadyExists(): void rewind($this->errorStream); $this->assertSame( ColorEnum::colorize( - 'Module "App" already exists at vfs://root/src/App', + sprintf('Module "App" already exists at %s/src/App', $root), ColorEnum::ForegroundBrightRed ) . PHP_EOL, stream_get_contents($this->errorStream) @@ -193,7 +197,7 @@ public function testCallToInvokeWillFailWhenModuleAlreadyExists(): void public function testCallToInvokeWillFailWhenUnableToCreateModuleDirectory(): void { - $root = vfsStream::setup('root', 0000, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -201,10 +205,12 @@ public function testCallToInvokeWillFailWhenUnableToCreateModuleDirectory(): voi } } }', + // A regular file at "src" makes the directory creation fail for every user. + 'src' => 'not a directory', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); fwrite($this->inputStream, 'App' . PHP_EOL); @@ -212,12 +218,19 @@ public function testCallToInvokeWillFailWhenUnableToCreateModuleDirectory(): voi $module = new Module($this->fileSystem, $this->context, $this->config); $module->setModule($module); - $module(); + + // mkdir() reports the expected failure as a warning. Keep it out of the test output. + set_error_handler(static fn (): bool => true, E_WARNING); + try { + $module(); + } finally { + restore_error_handler(); + } rewind($this->errorStream); $this->assertSame( ColorEnum::colorize( - 'Could not create directory "vfs://root/src/App"', + sprintf('Could not create directory "%s/src/App"', $root), ColorEnum::ForegroundBrightRed ) . PHP_EOL, stream_get_contents($this->errorStream) @@ -226,7 +239,7 @@ public function testCallToInvokeWillFailWhenUnableToCreateModuleDirectory(): voi public function testWillAddMessage(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -236,8 +249,8 @@ public function testWillAddMessage(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $module = new Module($this->fileSystem, $this->context, $this->config); @@ -249,7 +262,7 @@ public function testWillAddMessage(): void public function testInitExistingWillNotInitWhenInvalidModuleName(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -262,8 +275,8 @@ public function testInitExistingWillNotInitWhenInvalidModuleName(): void ], ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); fwrite($this->inputStream, '.' . PHP_EOL); @@ -282,7 +295,7 @@ public function testInitExistingWillNotInitWhenInvalidModuleName(): void public function testInitExistingWillNotInitFromInexistentModule(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -295,8 +308,8 @@ public function testInitExistingWillNotInitFromInexistentModule(): void ], ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); fwrite($this->inputStream, 'Test' . PHP_EOL); @@ -315,7 +328,7 @@ public function testInitExistingWillNotInitFromInexistentModule(): void public function testInitExistingWillInitExistingModule(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -328,8 +341,8 @@ public function testInitExistingWillInitExistingModule(): void ], ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->assertSame('BookStore', $this->fileSystem->getModuleName()); @@ -351,7 +364,7 @@ public function testInitExistingWillInitExistingModule(): void public function testWillIdentifyAsModule(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -361,8 +374,8 @@ public function testWillIdentifyAsModule(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $module = new Module($this->fileSystem, $this->context, $this->config); @@ -371,7 +384,7 @@ public function testWillIdentifyAsModule(): void public function testWillNotRenderMessagesWhenNoMessageAvailable(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -381,8 +394,8 @@ public function testWillNotRenderMessagesWhenNoMessageAvailable(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $module = new Module($this->fileSystem, $this->context, $this->config); @@ -394,7 +407,7 @@ public function testWillNotRenderMessagesWhenNoMessageAvailable(): void public function testWillCreateFilesWhenProjectTypeIsApiAndUsesCore(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -405,8 +418,8 @@ public function testWillCreateFilesWhenProjectTypeIsApiAndUsesCore(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $entity = $this->fileSystem->entity($this->resourceName); @@ -554,14 +567,14 @@ public function testWillCreateFilesWhenProjectTypeIsApiAndUsesCore(): void rewind($this->outputStream); $this->assertEmpty(stream_get_contents($this->errorStream)); $this->assertSame( - $this->dataProviderWhenProjectTypeIsApiAndUsesCore(), + $this->dataProviderWhenProjectTypeIsApiAndUsesCore($root), stream_get_contents($this->outputStream) ); } public function testWillCreateFilesWhenProjectTypeIsApiAndDoesNotUseCore(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -571,8 +584,8 @@ public function testWillCreateFilesWhenProjectTypeIsApiAndDoesNotUseCore(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $entity = $this->fileSystem->entity($this->resourceName); @@ -720,14 +733,14 @@ public function testWillCreateFilesWhenProjectTypeIsApiAndDoesNotUseCore(): void rewind($this->outputStream); $this->assertEmpty(stream_get_contents($this->errorStream)); $this->assertSame( - $this->dataProviderWhenProjectTypeIsApiAndDoesNotUseCore(), + $this->dataProviderWhenProjectTypeIsApiAndDoesNotUseCore($root), stream_get_contents($this->outputStream) ); } public function testWillCreateFilesWhenProjectTypeIsNotApiAndUsesCore(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -738,8 +751,8 @@ public function testWillCreateFilesWhenProjectTypeIsNotApiAndUsesCore(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $entity = $this->fileSystem->entity($this->resourceName); @@ -886,14 +899,14 @@ public function testWillCreateFilesWhenProjectTypeIsNotApiAndUsesCore(): void rewind($this->outputStream); $this->assertEmpty(stream_get_contents($this->errorStream)); $this->assertSame( - $this->dataProviderWhenProjectTypeIsNotApiAndUsesCore(), + $this->dataProviderWhenProjectTypeIsNotApiAndUsesCore($root), stream_get_contents($this->outputStream) ); } public function testWillCreateFilesWhenProjectTypeIsNootApiAndDoesNotUseCore(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -903,8 +916,8 @@ public function testWillCreateFilesWhenProjectTypeIsNootApiAndDoesNotUseCore(): }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $entity = $this->fileSystem->entity($this->resourceName); @@ -1051,50 +1064,50 @@ public function testWillCreateFilesWhenProjectTypeIsNootApiAndDoesNotUseCore(): rewind($this->outputStream); $this->assertEmpty(stream_get_contents($this->errorStream)); $this->assertSame( - $this->dataProviderWhenProjectTypeIsNotApiAndDoesNotUseCore(), + $this->dataProviderWhenProjectTypeIsNotApiAndDoesNotUseCore($root), stream_get_contents($this->outputStream) ); } - private function dataProviderWhenProjectTypeIsApiAndUsesCore(): string + private function dataProviderWhenProjectTypeIsApiAndUsesCore(string $root): string { // phpcs:disable Generic.Files.LineLength.TooLong return <<pipe(Api\BookStore\Middleware\BookStoreMiddleware::class);\033[0m - add to \033[97mconfig/autoload/authorization.global.php\033[0m - the routes registered in \033[97mvfs://root/src/BookStore/src/RoutesDelegator.php\033[0m + the routes registered in \033[97m{$root}/src/BookStore/src/RoutesDelegator.php\033[0m - add to \033[97mcomposer.json\033[0m under \033[97mautoload\033[0m.\033[97mpsr-4\033[0m: \033[93m "Api\\\\BookStore\\\\": "src/BookStore/src/"\033[0m - add to \033[97mcomposer.json\033[0m under \033[97mautoload\033[0m.\033[97mpsr-4\033[0m: @@ -1122,44 +1135,44 @@ private function dataProviderWhenProjectTypeIsApiAndUsesCore(): string // phpcs:enable Generic.Files.LineLength.TooLong } - private function dataProviderWhenProjectTypeIsApiAndDoesNotUseCore(): string + private function dataProviderWhenProjectTypeIsApiAndDoesNotUseCore(string $root): string { // phpcs:disable Generic.Files.LineLength.TooLong return <<pipe(Api\BookStore\Middleware\BookStoreMiddleware::class);\033[0m - add to \033[97mconfig/autoload/authorization.global.php\033[0m - the routes registered in \033[97mvfs://root/src/BookStore/src/RoutesDelegator.php\033[0m + the routes registered in \033[97m{$root}/src/BookStore/src/RoutesDelegator.php\033[0m - add to \033[97mcomposer.json\033[0m under \033[97mautoload\033[0m.\033[97mpsr-4\033[0m: \033[93m "Api\\\\BookStore\\\\": "src/BookStore/src/"\033[0m - dump Composer autoloader by executing this command: @@ -1183,53 +1196,53 @@ private function dataProviderWhenProjectTypeIsApiAndDoesNotUseCore(): string // phpcs:enable Generic.Files.LineLength.TooLong } - private function dataProviderWhenProjectTypeIsNotApiAndUsesCore(): string + private function dataProviderWhenProjectTypeIsNotApiAndUsesCore(string $root): string { // phpcs:disable Generic.Files.LineLength.TooLong return <<pipe(Admin\BookStore\Middleware\BookStoreMiddleware::class);\033[0m - add to \033[97mconfig/autoload/authorization-guards.global.php\033[0m - the routes registered in \033[97mvfs://root/src/BookStore/src/RoutesDelegator.php\033[0m + the routes registered in \033[97m{$root}/src/BookStore/src/RoutesDelegator.php\033[0m - add to \033[97mcomposer.json\033[0m under \033[97mautoload\033[0m.\033[97mpsr-4\033[0m: \033[93m "Admin\\\\BookStore\\\\": "src/BookStore/src/"\033[0m - add to \033[97mcomposer.json\033[0m under \033[97mautoload\033[0m.\033[97mpsr-4\033[0m: @@ -1257,52 +1270,52 @@ private function dataProviderWhenProjectTypeIsNotApiAndUsesCore(): string // phpcs:enable Generic.Files.LineLength.TooLong } - private function dataProviderWhenProjectTypeIsNotApiAndDoesNotUseCore(): string + private function dataProviderWhenProjectTypeIsNotApiAndDoesNotUseCore(string $root): string { // phpcs:disable Generic.Files.LineLength.TooLong return <<pipe(Admin\BookStore\Middleware\BookStoreMiddleware::class);\033[0m - add to \033[97mconfig/autoload/authorization-guards.global.php\033[0m - the routes registered in \033[97mvfs://root/src/BookStore/src/RoutesDelegator.php\033[0m + the routes registered in \033[97m{$root}/src/BookStore/src/RoutesDelegator.php\033[0m - add to \033[97mcomposer.json\033[0m under \033[97mautoload\033[0m.\033[97mpsr-4\033[0m: \033[93m "Admin\\\\BookStore\\\\": "src/BookStore/src/"\033[0m - dump Composer autoloader by executing this command: diff --git a/test/Type/OpenApiTest.php b/test/Type/OpenApiTest.php index befe6d3..07cbb02 100644 --- a/test/Type/OpenApiTest.php +++ b/test/Type/OpenApiTest.php @@ -11,7 +11,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Module; use Dot\Maker\Type\OpenApi; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -46,7 +46,7 @@ protected function tearDown(): void public function testCallToCreateWillEarlyReturnWhenProjectTypeIsApi(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -56,8 +56,8 @@ public function testCallToCreateWillEarlyReturnWhenProjectTypeIsApi(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -69,7 +69,7 @@ public function testCallToCreateWillEarlyReturnWhenProjectTypeIsApi(): void public function testCallToCreateWillFailWhenFileAlreadyExists(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -86,8 +86,8 @@ public function testCallToCreateWillFailWhenFileAlreadyExists(): void ], ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -103,7 +103,7 @@ public function testCallToCreateWillFailWhenFileAlreadyExists(): void public function testWillCreateFile(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -113,8 +113,8 @@ public function testWillCreateFile(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -136,7 +136,7 @@ public function testWillCreateFile(): void $this->assertSame($this->dataProviderRenderedOpenApi(), $file->read()); $this->assertSame( ColorEnum::colorize( - 'Created OpenAPI: vfs://root/src/ModuleName/src/OpenAPI.php', + sprintf('Created OpenAPI: %s/src/ModuleName/src/OpenAPI.php', $root), ColorEnum::ForegroundBrightGreen ) . PHP_EOL, stream_get_contents($this->outputStream) diff --git a/test/Type/RepositoryTest.php b/test/Type/RepositoryTest.php index c841c49..78ae4e8 100644 --- a/test/Type/RepositoryTest.php +++ b/test/Type/RepositoryTest.php @@ -11,7 +11,8 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Module; use Dot\Maker\Type\Repository; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function fclose; @@ -41,7 +42,7 @@ class RepositoryTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -52,8 +53,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -145,9 +146,7 @@ public function testCallToInvokeWillOutputErrorAndWillNotCreateFileWhenNameIsInv $this->assertFileDoesNotExist($file->getPath()); } - /** - * @dataProvider dataProvider - */ + #[DataProvider('dataProvider')] public function testCallToInvokeWillSucceedWhenNameIsValid(string $expected): void { $file = $this->fileSystem->repository($this->resourceName); @@ -166,9 +165,7 @@ public function testCallToInvokeWillSucceedWhenNameIsValid(string $expected): vo $this->assertSame($expected, $file->read()); } - /** - * @dataProvider dataProvider - */ + #[DataProvider('dataProvider')] public function testCallToCreateWillSucceedWhenNameIsValid(string $expected): void { $file = $this->fileSystem->repository($this->resourceName); diff --git a/test/Type/RoutesDelegatorTest.php b/test/Type/RoutesDelegatorTest.php index 0085f5d..55e1255 100644 --- a/test/Type/RoutesDelegatorTest.php +++ b/test/Type/RoutesDelegatorTest.php @@ -10,7 +10,8 @@ use Dot\Maker\FileSystem; use Dot\Maker\IO\Output; use Dot\Maker\Type\RoutesDelegator; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function fclose; @@ -26,15 +27,13 @@ class RoutesDelegatorTest extends TestCase private string $moduleName = 'ModuleName'; private string $resourceName = 'BookStore'; - /** - * @dataProvider dataProvider - */ + #[DataProvider('dataProvider')] public function testCallToCreateWhenProjectTypeIsNotApiWillCreateFile(string $expected): void { $stream = fopen('php://memory', 'w+'); Output::setOutputStream($stream); - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -45,8 +44,8 @@ public function testCallToCreateWhenProjectTypeIsNotApiWillCreateFile(string $ex }', ]); - $config = new Config($root->url()); - $context = new Context($root->url()); + $config = new Config($root); + $context = new Context($root); $fileSystem = (new FileSystem($context))->setModuleName($this->moduleName); $fileSystem->getCreateResourceHandler($this->resourceName)->create('...'); @@ -73,15 +72,13 @@ public function testCallToCreateWhenProjectTypeIsNotApiWillCreateFile(string $ex fclose($stream); } - /** - * @dataProvider dataProviderApi - */ + #[DataProvider('dataProviderApi')] public function testCallToCreateWhenProjectTypeIsApiWillCreateFile(string $expected): void { $stream = fopen('php://memory', 'w+'); Output::setOutputStream($stream); - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -92,8 +89,8 @@ public function testCallToCreateWhenProjectTypeIsApiWillCreateFile(string $expec }', ]); - $config = new Config($root->url()); - $context = new Context($root->url()); + $config = new Config($root); + $context = new Context($root); $fileSystem = (new FileSystem($context))->setModuleName($this->moduleName); $fileSystem->entity($this->resourceName)->create('...'); diff --git a/test/Type/ServiceInterfaceTest.php b/test/Type/ServiceInterfaceTest.php index f2b474f..8d99579 100644 --- a/test/Type/ServiceInterfaceTest.php +++ b/test/Type/ServiceInterfaceTest.php @@ -13,7 +13,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Module; use Dot\Maker\Type\ServiceInterface; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -45,7 +45,7 @@ class ServiceInterfaceTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -56,8 +56,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -211,7 +211,7 @@ public function testCallToCreateWillSucceedWhenNameIsValidAndProjectTypeIsNotApi public function testCallToInvokeWillSucceedWhenNameIsValidAndProjectTypeIsApi(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -222,7 +222,7 @@ public function testCallToInvokeWillSucceedWhenNameIsValidAndProjectTypeIsApi(): }', ]); - $this->context = new Context($root->url()); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -255,7 +255,7 @@ public function testCallToInvokeWillSucceedWhenNameIsValidAndProjectTypeIsApi(): public function testCallToCreateWillSucceedWhenNameIsValidAndProjectTypeIsApi(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -266,7 +266,7 @@ public function testCallToCreateWillSucceedWhenNameIsValidAndProjectTypeIsApi(): }', ]); - $this->context = new Context($root->url()); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); diff --git a/test/Type/ServiceTest.php b/test/Type/ServiceTest.php index 36cb93b..4155407 100644 --- a/test/Type/ServiceTest.php +++ b/test/Type/ServiceTest.php @@ -13,7 +13,7 @@ use Dot\Maker\IO\Output; use Dot\Maker\Type\Module; use Dot\Maker\Type\Service; -use org\bovigo\vfs\vfsStream; +use DotTest\Maker\Fixture\TemporaryDirectory; use PHPUnit\Framework\TestCase; use function fclose; @@ -45,7 +45,7 @@ class ServiceTest extends TestCase protected function setUp(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -56,8 +56,8 @@ protected function setUp(): void }', ]); - $this->config = new Config($root->url()); - $this->context = new Context($root->url()); + $this->config = new Config($root); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -208,7 +208,7 @@ public function testCallToCreateWillSucceedWhenNameIsValidAndProjectTypeIsNotApi public function testCallToInvokeWillSucceedWhenNameIsValidAndProjectTypeIsApi(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -219,7 +219,7 @@ public function testCallToInvokeWillSucceedWhenNameIsValidAndProjectTypeIsApi(): }', ]); - $this->context = new Context($root->url()); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config); @@ -252,7 +252,7 @@ public function testCallToInvokeWillSucceedWhenNameIsValidAndProjectTypeIsApi(): public function testCallToCreateWillSucceedWhenNameIsValidAndProjectTypeIsApi(): void { - $root = vfsStream::setup('root', 0644, [ + $root = TemporaryDirectory::create([ 'composer.json' => '{ "autoload": { "psr-4": { @@ -263,7 +263,7 @@ public function testCallToCreateWillSucceedWhenNameIsValidAndProjectTypeIsApi(): }', ]); - $this->context = new Context($root->url()); + $this->context = new Context($root); $this->fileSystem = (new FileSystem($this->context))->setModuleName($this->moduleName); $this->import = new Import($this->context); $this->module = new Module($this->fileSystem, $this->context, $this->config);