Skip to content

Commit

Permalink
Add test coverage to ensure package remains in require (not `requir…
Browse files Browse the repository at this point in the history
…e-dev`).
  • Loading branch information
jesseleite committed Nov 26, 2024
1 parent faeb1dc commit c299481
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/StarterKits/InstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Statamic\Facades\Blink;
use Statamic\Facades\Config;
use Statamic\Facades\YAML;
use Statamic\Support\Arr;
use Statamic\Support\Str;
use Tests\Fakes\Composer\FakeComposer;
use Tests\TestCase;
Expand Down Expand Up @@ -56,6 +57,7 @@ public function it_installs_starter_kit()
$this->assertFalse(Blink::has('starter-kit-repository-added'));
$this->assertFileDoesNotExist($this->kitVendorPath());
$this->assertFileDoesNotExist(base_path('composer.json.bak'));
$this->assertComposerJsonDoesntHavePackage('statamic/cool-runnings');
$this->assertComposerJsonDoesntHave('repositories');
$this->assertFileExists(base_path('copied.md'));
}
Expand Down Expand Up @@ -229,6 +231,7 @@ public function it_installs_as_living_package_with_custom_config()

// Keep package around
$this->assertFileExists($this->kitVendorPath());
$this->assertComposerJsonHasPackage('require', 'statamic/cool-runnings');

// But ensure we still delete backup composer.json, which is only used for error handling purposes
$this->assertFileDoesNotExist(base_path('composer.json.bak'));
Expand Down Expand Up @@ -258,6 +261,7 @@ public function it_leaves_custom_repository_for_living_packages_that_need_it()

// Keep package around
$this->assertFileExists($this->kitVendorPath());
$this->assertComposerJsonHasPackage('require', 'statamic/cool-runnings');

// As well as custom repository, which will be needed for composer updates, if it was needed for install
$composerJson = json_decode($this->files->get(base_path('composer.json')), true);
Expand Down Expand Up @@ -1665,6 +1669,21 @@ private function assertFileDoesntHaveContent($expected, $path)
$this->assertStringNotContainsString($expected, $this->files->get($path));
}

private function assertComposerJsonHasPackage($requireKey, $package)
{
$composerJson = json_decode($this->files->get(base_path('composer.json')), true);

$this->assertTrue(Arr::has($composerJson, "{$requireKey}.{$package}"));
}

private function assertComposerJsonDoesntHavePackage($package)
{
$composerJson = json_decode($this->files->get(base_path('composer.json')), true);

$this->assertFalse(Arr::has($composerJson, "require.{$package}"));
$this->assertFalse(Arr::has($composerJson, "require-dev.{$package}"));
}

private function assertComposerJsonHasPackageVersion($requireKey, $package, $version)
{
$composerJson = json_decode($this->files->get(base_path('composer.json')), true);
Expand Down

0 comments on commit c299481

Please sign in to comment.