Skip to content

Commit 7594d80

Browse files
committed
Done
1 parent 6100987 commit 7594d80

File tree

6 files changed

+115
-10
lines changed

6 files changed

+115
-10
lines changed

src/Commands/SetRepository.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class SetRepository extends Command
1111
{
12+
1213
/**
1314
* The name and signature of the console command.
1415
*
@@ -20,7 +21,6 @@ class SetRepository extends Command
2021
public string $repo;
2122

2223

23-
2424
public function handle(): int
2525
{
2626
$this->package = $this->argument('package');
@@ -55,6 +55,8 @@ public function handle(): int
5555
}
5656

5757
File::put(config('laravel-git-workflow.composer_json'), json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
58+
unset($composer);
59+
5860
return 0;
5961
}
6062
}

src/Commands/UpdateIssue.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ class UpdateIssue extends Command
1212
public ?string $branch;
1313
public ?string $message;
1414
private GitCommand $git;
15+
private array $repos;
1516

1617
public function __construct(GetCurrentBranchName $branch, GitCommand $git)
1718
{
1819
parent::__construct();
1920
$this->branch = $branch->execute();
2021
$this->git = $git;
22+
$this->repos = config('laravel-git-workflow.repositories') ?? [];
2123
}
2224

2325
public function handle()
@@ -34,6 +36,10 @@ public function handle()
3436
$this->message = config('laravel-git-workflow.wip');
3537
}
3638

39+
foreach ($this->repos as $k => $v) {
40+
$this->call('repo', ['package' => $k, 'repo' => 'git']);
41+
}
42+
3743
$this->git->execute('git add .');
3844
$this->git->execute('git commit -m "'.$this->message.'"');
3945
$this->git->execute('git pull --rebase');
@@ -43,6 +49,10 @@ public function handle()
4349
$this->call('issue:close');
4450
}
4551

52+
foreach ($this->repos as $k => $v) {
53+
$this->call('repo', ['package' => $k, 'repo' => 'path']);
54+
}
55+
4656
$this->info('Your commit has been added to the pull request.');
4757
}
4858
}

tests/SetRepositoryCommandTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,27 @@ public function setUp(): void
3535
public function tearDown(): void
3636
{
3737
File::put(config('laravel-git-workflow.composer_json'), $this->composer);
38+
File::put(config('laravel-git-workflow.composer_json'), $this->composer);
3839
}
3940

4041
/** @test */
4142
public function it_happily_switches_between_two_repos()
4243
{
4344
$composer = json_decode($this->composer, true);
4445

45-
$this->assertEquals(['type' => 'path', 'url' => '../../packages/edgrosvenor/my-crazy-package'], $composer['repositories'][1]);
46+
$this->assertEquals(['type' => 'git', 'url' => 'https://github.com/edgrosvenor/my-crazy-package'], $composer['repositories'][2]);
4647

4748
$this->artisan('repo my-crazy-package git');
4849

4950
$updated = json_decode(File::get(config('laravel-git-workflow.composer_json')), true);
5051

51-
$this->assertEquals(['type' => 'git', 'url' => 'https://github.com/edgrosvenor/my-crazy-package'], $updated['repositories'][1]);
52+
$this->assertEquals(['type' => 'git', 'url' => 'https://github.com/edgrosvenor/my-crazy-package'], $updated['repositories'][2]);
5253

5354
$this->artisan('repo my-crazy-package path');
5455

5556
$updated = json_decode(File::get(config('laravel-git-workflow.composer_json')), true);
5657

57-
$this->assertEquals(['type' => 'path', 'url' => '../../packages/edgrosvenor/my-crazy-package'], $updated['repositories'][1]);
58+
$this->assertEquals(['type' => 'path', 'url' => '../../packages/edgrosvenor/my-crazy-package'], $updated['repositories'][2]);
5859

5960
$this->artisan('repo my-crazy-package packagist');
6061

@@ -66,13 +67,13 @@ public function it_happily_switches_between_two_repos()
6667

6768
$updated = json_decode(File::get(config('laravel-git-workflow.composer_json')), true);
6869

69-
$this->assertEquals(['type' => 'path', 'url' => '../../packages/edgrosvenor/my-crazy-package'], $updated['repositories'][1]);
70+
$this->assertEquals(['type' => 'path', 'url' => '../../packages/edgrosvenor/my-crazy-package'], $updated['repositories'][2]);
7071

7172
$this->artisan('repo my-crazy-package git');
7273

7374
$updated = json_decode(File::get(config('laravel-git-workflow.composer_json')), true);
7475

75-
$this->assertEquals(['type' => 'git', 'url' => 'https://github.com/edgrosvenor/my-crazy-package'], $updated['repositories'][1]);
76+
$this->assertEquals(['type' => 'git', 'url' => 'https://github.com/edgrosvenor/my-crazy-package'], $updated['repositories'][2]);
7677
}
7778

7879
/** @test */

tests/UpdateIssueCommandTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,39 @@
33
namespace Tests;
44

55
use Grosv\LaravelGitWorkflow\Actions\GetCurrentBranchName;
6+
use Illuminate\Support\Facades\Config;
7+
use Illuminate\Support\Facades\File;
68

79
class UpdateIssueCommandTest extends TestCase
810
{
11+
private $composer;
12+
913
public function setUp(): void
1014
{
1115
parent::setUp();
16+
17+
Config::set('laravel-git-workflow.composer_json', __DIR__ . '/test_composer.json');
18+
Config::set('laravel-git-workflow.repositories', [
19+
'my-happy-package' => [
20+
'git' => 'https://github.com/edgrosvenor/my-happy-package',
21+
'path' => '../../packages/edgrosvenor/my-happy-package',
22+
],
23+
'my-crazy-package' => [
24+
'git' => 'https://github.com/edgrosvenor/my-crazy-package',
25+
'path' => '../../packages/edgrosvenor/my-crazy-package',
26+
],
27+
'my-sad-package' => [
28+
'path' => '../../packages/edgrosvenor/my-sad-package',
29+
],
30+
]);
31+
32+
$this->composer = File::get(config('laravel-git-workflow.composer_json'));
33+
34+
}
35+
36+
public function tearDown(): void
37+
{
38+
File::put(config('laravel-git-workflow.composer_json'), $this->composer);
1239
}
1340

1441
/** @test */
@@ -27,6 +54,7 @@ public function it_will_not_let_you_commit_directly_to_master()
2754
/** @test */
2855
public function it_will_let_you_commit_to_a_feature_branch()
2956
{
57+
3058
$this->mock(GetCurrentBranchName::class, function ($mock) {
3159
$mock->shouldReceive('execute')
3260
->andReturn('1_feature_branch');
@@ -36,5 +64,11 @@ public function it_will_let_you_commit_to_a_feature_branch()
3664
->expectsConfirmation('Are you ready to close this issue and request a review of the pull request?')
3765
->expectsOutput('Your commit has been added to the pull request.')
3866
->assertExitCode(0);
67+
68+
$updated = File::get(config('laravel-git-workflow.composer_json'));
69+
70+
$this->assertStringContainsString('../../packages/edgrosvenor/my-sad-package', $updated);
71+
$this->assertStringContainsString('../../packages/edgrosvenor/my-happy-package', $updated);
72+
$this->assertStringContainsString('../../packages/edgrosvenor/my-crazy-package', $updated);
3973
}
4074
}

tests/test_composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@
3333
},
3434
"repositories": [
3535
{
36-
"type": "path",
37-
"url": "../../packages/edgrosvenor/my-sad-package"
36+
"url": "https://github.com/edgrosvenor/my-happy-package",
37+
"type": "git"
3838
},
3939
{
40-
"url": "../../packages/edgrosvenor/my-crazy-package",
41-
"type": "path"
40+
"url": "../../packages/edgrosvenor/my-sad-package",
41+
"type": "git"
42+
},
43+
{
44+
"url": "https://github.com/edgrosvenor/my-crazy-package",
45+
"type": "git"
4246
}
4347
],
4448
"extra": {

tests/test_composer.json.original

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "grosv/totally-fake-package",
3+
"description": "A beautiful work of fiction",
4+
"type": "pipe-dream",
5+
"license": "Imaginary",
6+
"authors": [
7+
{
8+
"name": "Ed Grosvenor",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"minimum-stability": "dev",
13+
"prefer-stable": true,
14+
"require": {
15+
"php": "^7.4",
16+
"illuminate/support": "^7.0",
17+
"ext-json": "*"
18+
},
19+
"require-dev": {
20+
"orchestra/testbench": "^5.0",
21+
"nunomaduro/collision": "^4.1"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"Grosv\\LaravelGitWorkflow\\": "src/"
26+
}
27+
},
28+
"autoload-dev": {
29+
"psr-4": {
30+
"Tests\\": "tests/",
31+
"App\\": "vendor/orchestra/testbench-core/laravel/app"
32+
}
33+
},
34+
"repositories": [
35+
{
36+
"url": "https://github.com/edgrosvenor/my-happy-package",
37+
"type": "git"
38+
},
39+
{
40+
"url": "../../packages/edgrosvenor/my-sad-package",
41+
"type": "git"
42+
},
43+
{
44+
"url": "https://github.com/edgrosvenor/my-crazy-package",
45+
"type": "git"
46+
}
47+
48+
],
49+
"extra": {
50+
"laravel": {
51+
"providers": "Grosv\\LaravelGitWorkflow\\LaravelGitWorkflowProvider"
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)