Skip to content

Commit 5a59719

Browse files
committed
refactor: unify into single mockChangeConfig function
1 parent b84c814 commit 5a59719

File tree

2 files changed

+16
-43
lines changed

2 files changed

+16
-43
lines changed

tests/InitCommandTest.php

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

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

1715
$this->mockFileGetContent(
1816
[
@@ -58,9 +56,7 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCaseTe
5856

5957
public function testRunWithoutAdminAndReadmeCreation()
6058
{
61-
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
62-
63-
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
59+
$this->mockChangeConfig('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php');
6460

6561
$this->mockFileGetContent(
6662
[
@@ -108,9 +104,7 @@ public function testRunWithoutAdminAndReadmeCreation()
108104

109105
public function testRunWithAdminAndWithoutReadmeCreation()
110106
{
111-
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
112-
113-
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
107+
$this->mockChangeConfig('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php');
114108

115109
$this->mockFileGetContent(
116110
[
@@ -162,9 +156,7 @@ public function testRunWithAdminAndWithoutReadmeCreation()
162156

163157
public function testRunWithAdminAndDefaultReadmeCreation()
164158
{
165-
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
166-
167-
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
159+
$this->mockChangeConfig('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php');
168160

169161
$this->mockFileGetContent(
170162
[
@@ -342,9 +334,7 @@ public function testRunWithAdminAndDefaultReadmeCreation()
342334

343335
public function testRunWithAdminAndPartialReadmeCreation()
344336
{
345-
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
346-
347-
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
337+
$this->mockChangeConfig('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php');
348338

349339
$this->mockFileGetContent(
350340
[
@@ -461,9 +451,7 @@ public function testRunWithAdminAndPartialReadmeCreation()
461451

462452
public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorInstallationMedia()
463453
{
464-
$this->mockUpdateConfigGetContent('config/auto-doc.php', 'auto_doc.php');
465-
466-
$this->mockUpdateConfigPutContent('config/auto-doc.php', 'auto_doc_after_changes.php');
454+
$this->mockChangeConfig('config/auto-doc.php', 'auto_doc.php', 'auto_doc_after_changes.php');
467455

468456
$this->mockFileGetContent(
469457
[

tests/Support/Traits/InitCommandMockTrait.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace RonasIT\ProjectInitializator\Tests\Support\Traits;
44

5+
use com_exception;
56
use Illuminate\Support\Arr;
67
use RonasIT\Support\Traits\MockTrait;
78

@@ -70,31 +71,15 @@ protected function getTemplate(string $template): string
7071
return file_get_contents(base_path("/resources/md/readme/{$template}"));
7172
}
7273

73-
public function mockUpdateConfigGetContent(string $path, string $expectedContent): void
74+
public function mockChangeConfig(string $path, string $initialContent, string $finalContent): void
7475
{
75-
$this->mockNativeFunction(
76-
'\Winter\LaravelConfigWriter',
77-
[
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)),
97-
]
98-
);
76+
$this->mockNativeFunction('\Winter\LaravelConfigWriter', [
77+
$this->functionCall('file_exists', [base_path($path)], true),
78+
$this->functionCall('file_get_contents', [base_path($path)], $this->getFixture($initialContent)),
79+
$this->functionCall('file_put_contents', [
80+
base_path($path),
81+
$this->getFixture($finalContent),
82+
], 1),
83+
]);
9984
}
10085
}

0 commit comments

Comments
 (0)