Skip to content

Commit 3ba3ec5

Browse files
committed
refactor: code
refs: #49
1 parent 872c78b commit 3ba3ec5

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

tests/Support/FileSystemMock.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class FileSystemMock
1717
public ?array $testClasses = null;
1818
public ?array $routes = null;
1919
public ?array $factories = null;
20+
public ?array $translations = null;
2021

2122
public function setStructure(): void
2223
{
@@ -106,6 +107,14 @@ public function setStructure(): void
106107
}
107108
}
108109

110+
if (!is_null($this->translations)) {
111+
$structure['resources']['lang']['en'] = [];
112+
113+
foreach ($this->translations as $translation => $content) {
114+
$structure['resources']['lang']['en'][$translation] = $content;
115+
}
116+
}
117+
109118
vfsStream::create($structure);
110119
}
111120
}

tests/Support/Translation/TranslationMockTrait.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,30 @@
22

33
namespace RonasIT\Support\Tests\Support\Translation;
44

5-
use org\bovigo\vfs\vfsStream;
5+
use RonasIT\Support\Tests\Support\FileSystemMock;
66
use RonasIT\Support\Tests\Support\GeneratorMockTrait;
7-
use RonasIT\Support\Traits\MockTrait;
87

98
trait TranslationMockTrait
109
{
11-
use GeneratorMockTrait, MockTrait;
10+
use GeneratorMockTrait;
1211

1312
public function mockFilesystem(): void
1413
{
15-
$structure = [
16-
'resources' => [
17-
'lang' => [
18-
'en' => [],
19-
],
20-
],
21-
];
22-
23-
vfsStream::create($structure);
14+
$fileSystemMock = new FileSystemMock;
15+
16+
$fileSystemMock->translations = [];
17+
18+
$fileSystemMock->setStructure();
2419
}
2520

2621
public function mockFilesystemForAppend(): void
2722
{
2823
$validation = file_get_contents(getcwd() . '/tests/Support/Translation/validation_without_exceptions.php');
2924

30-
$structure = [
31-
'resources' => [
32-
'lang' => [
33-
'en' => [
34-
'validation.php' => $validation,
35-
],
36-
],
37-
],
38-
];
39-
40-
vfsStream::create($structure);
25+
$fileSystemMock = new FileSystemMock;
26+
27+
$fileSystemMock->translations = ['validation.php' => $validation];
28+
29+
$fileSystemMock->setStructure();
4130
}
4231
}

tests/TranslationGeneratorTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public function testCreateStubNotExist()
3737
{
3838
config(['entity-generator.stubs.validation' => 'incorrect_stub']);
3939

40-
$this->mockFilesystem();
41-
4240
app(TranslationsGenerator::class)
4341
->setModel('Post')
4442
->generate();

0 commit comments

Comments
 (0)