-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathLangJsServiceProviderTest.php
More file actions
104 lines (86 loc) · 2.63 KB
/
LangJsServiceProviderTest.php
File metadata and controls
104 lines (86 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace Mariuzzo\LaravelJsLocalization;
use Illuminate\Support\Facades\File as FileFacade;
use Orchestra\Testbench\TestCase;
/**
* The LangJsServiceProviderTest class.
*
* @author Rubens Mariuzzo <rubens@mariuzzo.com>
*/
class LangJsServiceProviderTest extends TestCase
{
/**
* The base path of tests.
*
* @var string
*/
private $testPath;
/**
* The root path of the project.
*
* @var string
*/
private $rootPath;
/**
* The file path of the expected output.
*
* @var string
*/
private $outputFilePath;
/**
* The base path of language files.
*
* @var string
*/
private $langPath;
/**
* LangJsCommandTest constructor.
*/
public function __construct()
{
parent::__construct();
$this->testPath = __DIR__ . '/..';
$this->rootPath = __DIR__ . '/../..';
$this->outputFilePath = "$this->testPath/output/lang.js";
$this->langPath = "$this->testPath/fixtures/lang";
}
protected function getPackageProviders($app = null)
{
return [
'Mariuzzo\LaravelJsLocalization\LaravelJsLocalizationServiceProvider',
'Mariuzzo\LaravelJsLocalization\NonameIncProvider',
];
}
/**
* Test the command.
*/
public function testShouldIncludePackageLangRegisteredInProvider()
{
$this->app->setBasePath(__DIR__ . '/../fixtures/');
// this checks the LaravelJsLocalizationServiceProvider was loaded
$this->artisan("lang:js {$this->outputFilePath}")
->assertExitCode(0);
$this->assertFileExists($this->outputFilePath);
$expected = '"en.nonameinc::messages":{"another_important_data":"this is from the package lang","important_data":"should have replaced packages value for this key","new_key":"this is a new key added ontop of the packages"}';
$result = file_get_contents($this->outputFilePath);
$this->_assertStringContainsString($expected, $result);
$this->cleanupOutputDirectory();
}
/**
* Cleanup output directory after tests.
*/
protected function cleanupOutputDirectory()
{
$files = FileFacade::files("{$this->testPath}/output");
foreach ($files as $file) {
FileFacade::delete($file);
}
}
public function _assertStringContainsString($needle, $haystack)
{
if (method_exists(get_parent_class($this), 'assertStringContainsString')) {
return $this->assertStringContainsString($needle, $haystack);
}
return $this->assertContains($needle, $haystack);
}
}