Skip to content

Commit d035c5f

Browse files
committed
Sync views and app files with tests
1 parent 6fe1e78 commit d035c5f

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

src/LangmanServiceProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public function register()
2525
return new Manager(
2626
new Filesystem(),
2727
$this->app['config']['langman.path'],
28-
$this->app['config']['view.paths']
28+
array_merge(
29+
$this->app['config']['view.paths'],
30+
(array) app_path()
31+
)
2932
);
3033
});
3134

src/Manager.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ class Manager
2525
private $path;
2626

2727
/**
28-
* the paths to the views files.
28+
* the paths to the views,app files.
2929
*
3030
* @var array
3131
*/
32-
private $viewsPaths;
32+
private $allFiles;
3333

3434
/**
3535
* Manager constructor.
3636
*
3737
* @param Filesystem $disk
3838
* @param string $path
3939
*/
40-
public function __construct(Filesystem $disk, $path, array $viewsPaths)
40+
public function __construct(Filesystem $disk, $path, array $allFiles)
4141
{
4242
$this->disk = $disk;
4343
$this->path = $path;
44-
$this->viewsPaths = $viewsPaths;
44+
$this->allFiles = $allFiles;
4545
}
4646

4747
/**
@@ -274,7 +274,7 @@ public function collectFromViews()
274274
;
275275

276276
/** @var \Symfony\Component\Finder\SplFileInfo $file */
277-
foreach ($this->disk->allFiles($this->viewsPaths) as $file) {
277+
foreach ($this->disk->allFiles($this->allFiles) as $file) {
278278
if (preg_match_all("/$pattern/siU", $file->getContents(), $matches)) {
279279
foreach ($matches[2] as $key) {
280280
try {

tests/SyncCommandTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ public function testCommandOutputForFile()
1111
file_put_contents(__DIR__.'/views_temp/user.blade.php', '{{ trans(\'user.name\') }} {{ trans(\'user.age\') }}');
1212
mkdir(__DIR__.'/views_temp/user');
1313
file_put_contents(__DIR__.'/views_temp/user/index.blade.php', "{{ trans('user.city') }} {{ trans('user.code.initial') }}");
14+
15+
array_map('unlink', glob(__DIR__.'/app_temp/Http/Controllers/testController.php'));
16+
array_map('unlink', glob(__DIR__.'/app_temp/Jobs/testJob.php'));
17+
array_map('rmdir', glob(__DIR__.'/app_temp/Http/Controllers'));
18+
array_map('rmdir', glob(__DIR__.'/app_temp/Http'));
19+
array_map('rmdir', glob(__DIR__.'/app_temp/Jobs'));
20+
mkdir(__DIR__.'/app_temp/Http');
21+
mkdir(__DIR__.'/app_temp/Http/Controllers');
22+
mkdir(__DIR__.'/app_temp/Jobs');
23+
24+
25+
file_put_contents(__DIR__.'/app_temp/Http/Controllers/testController.php', "<?php class testController{ public function index() { return Lang::get('user.first_name'); } }");
26+
27+
file_put_contents(__DIR__.'/app_temp/Jobs/testJob.php', "<?php class testJob{ public function index() { return Lang::get('user.last_name'); } }");
1428

1529
$this->createTempFiles([
1630
'en' => ['user' => "<?php\n return ['name' => 'Name'];"],
@@ -26,13 +40,23 @@ public function testCommandOutputForFile()
2640
$this->assertArrayHasKey('initial', $userENFile['code']);
2741
$this->assertArrayHasKey('age', $userENFile);
2842
$this->assertArrayHasKey('city', $userENFile);
43+
$this->assertArrayHasKey('first_name', $userENFile);
44+
$this->assertArrayHasKey('last_name', $userENFile);
2945
$this->assertArrayHasKey('name', $userNlFile);
3046
$this->assertArrayHasKey('initial', $userNlFile['code']);
3147
$this->assertArrayHasKey('age', $userNlFile);
3248
$this->assertArrayHasKey('city', $userNlFile);
33-
49+
$this->assertArrayHasKey('first_name', $userNlFile);
50+
$this->assertArrayHasKey('last_name', $userNlFile);
51+
3452
array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));
3553
array_map('rmdir', glob(__DIR__.'/views_temp/user'));
3654
array_map('unlink', glob(__DIR__.'/views_temp/user.blade.php'));
55+
56+
array_map('unlink', glob(__DIR__.'/app_temp/Http/Controllers/testController.php'));
57+
array_map('unlink', glob(__DIR__.'/app_temp/Jobs/testJob.php'));
58+
array_map('rmdir', glob(__DIR__.'/app_temp/Http/Controllers'));
59+
array_map('rmdir', glob(__DIR__.'/app_temp/Http'));
60+
array_map('rmdir', glob(__DIR__.'/app_temp/Jobs'));
3761
}
3862
}

tests/TestCase.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ protected function getPackageProviders($app)
1212
protected function getEnvironmentSetUp($app)
1313
{
1414
$app['config']->set('langman.path', __DIR__.'/temp');
15-
$app['config']->set('view.paths', [__DIR__.'/views_temp']);
15+
// here we put the app temp with views path , because the app_path in
16+
// service porovider pass wrong app path of laravel, but we need to
17+
// check if the app_temp directory exists or not
18+
if (!is_dir(__DIR__.'/app_temp')) {
19+
mkdir(__DIR__.'/app_temp');
20+
}
21+
$app['config']->set('view.paths', [__DIR__.'/views_temp',__DIR__.'/app_temp']);
1622
}
1723

1824
public function setUp()

0 commit comments

Comments
 (0)