|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Orchid\Tests\Console; |
| 6 | + |
| 7 | +use Orchid\Tests\TestConsoleCase; |
| 8 | +use Illuminate\Filesystem\Filesystem; |
| 9 | + |
| 10 | +class StubPublishCommandTest extends TestConsoleCase |
| 11 | +{ |
| 12 | + public function setUp(): void |
| 13 | + { |
| 14 | + parent::setUp(); |
| 15 | + $this->stubsPath = base_path('stubs/orchid/platform'); |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * Clears the directory after each test. |
| 20 | + */ |
| 21 | + public function tearDown(): void |
| 22 | + { |
| 23 | + parent::tearDown(); |
| 24 | + |
| 25 | + $filesystem = new Filesystem(); |
| 26 | + if ($filesystem->exists($this->stubsPath)) { |
| 27 | + $filesystem->cleanDirectory($this->stubsPath); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Test using the --force option to overwrite an existing file. |
| 33 | + */ |
| 34 | + public function testForcePublish(): void |
| 35 | + { |
| 36 | + $file = 'screen.stub'; |
| 37 | + |
| 38 | + // Simulate an existing file. |
| 39 | + file_put_contents($this->stubsPath.'/'.$file, 'Existing content'); |
| 40 | + |
| 41 | + $this->artisan('orchid:stubs', ['--force' => true]) |
| 42 | + ->expectsOutputToContain('Stubs published successfully.') |
| 43 | + ->assertOk(); |
| 44 | + |
| 45 | + // Check that the file was overwritten. |
| 46 | + $this->assertNotEquals('Existing content', file_get_contents($this->stubsPath.'/'.$file)); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Test using the --existing option to overwrite only existing files. |
| 51 | + */ |
| 52 | + public function testExistingPublish(): void |
| 53 | + { |
| 54 | + $file = 'screen.stub'; |
| 55 | + |
| 56 | + // Simulate an existing file. |
| 57 | + file_put_contents($this->stubsPath.'/'.$file, 'Existing content'); |
| 58 | + |
| 59 | + $this->artisan('orchid:stubs', ['--existing' => true]) |
| 60 | + ->expectsOutputToContain('Stubs published successfully.') |
| 61 | + ->assertOk(); |
| 62 | + |
| 63 | + // Check that the file was overwritten. |
| 64 | + $this->assertNotEquals('Existing content', file_get_contents($this->stubsPath.'/'.$file)); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Test without any options to check normal file publishing behavior. |
| 69 | + */ |
| 70 | + public function testPublishWithoutOptions(): void |
| 71 | + { |
| 72 | + $this->artisan('orchid:stubs') |
| 73 | + ->expectsOutputToContain('Stubs published successfully.') |
| 74 | + ->assertOk(); |
| 75 | + } |
| 76 | +} |
0 commit comments