|
567 | 567 | ->expectsOutput('"refactor": "vendor/bin/rector"'); |
568 | 568 |
|
569 | 569 | }); |
| 570 | + |
| 571 | +it('skips existing config file when user declines to overwrite', function (): void { |
| 572 | + // Arrange |
| 573 | + File::shouldReceive('exists') |
| 574 | + ->with(base_path('composer.json')) |
| 575 | + ->andReturnTrue(); |
| 576 | + File::shouldReceive('get') |
| 577 | + ->with(base_path('composer.json')) |
| 578 | + ->andReturn(json_encode(['require' => [], 'require-dev' => []])); |
| 579 | + File::shouldReceive('exists') |
| 580 | + ->with(base_path('pint.json')) |
| 581 | + ->andReturnTrue(); // pint.json already exists |
| 582 | + File::shouldReceive('exists') |
| 583 | + ->with(base_path('phpstan.neon.dist')) |
| 584 | + ->andReturnFalse(); |
| 585 | + File::shouldReceive('exists') |
| 586 | + ->with(base_path('rector.php')) |
| 587 | + ->andReturnFalse(); |
| 588 | + File::shouldReceive('copy') |
| 589 | + ->with(Mockery::type('string'), base_path('phpstan.neon.dist')) |
| 590 | + ->andReturnTrue(); |
| 591 | + File::shouldReceive('copy') |
| 592 | + ->with(Mockery::type('string'), base_path('rector.php')) |
| 593 | + ->andReturnTrue(); |
| 594 | + // pint.json should NOT be copied |
| 595 | + |
| 596 | + Process::fake(); |
| 597 | + |
| 598 | + // Act & Assert |
| 599 | + $this->artisan('laravel-init:install') |
| 600 | + ->expectsConfirmation('File pint.json already exists. Overwrite?', 'no') |
| 601 | + ->expectsOutputToContain('Skipping pint.json') |
| 602 | + ->assertExitCode(0); |
| 603 | +}); |
| 604 | + |
| 605 | +it('overwrites existing config file when user confirms', function (): void { |
| 606 | + // Arrange |
| 607 | + File::shouldReceive('exists') |
| 608 | + ->with(base_path('composer.json')) |
| 609 | + ->andReturnTrue(); |
| 610 | + File::shouldReceive('get') |
| 611 | + ->with(base_path('composer.json')) |
| 612 | + ->andReturn(json_encode(['require' => [], 'require-dev' => []])); |
| 613 | + File::shouldReceive('exists') |
| 614 | + ->with(base_path('pint.json')) |
| 615 | + ->andReturnTrue(); // pint.json already exists |
| 616 | + File::shouldReceive('exists') |
| 617 | + ->with(base_path('phpstan.neon.dist')) |
| 618 | + ->andReturnFalse(); |
| 619 | + File::shouldReceive('exists') |
| 620 | + ->with(base_path('rector.php')) |
| 621 | + ->andReturnFalse(); |
| 622 | + File::shouldReceive('copy') |
| 623 | + ->andReturnTrue(); // All copies succeed |
| 624 | + |
| 625 | + Process::fake(); |
| 626 | + |
| 627 | + // Act & Assert |
| 628 | + $this->artisan('laravel-init:install') |
| 629 | + ->expectsConfirmation('File pint.json already exists. Overwrite?', 'yes') |
| 630 | + ->expectsOutputToContain('Overwriting pint.json') |
| 631 | + ->assertExitCode(0); |
| 632 | +}); |
| 633 | + |
| 634 | +it('overwrites existing config file with --force without asking', function (): void { |
| 635 | + // Arrange |
| 636 | + File::shouldReceive('exists') |
| 637 | + ->with(base_path('composer.json')) |
| 638 | + ->andReturnTrue(); |
| 639 | + File::shouldReceive('get') |
| 640 | + ->with(base_path('composer.json')) |
| 641 | + ->andReturn(json_encode(['require' => [], 'require-dev' => []])); |
| 642 | + File::shouldReceive('exists') |
| 643 | + ->with(base_path('pint.json')) |
| 644 | + ->andReturnTrue(); // pint.json already exists |
| 645 | + File::shouldReceive('exists') |
| 646 | + ->with(base_path('phpstan.neon.dist')) |
| 647 | + ->andReturnFalse(); |
| 648 | + File::shouldReceive('exists') |
| 649 | + ->with(base_path('rector.php')) |
| 650 | + ->andReturnFalse(); |
| 651 | + File::shouldReceive('copy') |
| 652 | + ->andReturnTrue(); // Should copy with --force |
| 653 | + |
| 654 | + Process::fake(); |
| 655 | + |
| 656 | + // Act & Assert |
| 657 | + $this->artisan('laravel-init:install --force') |
| 658 | + ->expectsOutputToContain('Overwriting pint.json') |
| 659 | + ->assertExitCode(0); |
| 660 | +}); |
| 661 | + |
| 662 | +it('copies new config file without prompting when file does not exist', function (): void { |
| 663 | + // Arrange |
| 664 | + File::shouldReceive('exists') |
| 665 | + ->andReturnFalse(); // No files exist |
| 666 | + File::shouldReceive('copy') |
| 667 | + ->andReturnTrue(); |
| 668 | + File::shouldReceive('get') |
| 669 | + ->andReturn(json_encode(['require' => [], 'require-dev' => []])); |
| 670 | + |
| 671 | + Process::fake(); |
| 672 | + |
| 673 | + // Act & Assert |
| 674 | + $this->artisan('laravel-init:install') |
| 675 | + ->doesntExpectOutput('already exists') // No prompts since files don't exist |
| 676 | + ->assertExitCode(0); |
| 677 | +}); |
0 commit comments