1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Unit; |
4
|
|
|
|
5
|
|
|
use Tests\TestCase; |
6
|
|
|
use LaravelZero\Framework\Container; |
7
|
|
|
use Illuminate\Contracts\Config\Repository; |
8
|
|
|
|
9
|
|
|
class ContainerTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** @test */ |
12
|
|
|
public function it_has_version_getter() |
13
|
|
|
{ |
14
|
|
|
$configMock = $this->createMock(Repository::class); |
15
|
|
|
|
16
|
|
|
$configMock->expects($this->once()) |
17
|
|
|
->method('get') |
18
|
|
|
->with('app.version') |
19
|
|
|
->willReturn('X.2.3'); |
20
|
|
|
|
21
|
|
|
app()->instance('config', $configMock); |
22
|
|
|
|
23
|
|
|
$this->assertEquals((new Container)->version(), 'X.2.3'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** @test */ |
27
|
|
|
public function it_has_a_base_path_getter() |
28
|
|
|
{ |
29
|
|
|
$container = new Container; |
30
|
|
|
|
31
|
|
|
$this->assertEquals(BASE_PATH, $container->basePath()); |
32
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'Unit', $container->basePath('Unit')); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** @test */ |
36
|
|
View Code Duplication |
public function it_has_a_config_path_getter() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$container = new Container; |
39
|
|
|
|
40
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'config', $container->configPath()); |
41
|
|
|
$this->assertEquals( |
42
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'custom.php', |
43
|
|
|
$container->configPath('custom.php') |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** @test */ |
48
|
|
View Code Duplication |
public function it_has_a_database_path_getter() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$container = new Container; |
51
|
|
|
|
52
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'database', $container->databasePath()); |
53
|
|
|
$this->assertEquals( |
54
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations', |
55
|
|
|
$container->databasePath('migrations') |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** @test */ |
60
|
|
|
public function it_has_a_lang_path_getter() |
61
|
|
|
{ |
62
|
|
|
$this->assertEquals( |
63
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'lang', |
64
|
|
|
(new Container)->langPath() |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** @test */ |
69
|
|
|
public function it_has_a_resource_path_getter() |
70
|
|
|
{ |
71
|
|
|
$container = new Container; |
72
|
|
|
|
73
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'resources', $container->resourcePath()); |
74
|
|
|
$this->assertEquals( |
75
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'js', |
76
|
|
|
$container->resourcePath('assets'.DIRECTORY_SEPARATOR.'js') |
77
|
|
|
); |
78
|
|
|
$this->assertEquals( |
79
|
|
|
BASE_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'app.php', |
80
|
|
|
$container->resourcePath('assets'.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'app.php') |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** @test */ |
85
|
|
|
public function it_has_a_storage_path_getter() |
86
|
|
|
{ |
87
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'storage', (new Container)->storagePath()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** @test */ |
91
|
|
|
public function it_has_environment_getter() |
92
|
|
|
{ |
93
|
|
|
$configMock = $this->createMock(Repository::class); |
94
|
|
|
|
95
|
|
|
$configMock->expects($this->once()) |
96
|
|
|
->method('get') |
97
|
|
|
->with('app.production') |
98
|
|
|
->willReturn(true); |
99
|
|
|
|
100
|
|
|
app()->instance('config', $configMock); |
101
|
|
|
|
102
|
|
|
$this->assertEquals((new Container)->environment(), 'production'); |
103
|
|
|
|
104
|
|
|
$configMock = $this->createMock(Repository::class); |
105
|
|
|
|
106
|
|
|
$configMock->expects($this->once()) |
107
|
|
|
->method('get') |
108
|
|
|
->with('app.production') |
109
|
|
|
->willReturn(false); |
110
|
|
|
|
111
|
|
|
app()->instance('config', $configMock); |
112
|
|
|
|
113
|
|
|
$this->assertEquals((new Container)->environment(), 'development'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** @test */ |
117
|
|
|
public function it_confirms_the_running_in_console() |
118
|
|
|
{ |
119
|
|
|
$this->assertTrue( |
120
|
|
|
(new Container())->runningInConsole() |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** @test */ |
125
|
|
|
public function it_has_namespace_getter() |
126
|
|
|
{ |
127
|
|
|
// @todo |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** @test */ |
131
|
|
|
public function it_confirms_that_is_not_down_for_maintenance() |
132
|
|
|
{ |
133
|
|
|
$this->assertFalse( |
134
|
|
|
(new Container())->isDownForMaintenance() |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.