Skip to content

Commit b84c814

Browse files
committed
fix: remarks from reviewer
1 parent 9e7534b commit b84c814

File tree

7 files changed

+73
-391
lines changed

7 files changed

+73
-391
lines changed

config/auto-doc.php

Lines changed: 0 additions & 184 deletions
This file was deleted.

src/Commands/InitCommand.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class InitCommand extends Command implements Isolatable
4646

4747
protected $description = 'Initialize required project parameters to run DEV environment';
4848

49-
protected string $emailTeamLead;
49+
protected string $codeOwnerEmail;
5050

5151
protected array $resources = [];
5252

@@ -77,8 +77,8 @@ public function handle(): void
7777

7878
$kebabName = Str::kebab($this->appName);
7979

80-
$this->emailTeamLead = $this->validateInput(
81-
method: fn () => $this->ask('Please specify a Code Owner/Team Lead\'s email', Str::before($this->reviewer, '@')),
80+
$this->codeOwnerEmail = $this->validateInput(
81+
method: fn () => $this->ask('Please specify a Code Owner/Team Lead\'s email'),
8282
field: 'email of code owner / team lead',
8383
rules: 'required|email',
8484
);
@@ -188,16 +188,16 @@ public function handle(): void
188188
shell_exec("{$shellCommand} --ansi");
189189
}
190190

191-
$this->setAutoDocContactEmail($this->emailTeamLead);
192-
191+
$this->setAutoDocContactEmail($this->codeOwnerEmail);
192+
193193
Artisan::call('migrate');
194194
}
195195

196196
protected function setAutoDocContactEmail(string $email): void
197197
{
198198
$config = ArrayFile::open(base_path('config/auto-doc.php'));
199199

200-
$config->set('info.contact.email', $email);
200+
$config->set('info.contact.email', $email);
201201

202202
$config->write();
203203
}
@@ -291,10 +291,6 @@ protected function fillContacts(): void
291291

292292
foreach (self::CONTACTS_ITEMS as $key => $title) {
293293
if ($link = $this->ask("Please enter a {$title}'s email", '')) {
294-
if (!empty($link) && $key === $this->emailTeamLead) {
295-
$this->reviewer = $link;
296-
}
297-
298294
$this->setReadmeValue($filePart, "{$key}_link", $link);
299295
} else {
300296
$this->emptyValuesList[] = "{$title}'s email";
@@ -303,7 +299,7 @@ protected function fillContacts(): void
303299
$this->removeTag($filePart, $key);
304300
}
305301

306-
$this->setReadmeValue($filePart, "team_lead_link", $this->emailTeamLead);
302+
$this->setReadmeValue($filePart, 'team_lead_link', $this->codeOwnerEmail);
307303

308304
$this->updateReadmeFile($filePart);
309305
}

tests/InitCommandTest.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class InitCommandTest extends TestCase
1010

1111
public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTelescopeAlreadyInstalled()
1212
{
13-
$this->mockArrayFilePutContent();
13+
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
14+
15+
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
1416

1517
$this->mockFileGetContent(
1618
[
@@ -56,7 +58,9 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe
5658

5759
public function testRunWithoutAdminAndReadmeCreation()
5860
{
59-
$this->mockArrayFilePutContent();
61+
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
62+
63+
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
6064

6165
$this->mockFileGetContent(
6266
[
@@ -104,7 +108,9 @@ public function testRunWithoutAdminAndReadmeCreation()
104108

105109
public function testRunWithAdminAndWithoutReadmeCreation()
106110
{
107-
$this->mockArrayFilePutContent();
111+
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
112+
113+
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
108114

109115
$this->mockFileGetContent(
110116
[
@@ -156,7 +162,9 @@ public function testRunWithAdminAndWithoutReadmeCreation()
156162

157163
public function testRunWithAdminAndDefaultReadmeCreation()
158164
{
159-
$this->mockArrayFilePutContent();
165+
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
166+
167+
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
160168

161169
$this->mockFileGetContent(
162170
[
@@ -334,7 +342,9 @@ public function testRunWithAdminAndDefaultReadmeCreation()
334342

335343
public function testRunWithAdminAndPartialReadmeCreation()
336344
{
337-
$this->mockArrayFilePutContent();
345+
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
346+
347+
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
338348

339349
$this->mockFileGetContent(
340350
[
@@ -451,7 +461,9 @@ public function testRunWithAdminAndPartialReadmeCreation()
451461

452462
public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorInstallationMedia()
453463
{
454-
$this->mockArrayFilePutContent();
464+
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
465+
466+
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
455467

456468
$this->mockFileGetContent(
457469
[

tests/Support/Traits/InitCommandMockTrait.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,30 @@ protected function getTemplate(string $template): string
7070
return file_get_contents(base_path("/resources/md/readme/{$template}"));
7171
}
7272

73-
public function mockArrayFilePutContent(): void
73+
public function mockUpdateConfigGetContent(string $path, string $expectedContent): void
7474
{
7575
$this->mockNativeFunction(
7676
'\Winter\LaravelConfigWriter',
7777
[
78-
[
79-
'function' => 'file_put_contents',
80-
'arguments' => [base_path('config/auto-doc.php'), $this->getFixture('auto-doc.php')],
81-
'result' => $this->getFixture('auto-doc.php'),
82-
],
78+
$this->functionCall('file_exists', [
79+
base_path($path),
80+
], true),
81+
$this->functionCall('file_get_contents', [
82+
base_path($path),
83+
], $this->getFixture($expectedContent)),
84+
]
85+
);
86+
}
87+
88+
public function mockUpdateConfigPutContent(string $path, string $expectedContent): void
89+
{
90+
$this->mockNativeFunction(
91+
'\Winter\LaravelConfigWriter',
92+
[
93+
$this->functionCall('file_put_contents', [
94+
base_path($path),
95+
$this->getFixture($expectedContent),
96+
], $this->getFixture($expectedContent)),
8397
]
8498
);
8599
}

0 commit comments

Comments
 (0)