-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathTestCase.php
109 lines (85 loc) · 2.93 KB
/
TestCase.php
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
105
106
107
108
109
sh<?php
use Mockery as m;
class TestCase extends Orchestra\Testbench\TestCase
{
protected $testMessagesConfig = [
'test_string',
'test' // this includes all messages with key 'test.*'
];
protected $testMessages = [
'en' => [
'test_string' => 'This is: test_string',
'test' => [
'nested' => [
'leaf' => 'I am deeply nested!'
],
'string' => 'This is: test.string'
],
'test.string' => 'This is: test.string'
]
];
protected $testMessagesFlat = [
'en' => [
'test_string' => 'This is: test_string',
'test.nested.leaf' => 'I am deeply nested!',
'test.string' => 'This is: test.string'
]
];
protected $testConfigExportFlat = [
'js-localization.test-config' => 'some test property value'
];
public function setUp()
{
parent::setUp();
$this->updateMessagesConfig($this->testMessagesConfig);
$this->updateConfigExportConfig($this->testConfigExportFlat);
$this->mockLang();
}
public function tearDown()
{
m::close();
parent::tearDown();
}
protected function getPackageProviders($app)
{
return ['JsLocalization\JsLocalizationServiceProvider'];
}
protected function updateMessagesConfig(array $config)
{
Config::set('js-localization.messages', $config);
}
protected function updateConfigExportConfig(array $configData)
{
Config::set('js-localization.config', array_keys($configData));
foreach ($configData as $propertyName => $propertyValue) {
Config::set($propertyName, $propertyValue);
}
}
protected function mockLang($locale = "en")
{
Illuminate\Support\Facades\Lang::swap($lang = m::mock('LangMock'));
$lang->shouldReceive('setLocale');
$lang->shouldReceive('locale')->andReturn($locale);
foreach ($this->testMessages[$locale] as $key=>$message) {
$lang->shouldReceive('get')
->with($key)->andReturn($message);
$lang->shouldReceive('get')
->with($key, m::any(), $locale)->andReturn($message);
}
}
protected function addTestMessage($locale, $messageKey, $message)
{
$this->testMessagesConfig[] = $messageKey;
$this->testMessages[$locale][$messageKey] = $message;
$this->testMessagesFlat[$locale][$messageKey] = $message;
$keys = explode('.', $messageKey);
if (count($keys) == 2) {
if (!isset($this->testMessages[$locale][$keys[0]])) {
$this->testMessages[$locale][$keys[0]] = [];
}
$this->testMessages[$locale][$keys[0]][$keys[1]] = $message;
}
$this->updateMessagesConfig($this->testMessagesConfig);
$this->mockLang();
}
}