From 6480e8543f265309f1b2781fe84997311ed9244c Mon Sep 17 00:00:00 2001 From: Utsav Somaiya Date: Tue, 16 Jan 2024 14:13:04 +0530 Subject: [PATCH 1/3] test: command stub file tests --- .../Generators/StubPublishedCommandTest.php | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tests/Integration/Generators/StubPublishedCommandTest.php diff --git a/tests/Integration/Generators/StubPublishedCommandTest.php b/tests/Integration/Generators/StubPublishedCommandTest.php new file mode 100644 index 000000000000..8992d1a4f109 --- /dev/null +++ b/tests/Integration/Generators/StubPublishedCommandTest.php @@ -0,0 +1,96 @@ +getAllStubs(); + + $this->artisan('stub:publish') + ->assertExitCode(0) + ->expectsOutputToContain('Stubs published successfully.'); + + Event::assertDispatched(PublishingStubs::class); + + $this->assertDirectoryExists(base_path('stubs')); + + $this->assertFileExists(base_path('stubs'.DIRECTORY_SEPARATOR.$stubs[array_rand($stubs)])); + } + + public function testItCanOverWriteAnyExistingFiles() + { + if (! is_dir($stubsPath = base_path('stubs'))) { + File::makeDirectory($stubsPath); + } + + $stubs = $this->getAllStubs(); + + $existingStubFile = $stubsPath.DIRECTORY_SEPARATOR.ltrim($stubs[array_rand($stubs)], DIRECTORY_SEPARATOR); + + file_put_contents($existingStubFile, $data = fake()->sentence()); + + $this->artisan('stub:publish --force') + ->assertExitCode(0) + ->expectsOutputToContain('Stubs published successfully.'); + + $this->assertNotEquals(Process::run('cat ' . $existingStubFile)->output(), $data); + } + + private function getAllStubs() + { + return [ + 'cast.inbound.stub', + 'cast.stub', + 'console.stub', + 'event.stub', + 'job.queued.stub', + 'job.stub', + 'mail.stub', + 'markdown-mail.stub', + 'markdown-notification.stub', + 'model.pivot.stub', + 'model.stub', + 'notification.stub', + 'observer.plain.stub', + 'observer.stub', + 'policy.plain.stub', + 'policy.stub', + 'provider.stub', + 'request.stub', + 'resource.stub', + 'resource-collection.stub', + 'rule.stub', + 'scope.stub', + 'test.stub', + 'test.unit.stub', + 'view-component.stub', + 'factory.stub', + 'seeder.stub', + 'migration.create.stub', + 'migration.stub', + 'migration.update.stub', + 'controller.api.stub', + 'controller.invokable.stub', + 'controller.model.api.stub', + 'controller.model.stub', + 'controller.nested.api.stub', + 'controller.nested.singleton.api.stub', + 'controller.nested.singleton.stub', + 'controller.nested.stub', + 'controller.plain.stub', + 'controller.singleton.api.stub', + 'controller.singleton.stub', + 'controller.stub', + 'middleware.stub', + ]; + } +} From b69fe0adc42d02b9e387baad1434f5f1e14fc6f1 Mon Sep 17 00:00:00 2001 From: Utsav Somaiya Date: Tue, 16 Jan 2024 14:15:47 +0530 Subject: [PATCH 2/3] fix: ci --- tests/Integration/Generators/StubPublishedCommandTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Generators/StubPublishedCommandTest.php b/tests/Integration/Generators/StubPublishedCommandTest.php index 8992d1a4f109..cc0ffad22df4 100644 --- a/tests/Integration/Generators/StubPublishedCommandTest.php +++ b/tests/Integration/Generators/StubPublishedCommandTest.php @@ -2,10 +2,10 @@ namespace Illuminate\Tests\Integration\Generators; -use Illuminate\Support\Facades\Event; -use Illuminate\Support\Facades\Process; use Illuminate\Foundation\Events\PublishingStubs; +use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Process; class StubPublishedCommandTest extends TestCase { @@ -42,7 +42,7 @@ public function testItCanOverWriteAnyExistingFiles() ->assertExitCode(0) ->expectsOutputToContain('Stubs published successfully.'); - $this->assertNotEquals(Process::run('cat ' . $existingStubFile)->output(), $data); + $this->assertNotEquals(Process::run('cat '.$existingStubFile)->output(), $data); } private function getAllStubs() From 79c9d3bd17fee4bdda5f5790edbdd6263a3ad176 Mon Sep 17 00:00:00 2001 From: Utsav Somaiya Date: Tue, 16 Jan 2024 14:23:21 +0530 Subject: [PATCH 3/3] rename: file name --- ...{StubPublishedCommandTest.php => StubPublishCommandTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/Integration/Generators/{StubPublishedCommandTest.php => StubPublishCommandTest.php} (98%) diff --git a/tests/Integration/Generators/StubPublishedCommandTest.php b/tests/Integration/Generators/StubPublishCommandTest.php similarity index 98% rename from tests/Integration/Generators/StubPublishedCommandTest.php rename to tests/Integration/Generators/StubPublishCommandTest.php index cc0ffad22df4..e3fb6c15d042 100644 --- a/tests/Integration/Generators/StubPublishedCommandTest.php +++ b/tests/Integration/Generators/StubPublishCommandTest.php @@ -7,7 +7,7 @@ use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Process; -class StubPublishedCommandTest extends TestCase +class StubPublishCommandTest extends TestCase { public function testItCanPublishedStubFiles() {