Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit 352acbe

Browse files
committed
Backfill test
1 parent 186e4ac commit 352acbe

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

src/Support/TaskManifest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class TaskManifest
1212

1313
public function __construct(string $vendorPath)
1414
{
15-
$this->manifestPath = $vendorPath . '/shift-tasks.php';
1615
$this->vendorPath = $vendorPath;
16+
$this->manifestPath = $vendorPath . DIRECTORY_SEPARATOR . 'shift-tasks.php';
1717
}
1818

1919
public function list(): array
@@ -33,8 +33,9 @@ public function list(): array
3333
public function build(): void
3434
{
3535
$packages = [];
36+
$path = $this->vendorPath . DIRECTORY_SEPARATOR . 'composer' . DIRECTORY_SEPARATOR . 'installed.json';
3637

37-
if (file_exists($path = $this->vendorPath . '/composer/installed.json')) {
38+
if (file_exists($path)) {
3839
$installed = json_decode(file_get_contents($path), true);
3940

4041
$packages = $installed['packages'] ?? $installed;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace Tests\Feature\Support;
4+
5+
use PHPUnit\Framework\Attributes\Test;
6+
use PHPUnit\Framework\TestCase;
7+
use Shift\Cli\Sdk\Testing\InteractsWithProject;
8+
use Shift\Cli\Support\TaskManifest;
9+
10+
class TaskManifestTest extends TestCase
11+
{
12+
use InteractsWithProject;
13+
14+
#[Test]
15+
public function list_returns_existing_manifest()
16+
{
17+
$this->fakeProject([
18+
'shift-tasks.php' => '<?php return ["task-name" => "fqcn"];',
19+
]);
20+
21+
$taskManifest = new TaskManifest($this->currentSnapshotPath());
22+
23+
$this->assertSame(['task-name' => 'fqcn'], $taskManifest->list());
24+
}
25+
26+
#[Test]
27+
public function list_returns_default_tasks_for_no_manifest()
28+
{
29+
$this->fakeProject([]);
30+
31+
$taskManifest = new TaskManifest($this->currentSnapshotPath());
32+
33+
$this->assertSame($this->defaultTasks(), $taskManifest->list());
34+
$this->assertFileExists($this->currentSnapshotPath() . DIRECTORY_SEPARATOR . 'shift-tasks.php');
35+
}
36+
37+
#[Test]
38+
public function build_returns_merged_tasks_from_packages()
39+
{
40+
$this->fakeProject([
41+
'composer/installed.json' => json_encode([
42+
'packages' => [
43+
[
44+
'extra' => [
45+
'shift' => [
46+
'tasks' => ['package1-task' => '\\Package1\\Task'],
47+
],
48+
],
49+
],
50+
[
51+
'extra' => [
52+
'shift' => [
53+
'tasks' => ['package2-task' => '\\Package2\\Task'],
54+
],
55+
],
56+
],
57+
],
58+
]),
59+
]);
60+
61+
$taskManifest = new TaskManifest($this->currentSnapshotPath());
62+
63+
$this->assertEqualsCanonicalizing(
64+
array_merge(['package1-task' => '\\Package1\\Task', 'package2-task' => '\\Package2\\Task'], $this->defaultTasks()),
65+
$taskManifest->list()
66+
);
67+
68+
$this->assertFileExists($this->currentSnapshotPath() . DIRECTORY_SEPARATOR . 'shift-tasks.php');
69+
}
70+
71+
private function defaultTasks()
72+
{
73+
return [
74+
'anonymous-migrations' => \Shift\Cli\Tasks\AnonymousMigrations::class,
75+
'check-lint' => \Shift\Cli\Tasks\CheckLint::class,
76+
'class-strings' => \Shift\Cli\Tasks\ClassStrings::class,
77+
'debug-calls' => \Shift\Cli\Tasks\DebugCalls::class,
78+
'declare-strict' => \Shift\Cli\Tasks\DeclareStrictTypes::class,
79+
'down-migration' => \Shift\Cli\Tasks\DownMigration::class,
80+
'explicit-orderby' => \Shift\Cli\Tasks\ExplicitOrderBy::class,
81+
'facade-aliases' => \Shift\Cli\Tasks\FacadeAliases::class,
82+
'faker-methods' => \Shift\Cli\Tasks\FakerMethods::class,
83+
'laravel-carbon' => \Shift\Cli\Tasks\LaravelCarbon::class,
84+
'latest-oldest' => \Shift\Cli\Tasks\LatestOldest::class,
85+
'model-table' => \Shift\Cli\Tasks\ModelTableName::class,
86+
'order-model' => \Shift\Cli\Tasks\OrderModel::class,
87+
'remove-docblocks' => \Shift\Cli\Tasks\RemoveDocBlocks::class,
88+
'rules-arrays' => \Shift\Cli\Tasks\RulesArrays::class,
89+
];
90+
}
91+
}

0 commit comments

Comments
 (0)