diff --git a/.gitignore b/.gitignore index 4913b8e..35f74f1 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ composer.lock .phpunit.result.cache tests/Site/build_testing/ tests/Site/torchlight.php +.phpunit.cache/ diff --git a/composer.json b/composer.json index d2d3211..8a0d97f 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,11 @@ "laravel" ], "require": { - "tightenco/jigsaw": "^1.3.27", - "torchlight/torchlight-laravel": "^0.5.10" + "tightenco/jigsaw": "^1.8", + "torchlight/torchlight-laravel": "^0.6" }, "require-dev": { - "phpunit/phpunit": "^8.4" + "phpunit/phpunit": "^11.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d434150..24da3b8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,9 @@ - + - tests + tests + vendor - - - src/ - - - - - \ No newline at end of file + diff --git a/tests/BaseTest.php b/tests/BaseTest.php index cb77210..ed2d4eb 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -1,4 +1,5 @@ */ @@ -7,13 +8,16 @@ use Illuminate\Cache\NullStore; use Illuminate\Cache\Repository; -use Illuminate\Container\Container; use Illuminate\Http\Client\Factory; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; +use Illuminate\View\Component; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Symfony\Component\Console\Application; +use TightenCo\Jigsaw\Bootstrap\HandleExceptions; use TightenCo\Jigsaw\Console\BuildCommand; +use TightenCo\Jigsaw\Container; +use TightenCo\Jigsaw\File\Filesystem; use TightenCo\Jigsaw\Jigsaw; use Torchlight\Block; use Torchlight\Jigsaw\Exceptions\UnrenderedBlockException; @@ -26,48 +30,79 @@ class BaseTest extends TestCase protected $container; - protected function prepareForBuilding() + protected Filesystem $filesystem; + + protected string $sitePath; + + public function __construct($name = null, array $data = [], $dataName = '') + { + parent::__construct($name, $data, $dataName); + + $this->sitePath = __DIR__ . '/Site'; + + $this->filesystem = new Filesystem; + } + + protected function tearDown(): void { - $sitePath = __DIR__ . '/Site'; + if ($this->container) { + $this->container->flush(); + } - // Clear out the old build directory. - if (is_dir("$sitePath/build_testing")) { - exec("rm -rf $sitePath/build_testing"); + if (method_exists(Component::class, 'flushCache')) { + Component::flushCache(); + Component::forgetComponentsResolver(); + Component::forgetFactory(); } - // Clear the old config. - if (file_exists("$sitePath/torchlight.php")) { - exec("rm $sitePath/torchlight.php"); + if ($this->status()->isSuccess()) { + $this->filesystem->deleteDirectory(app()->cachePath()); + + $this->filesystem->delete("$this->sitePath/torchlight.php"); } - /** - * These next lines basically mimic the /vendor/bin/jigsaw.php file. - */ - require realpath(__DIR__ . '/../vendor/tightenco/jigsaw/jigsaw-core.php'); + HandleExceptions::flushState(); - $this->app = new Application('Jigsaw', '1.3.37'); + parent::tearDown(); + } + + protected function prepareForBuilding() + { + // Keeping it fully qualified here to make it easier + // to compare with the jigsaw initialization flow + $this->app = new \Symfony\Component\Console\Application('Jigsaw', '1.8.2'); /** @var Container $container */ - $this->container = $container; + $this->container = new \TightenCo\Jigsaw\Container; + + $this->container->singleton( + \Illuminate\Contracts\Debug\ExceptionHandler::class, + \TightenCo\Jigsaw\Exceptions\Handler::class, + ); + + $this->container->bootstrapWith([ + \TightenCo\Jigsaw\Bootstrap\HandleExceptions::class, + ]); - $this->container->instance('cwd', $sitePath); $this->container->buildPath = [ - 'source' => $sitePath, - 'views' => $sitePath, - 'destination' => "$sitePath/build_testing", + 'source' => $this->sitePath, + 'views' => $this->sitePath, + 'destination' => "$this->sitePath/build_testing", ]; + $this->container['env'] = 'testing'; + // There are other Jigsaw commands we could register, // but we dont' need them so we don't add them. $this->app->add(new BuildCommand($this->container)); - Jigsaw::addUserCommands($this->app, $this->container); - // This is from the bottom of jigsaw-core.php. We have to do it + // This is from the bottom of jigsaw. We have to do it // ourselves since we're in a different working directory than // that file expects us to be. + $container = $this->container; $events = $this->container->events; - include "$sitePath/bootstrap.php"; + include "$this->sitePath/bootstrap.php"; Http::swap(new Factory); } @@ -76,8 +111,14 @@ protected function build($source = 'source-1') { // Turn off the Jigsaw progress bars. $this->container->consoleOutput->setup($verbosity = -1); + + $this->container->buildPath = [ + 'source' => __DIR__ . "/Site/$source", + 'views' => __DIR__ . '/Site', + 'destination' => __DIR__ . '/Site/build_testing', + ]; + $jigsaw = $this->container->make(Jigsaw::class); - $jigsaw->setSourcePath(__DIR__ . "/Site/$source"); $jigsaw->build('testing'); } @@ -89,7 +130,7 @@ protected function assertSnapshotMatches($file) $this->assertEquals($expected, $actual, "Checking snapshot $file"); } - /** @test */ + #[Test] public function most_of_the_tests_are_here() { TorchlightExtension::macro('afterStandaloneConfiguration', function () { @@ -126,7 +167,7 @@ public function most_of_the_tests_are_here() $this->assertSnapshotMatches('code-indents-work'); } - /** @test */ + #[Test] public function no_blocks_doesnt_create_an_error() { TorchlightExtension::macro('afterStandaloneConfiguration', function () { @@ -145,7 +186,7 @@ public function no_blocks_doesnt_create_an_error() $this->assertTrue(true); } - /** @test */ + #[Test] public function non_existent_block_throws() { TorchlightExtension::macro('afterStandaloneConfiguration', function () { @@ -167,7 +208,7 @@ public function non_existent_block_throws() $this->assertTrue(false); } - /** @test */ + #[Test] public function expected_non_existent_block_is_fine() { TorchlightExtension::macro('afterStandaloneConfiguration', function () { @@ -187,7 +228,7 @@ public function expected_non_existent_block_is_fine() $this->assertTrue(true); } - /** @test */ + #[Test] public function can_manually_add_blocks() { TorchlightExtension::macro('afterStandaloneConfiguration', function () { @@ -242,7 +283,7 @@ public function can_manually_add_blocks() $this->assertSnapshotMatches('manually-added'); } - /** @test */ + #[Test] public function dark_mode_works() { TorchlightExtension::macro('afterStandaloneConfiguration', function () { @@ -317,7 +358,7 @@ public function dark_mode_works() $this->assertSnapshotMatches('dark-mode'); } - /** @test */ + #[Test] public function test_publish_command() { $this->assertFalse(file_exists(__DIR__ . '/Site/torchlight.php'));