forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigFileLoaderTest.php
More file actions
executable file
·96 lines (71 loc) · 3.52 KB
/
ConfigFileLoaderTest.php
File metadata and controls
executable file
·96 lines (71 loc) · 3.52 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
<?php
use Mockery as m;
class ConfigFileLoaderTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testEmptyArrayIsReturnedOnNullPath()
{
$loader = $this->getLoader();
$this->assertEquals(array(), $loader->load('local', 'group', 'namespace'));
}
public function testBasicArrayIsReturned()
{
$loader = $this->getLoader();
$loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/app.php')->andReturn(true);
$loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/local/app.php')->andReturn(false);
$loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/app.php')->andReturn(array('foo' => 'bar'));
$array = $loader->load('local', 'app', null);
$this->assertEquals(array('foo' => 'bar'), $array);
}
public function testEnvironmentArrayIsMerged()
{
$loader = $this->getLoader();
$loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/app.php')->andReturn(true);
$loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/local/app.php')->andReturn(true);
$loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/app.php')->andReturn(array('foo' => 'bar'));
$loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/local/app.php')->andReturn(array('foo' => 'blah', 'baz' => 'boom'));
$array = $loader->load('local', 'app', null);
$this->assertEquals(array('foo' => 'blah', 'baz' => 'boom'), $array);
}
public function testGroupExistsReturnsTrueWhenTheGroupExists()
{
$loader = $this->getLoader();
$loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/app.php')->andReturn(true);
$this->assertTrue($loader->exists('app'));
}
public function testGroupExistsReturnsTrueWhenNamespaceGroupExists()
{
$loader = $this->getLoader();
$loader->addNamespace('namespace', __DIR__.'/namespace');
$loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/namespace/app.php')->andReturn(true);
$this->assertTrue($loader->exists('app', 'namespace'));
}
public function testGroupExistsReturnsFalseWhenNamespaceHintDoesntExists()
{
$loader = $this->getLoader();
$this->assertFalse($loader->exists('app', 'namespace'));
}
public function testGroupExistsReturnsFalseWhenNamespaceGroupDoesntExists()
{
$loader = $this->getLoader();
$loader->addNamespace('namespace', __DIR__.'/namespace');
$loader->getFilesystem()->shouldReceive('exists')->with(__DIR__.'/namespace/app.php')->andReturn(false);
$this->assertFalse($loader->exists('app', 'namespace'));
}
public function testCascadingPackagesProperlyLoadsFiles()
{
$loader = $this->getLoader();
$loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/packages/dayle/rees/group.php')->andReturn(true);
$loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/packages/dayle/rees/group.php')->andReturn(array('bar' => 'baz'));
$loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/packages/dayle/rees/local/group.php')->andReturn(true);
$loader->getFilesystem()->shouldReceive('getRequire')->once()->with(__DIR__.'/packages/dayle/rees/local/group.php')->andReturn(array('foo' => 'boom'));
$items = $loader->cascadePackage('local', 'dayle/rees', 'group', array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'boom', 'bar' => 'baz'), $items);
}
protected function getLoader()
{
return new Illuminate\Config\FileLoader(m::mock('Illuminate\Filesystem\Filesystem'), __DIR__);
}
}