Skip to content

Commit

Permalink
[4.x] Fake composer installs in make command tests (#9955)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Apr 24, 2024
1 parent 49e0ce4 commit c9c48c0
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 62 deletions.
20 changes: 0 additions & 20 deletions tests/Console/Commands/Concerns/BacksUpComposerJson.php

This file was deleted.

13 changes: 13 additions & 0 deletions tests/Console/Commands/Concerns/FakesComposerInstalls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Tests\Console\Commands\Concerns;

use Facades\Statamic\Console\Processes\Composer;

trait FakesComposerInstalls
{
private function fakeSuccessfulComposerRequire()
{
Composer::shouldReceive('withoutQueue', 'throwOnFailure', 'require')->andReturnSelf();
}
}
7 changes: 3 additions & 4 deletions tests/Console/Commands/MakeActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class MakeActionTest extends TestCase
{
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;
use Concerns\CleansUpGeneratedPaths,
Concerns\FakesComposerInstalls;

private $files;

Expand All @@ -18,13 +18,12 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
$this->fakeSuccessfulComposerRequire();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
17 changes: 3 additions & 14 deletions tests/Console/Commands/MakeAddonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace Tests\Console\Commands;

use Facades\Statamic\Console\Processes\Composer;
use Illuminate\Filesystem\Filesystem;
use Tests\TestCase;

class MakeAddonTest extends TestCase
{
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;
use Concerns\CleansUpGeneratedPaths,
Concerns\FakesComposerInstalls;

private $files;

Expand All @@ -20,13 +19,12 @@ public function setUp(): void
$this->markTestSkippedInWindows();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
$this->fakeSuccessfulComposerRequire();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down Expand Up @@ -94,8 +92,6 @@ public function using_force_option_will_overwrite_original_addon()
/** @test */
public function it_can_generate_with_a_fieldtype()
{
$this->fakeSuccessfulComposerInstall();

$this->assertFileDoesNotExist(base_path('addons/hasselhoff/knight-rider'));

$this->makeAddon('hasselhoff/knight-rider', ['--fieldtype' => true]);
Expand All @@ -118,8 +114,6 @@ public function it_can_generate_with_a_fieldtype()
/** @test */
public function it_can_make_an_addon_with_everything_including_the_kitchen_sink()
{
$this->fakeSuccessfulComposerInstall();

$path = base_path('addons/ford/san-holo');

$this->assertFileDoesNotExist($path);
Expand All @@ -146,9 +140,4 @@ private function makeAddon($addon, $options = [])
'--no-interaction' => true,
], $options));
}

private function fakeSuccessfulComposerInstall()
{
Composer::shouldReceive('withoutQueue', 'throwOnFailure', 'require')->andReturnSelf();
}
}
7 changes: 3 additions & 4 deletions tests/Console/Commands/MakeFieldtypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class MakeFieldtypeTest extends TestCase
{
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;
use Concerns\CleansUpGeneratedPaths,
Concerns\FakesComposerInstalls;

private $files;

Expand All @@ -18,13 +18,12 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
$this->fakeSuccessfulComposerRequire();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
7 changes: 3 additions & 4 deletions tests/Console/Commands/MakeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class MakeFilterTest extends TestCase
{
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;
use Concerns\CleansUpGeneratedPaths,
Concerns\FakesComposerInstalls;

private $files;

Expand All @@ -18,13 +18,12 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
$this->fakeSuccessfulComposerRequire();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
7 changes: 3 additions & 4 deletions tests/Console/Commands/MakeModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class MakeModifierTest extends TestCase
{
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;
use Concerns\CleansUpGeneratedPaths,
Concerns\FakesComposerInstalls;

private $files;

Expand All @@ -18,13 +18,12 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
$this->fakeSuccessfulComposerRequire();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
7 changes: 3 additions & 4 deletions tests/Console/Commands/MakeScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class MakeScopeTest extends TestCase
{
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;
use Concerns\CleansUpGeneratedPaths,
Concerns\FakesComposerInstalls;

private $files;

Expand All @@ -18,13 +18,12 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
$this->fakeSuccessfulComposerRequire();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
7 changes: 3 additions & 4 deletions tests/Console/Commands/MakeTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class MakeTagTest extends TestCase
{
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;
use Concerns\CleansUpGeneratedPaths,
Concerns\FakesComposerInstalls;

private $files;

Expand All @@ -18,13 +18,12 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
$this->fakeSuccessfulComposerRequire();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
7 changes: 3 additions & 4 deletions tests/Console/Commands/MakeWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class MakeWidgetTest extends TestCase
{
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;
use Concerns\CleansUpGeneratedPaths,
Concerns\FakesComposerInstalls;

private $files;

Expand All @@ -18,13 +18,12 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
$this->fakeSuccessfulComposerRequire();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down

0 comments on commit c9c48c0

Please sign in to comment.