Skip to content

Commit ece3717

Browse files
committed
Finalizes
1 parent 21718bc commit ece3717

File tree

12 files changed

+157
-43
lines changed

12 files changed

+157
-43
lines changed

src/Install/GuidelineWriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public function write(string $guidelines): int
3131
$filePath = $this->agent->guidelinesPath();
3232

3333
$directory = dirname($filePath);
34-
if (! is_dir($directory) && ! mkdir($directory, 0755, true)) {
34+
if (! is_dir($directory) && ! @mkdir($directory, 0755, true)) {
3535
throw new RuntimeException("Failed to create directory: {$directory}");
3636
}
3737

38-
$handle = fopen($filePath, 'c+');
38+
$handle = @fopen($filePath, 'c+');
3939
if (! $handle) {
4040
throw new RuntimeException("Failed to open file: {$filePath}");
4141
}

src/Support/Composer.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
class Composer
88
{
9-
/**
10-
* Get all packages directories listed in composer.json (both require and require-dev).
11-
*/
129
public static function packagesDirectories(): array
1310
{
1411
return collect(static::packages())
@@ -40,9 +37,6 @@ public static function packages(): array
4037
->toArray();
4138
}
4239

43-
/**
44-
* Get all packages directories that contain Boost guidelines.
45-
*/
4640
public static function packagesDirectoriesWithBoostGuidelines(): array
4741
{
4842
return collect(Composer::packagesDirectories())

src/Support/Config.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ public function getHerdMcp(): bool
6262
return $this->get('herd_mcp', false);
6363
}
6464

65+
public function flush(): void
66+
{
67+
$path = base_path(self::FILE);
68+
69+
if (file_exists($path)) {
70+
unlink($path);
71+
}
72+
}
73+
6574
protected function get(string $key, mixed $default = null): mixed
6675
{
6776
$config = $this->all();

tests/Feature/Console/InstallCommandWslTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
test('isRunningInWsl returns true when WSL_DISTRO_NAME is set', function (): void {
99
putenv('WSL_DISTRO_NAME=Ubuntu');
1010

11-
$command = new InstallCommand(new Config());
11+
$command = new InstallCommand(new Config);
1212
$reflection = new ReflectionClass($command);
1313
$method = $reflection->getMethod('isRunningInWsl');
1414

@@ -18,7 +18,7 @@
1818
test('isRunningInWsl returns true when IS_WSL is set', function (): void {
1919
putenv('IS_WSL=1');
2020

21-
$command = new InstallCommand(new Config());
21+
$command = new InstallCommand(new Config);
2222
$reflection = new ReflectionClass($command);
2323
$method = $reflection->getMethod('isRunningInWsl');
2424

@@ -29,7 +29,7 @@
2929
putenv('WSL_DISTRO_NAME=Ubuntu');
3030
putenv('IS_WSL=true');
3131

32-
$command = new InstallCommand(new Config());
32+
$command = new InstallCommand(new Config);
3333
$reflection = new ReflectionClass($command);
3434
$method = $reflection->getMethod('isRunningInWsl');
3535

@@ -40,7 +40,7 @@
4040
putenv('WSL_DISTRO_NAME');
4141
putenv('IS_WSL');
4242

43-
$command = new InstallCommand(new Config());
43+
$command = new InstallCommand(new Config);
4444
$reflection = new ReflectionClass($command);
4545
$method = $reflection->getMethod('isRunningInWsl');
4646

@@ -51,7 +51,7 @@
5151
putenv('WSL_DISTRO_NAME=');
5252
putenv('IS_WSL=');
5353

54-
$command = new InstallCommand(new Config());
54+
$command = new InstallCommand(new Config);
5555
$reflection = new ReflectionClass($command);
5656
$method = $reflection->getMethod('isRunningInWsl');
5757

tests/Pest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
|
1414
*/
1515

16+
use Laravel\Boost\Support\Config;
1617
use Laravel\Mcp\Response;
1718

18-
uses(Tests\TestCase::class)->in('Feature');
19+
uses(Tests\TestCase::class)->in('Unit', 'Feature')
20+
->beforeEach(function () {
21+
(new Config)->flush();
22+
});
1923

2024
expect()->extend('isToolResult', fn () => $this->toBeInstanceOf(Response::class));
2125

tests/Unit/Install/CodeEnvironment/CodeEnvironmentTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
$this->strategy = Mockery::mock(DetectionStrategy::class);
2222
});
2323

24-
afterEach(function (): void {
25-
Mockery::close();
26-
});
27-
2824
// Create a concrete test implementation for testing abstract methods
2925
class TestCodeEnvironment extends CodeEnvironment
3026
{

tests/Unit/Install/CodeEnvironmentsDetectorTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
$this->detector = new CodeEnvironmentsDetector($this->container);
1212
});
1313

14-
afterEach(function (): void {
15-
Mockery::close();
16-
});
17-
1814
test('discoverSystemInstalledCodeEnvironments returns detected programs', function (): void {
1915
// Create mock programs
2016
$program1 = Mockery::mock(CodeEnvironment::class);

tests/Unit/Install/Detection/CompositeDetectionStrategyTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
$this->thirdStrategy = Mockery::mock(DetectionStrategy::class);
1313
});
1414

15-
afterEach(function (): void {
16-
Mockery::close();
17-
});
18-
1915
test('returns true when first strategy succeeds', function (): void {
2016
$this->firstStrategy
2117
->shouldReceive('detect')

tests/Unit/Install/Mcp/FileWriterTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44

55
namespace Tests\Unit\Install\Mcp;
66

7+
use Illuminate\Contracts\Filesystem\Filesystem;
78
use Illuminate\Support\Facades\File;
89
use Illuminate\Support\Str;
910
use Laravel\Boost\Install\Mcp\FileWriter;
1011
use Mockery;
1112
use ReflectionClass;
1213

13-
beforeEach(function (): void {
14-
Mockery::close();
15-
});
16-
1714
test('constructor sets file path', function (): void {
1815
$writer = new FileWriter('/path/to/mcp.json');
1916
expect($writer)->toBeInstanceOf(FileWriter::class);
@@ -283,8 +280,7 @@
283280
test("injecting twice into existing JSON 5 doesn't cause duplicates", function (): void {
284281
$capturedContent = '';
285282

286-
File::clearResolvedInstances();
287-
File::partialMock();
283+
File::swap(Mockery::mock(Filesystem::class));
288284

289285
File::shouldReceive('ensureDirectoryExists')->once();
290286
File::shouldReceive('exists')->andReturn(true);
@@ -313,8 +309,7 @@
313309

314310
$newContent = $capturedContent;
315311

316-
File::clearResolvedInstances();
317-
File::partialMock();
312+
File::swap(Mockery::mock(Filesystem::class));
318313

319314
File::shouldReceive('ensureDirectoryExists')->once();
320315
File::shouldReceive('exists')->andReturn(true);
@@ -388,8 +383,7 @@
388383
function mockFileOperations(bool $fileExists = false, string $content = '{}', bool $writeSuccess = true, ?string &$capturedPath = null, ?string &$capturedContent = null): void
389384
{
390385
// Clear any existing File facade mock
391-
File::clearResolvedInstances();
392-
File::partialMock();
386+
File::swap(Mockery::mock(Filesystem::class));
393387

394388
File::shouldReceive('ensureDirectoryExists')->once();
395389
File::shouldReceive('exists')->andReturn($fileExists);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
use Laravel\Boost\Support\Config;
4+
5+
afterEach(function () {
6+
(new Config(__DIR__))->flush();
7+
});
8+
9+
it('may store and retrieve guidelines', function (): void {
10+
$config = new Config(__DIR__);
11+
12+
expect($config->getGuidelines())->toBeEmpty();
13+
14+
$guidelines = [
15+
'guideline_1',
16+
'guideline_2',
17+
];
18+
19+
$config->setGuidelines($guidelines);
20+
21+
expect($config->getGuidelines())->toEqual($guidelines);
22+
});
23+
24+
it('may store and retrieve agents', function (): void {
25+
$config = new Config(__DIR__);
26+
27+
expect($config->getAgents())->toBeEmpty();
28+
29+
$agents = [
30+
'agent_1',
31+
'agent_2',
32+
];
33+
34+
$config->setAgents($agents);
35+
36+
expect($config->getAgents())->toEqual($agents);
37+
});
38+
39+
it('may store and retrieve editors', function (): void {
40+
$config = new Config(__DIR__);
41+
42+
expect($config->getEditors())->toBeEmpty();
43+
44+
$editors = [
45+
'editor_1',
46+
'editor_2',
47+
];
48+
49+
$config->setEditors($editors);
50+
51+
expect($config->getEditors())->toEqual($editors);
52+
});
53+
54+
it('may store and retrieve herd mcp installation status', function (): void {
55+
$config = new Config(__DIR__);
56+
57+
expect($config->getHerdMcp())->toBeFalse();
58+
59+
$config->setHerdMcp(true);
60+
61+
expect($config->getHerdMcp())->toBeTrue();
62+
63+
$config->setHerdMcp(false);
64+
65+
expect($config->getHerdMcp())->toBeFalse();
66+
});

0 commit comments

Comments
 (0)