Skip to content

Commit 1ad195d

Browse files
authored
Merge pull request #4 from blamebutton/3-error-in-dockergenerate-detect
Bugfix for key not found
2 parents b10ab31 + 0c856f0 commit 1ad195d

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

src/Commands/GenerateQuestions/PhpExtensionsQuestion.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,18 @@ public function getAnswer(BaseCommand $command, string $phpVersion): array
4242
->detect();
4343

4444
if ($command->option('detect')) {
45-
$detected = explode(',', $detected);
46-
47-
foreach ($detected as $key => $value) {
48-
$detected[$key] = $supported[$value];
49-
}
50-
5145
return $detected;
5246
}
5347

48+
$default = collect($detected)
49+
->map(fn ($extension) => array_search($extension, $supported))
50+
->where(fn ($key) => is_int($key))
51+
->join(',');
52+
5453
return $command->choice(
5554
question: 'PHP extensions',
5655
choices: $supported,
57-
default: $detected,
56+
default: $default,
5857
multiple: true,
5958
);
6059
}

src/Detectors/DetectorContract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
interface DetectorContract
66
{
7-
public function detect(): string|false;
7+
public function detect(): array|string|false;
88
}

src/Detectors/PhpExtensionsDetector.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function supported(array $supported = null): self|array
2020
return $this;
2121
}
2222

23-
public function detect(): string
23+
public function detect(): array
2424
{
2525
$extensions = [
2626
$this->getDefaultExtensions(),
@@ -36,9 +36,8 @@ public function detect(): string
3636
->unique()
3737
->sort()
3838
->intersect($this->supported())
39-
->map(fn (string $extension) => array_search($extension, $this->supported()))
40-
->filter(fn ($value) => is_int($value))
41-
->join(',');
39+
->values()
40+
->toArray();
4241
}
4342

4443
/**

tests/Unit/Commands/GenerateQuestions/PhpExtensionsQuestionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testItDetectsExtensions(): void
7373
->andReturnSelf();
7474
$mock->shouldReceive('detect')
7575
->once()
76-
->andReturn('0,1');
76+
->andReturn(['bcmath', 'pdo_mysql']);
7777
});
7878

7979
$mock = $this->createMock(BaseCommand::class);
@@ -103,7 +103,7 @@ public function testItAsksForInput(): void
103103
->andReturnSelf();
104104
$mock->shouldReceive('detect')
105105
->once()
106-
->andReturn('');
106+
->andReturn([]);
107107
});
108108

109109
$mock = $this->createMock(BaseCommand::class);

tests/Unit/Detectors/PhpExtensionsDetectorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function provideConfigurations(): array
3737
{
3838
return [
3939
[
40-
'1',
40+
['bcmath'],
4141
[
4242
'cache.default' => 'array',
4343
'cache.stores.array.driver' => 'array',
@@ -52,7 +52,7 @@ public function provideConfigurations(): array
5252
],
5353
],
5454
[
55-
'0,1',
55+
['apcu', 'bcmath'],
5656
[
5757
'cache.default' => 'apc',
5858
'cache.stores.apc.driver' => 'apc',
@@ -66,7 +66,7 @@ public function provideConfigurations(): array
6666
],
6767
],
6868
[
69-
'1,6',
69+
['bcmath', 'redis'],
7070
[
7171
'cache.default' => 'array',
7272
'cache.stores.array.driver' => 'array',
@@ -80,7 +80,7 @@ public function provideConfigurations(): array
8080
],
8181
],
8282
[
83-
'1,6',
83+
['bcmath', 'redis'],
8484
[
8585
'cache.default' => 'array',
8686
'cache.stores.array.driver' => 'array',
@@ -94,7 +94,7 @@ public function provideConfigurations(): array
9494
],
9595
],
9696
[
97-
'0,1,3',
97+
['apcu', 'bcmath', 'pdo_mysql'],
9898
[
9999
'cache.default' => 'apc',
100100
'cache.stores.apc.driver' => 'apc',
@@ -108,7 +108,7 @@ public function provideConfigurations(): array
108108
],
109109
],
110110
[
111-
'1,2,5,6,7',
111+
['bcmath', 'memcached', 'pdo_sqlsrv', 'redis', 'sqlsrv'],
112112
[
113113
'cache.default' => 'memcached',
114114
'cache.stores.memcached.driver' => 'memcached',
@@ -126,7 +126,7 @@ public function provideConfigurations(): array
126126
}
127127

128128
/** @dataProvider provideConfigurations */
129-
public function testItDetectsExtensionsWithoutDuplicates(string $expected, array $config): void
129+
public function testItDetectsExtensionsWithoutDuplicates(array $expected, array $config): void
130130
{
131131
config()->set($config);
132132

0 commit comments

Comments
 (0)