|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests; |
|
4
|
|
|
|
|
5
|
|
|
use LaravelZero\Framework\Container; |
|
6
|
|
|
|
|
7
|
|
|
class HelpersTest extends TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
/** @test */ |
|
10
|
|
|
public function abort_helper(): void |
|
11
|
|
|
{ |
|
12
|
|
|
$containerMock = $this->createMock(Container::class); |
|
13
|
|
|
|
|
14
|
|
|
$containerMock->expects($this->once())->method('abort')->with(404, 'Foo'); |
|
15
|
|
|
|
|
16
|
|
|
Container::setInstance($containerMock); |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
abort(404, 'Foo'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** @test */ |
|
22
|
|
View Code Duplication |
public function abort_if_helper(): void |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
abort_if(false, 123, 'Foo'); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertTrue(true); |
|
27
|
|
|
|
|
28
|
|
|
$containerMock = $this->createMock(Container::class); |
|
29
|
|
|
|
|
30
|
|
|
$containerMock->expects($this->once())->method('abort')->with(456, 'Bar'); |
|
31
|
|
|
|
|
32
|
|
|
Container::setInstance($containerMock); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
abort_if(true, 456, 'Bar'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** @test */ |
|
38
|
|
View Code Duplication |
public function abort_unless_helper(): void |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
abort_unless(true, 123, 'Foo'); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertTrue(true); |
|
43
|
|
|
|
|
44
|
|
|
$containerMock = $this->createMock(Container::class); |
|
45
|
|
|
|
|
46
|
|
|
$containerMock->expects($this->once())->method('abort')->with(456, 'Bar'); |
|
47
|
|
|
|
|
48
|
|
|
Container::setInstance($containerMock); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
abort_unless(false, 456, 'Bar'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** @test */ |
|
54
|
|
|
public function app_helper(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->assertSame(app(), Container::getInstance()); |
|
57
|
|
|
|
|
58
|
|
|
Container::getInstance()->bind('foo', function () { |
|
59
|
|
|
return 'bar'; |
|
60
|
|
|
}); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertEquals(app('foo'), 'bar'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** @test */ |
|
66
|
|
|
public function app_path_helper(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$this->assertSame(app_path(), app('path')); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals(app_path('foo'), app('path').DIRECTORY_SEPARATOR.'foo'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** @test */ |
|
74
|
|
|
public function config_helper(): void |
|
75
|
|
|
{ |
|
76
|
|
|
$this->assertSame(config(), app('config')); |
|
77
|
|
|
|
|
78
|
|
|
config(['foo' => 'bar']); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertEquals(app('config')->get('foo'), 'bar'); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertEquals(app('config')->get('foo2', 2), 2); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** @test */ |
|
86
|
|
|
public function event_helper(): void |
|
87
|
|
|
{ |
|
88
|
|
|
// @todo ... |
|
89
|
|
|
$this->assertTrue(true); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** @test */ |
|
93
|
|
|
public function base_path_helper(): void |
|
94
|
|
|
{ |
|
95
|
|
|
$this->assertEquals(BASE_PATH, base_path()); |
|
96
|
|
|
$this->assertEquals( |
|
97
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'some'.DIRECTORY_SEPARATOR.'directory', |
|
98
|
|
|
base_path('some'.DIRECTORY_SEPARATOR.'directory') |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** @test */ |
|
103
|
|
|
public function config_path_helper(): void |
|
104
|
|
|
{ |
|
105
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'config', config_path()); |
|
106
|
|
|
$this->assertEquals( |
|
107
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'vendor', |
|
108
|
|
|
config_path('vendor') |
|
109
|
|
|
); |
|
110
|
|
|
$this->assertEquals( |
|
111
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'custom.php', |
|
112
|
|
|
config_path('custom.php') |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** @test */ |
|
117
|
|
View Code Duplication |
public function database_path_helper(): void |
|
|
|
|
|
|
118
|
|
|
{ |
|
119
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'database', database_path()); |
|
120
|
|
|
$this->assertEquals( |
|
121
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'seeds', |
|
122
|
|
|
database_path('seeds') |
|
123
|
|
|
); |
|
124
|
|
|
$this->assertEquals( |
|
125
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'seeds'.DIRECTORY_SEPARATOR.'DatabaseSeeder.php', |
|
126
|
|
|
database_path('seeds'.DIRECTORY_SEPARATOR.'DatabaseSeeder.php') |
|
127
|
|
|
); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** @test */ |
|
131
|
|
|
public function resource_path_helper(): void |
|
132
|
|
|
{ |
|
133
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'resources', resource_path()); |
|
134
|
|
|
$this->assertEquals( |
|
135
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'js', |
|
136
|
|
|
resource_path('assets'.DIRECTORY_SEPARATOR.'js') |
|
137
|
|
|
); |
|
138
|
|
|
$this->assertEquals( |
|
139
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'app.php', |
|
140
|
|
|
resource_path('assets'.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'app.php') |
|
141
|
|
|
); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** @test */ |
|
145
|
|
View Code Duplication |
public function storage_path_helper(): void |
|
|
|
|
|
|
146
|
|
|
{ |
|
147
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'storage', storage_path()); |
|
148
|
|
|
$this->assertEquals( |
|
149
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'logs', |
|
150
|
|
|
storage_path('logs') |
|
151
|
|
|
); |
|
152
|
|
|
$this->assertEquals( |
|
153
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'logs'.DIRECTORY_SEPARATOR.'laravel.log', |
|
154
|
|
|
storage_path('logs'.DIRECTORY_SEPARATOR.'laravel.log') |
|
155
|
|
|
); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: