forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigRepositoryTest.php
More file actions
executable file
·143 lines (107 loc) · 5.3 KB
/
ConfigRepositoryTest.php
File metadata and controls
executable file
·143 lines (107 loc) · 5.3 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
use Mockery as m;
class ConfigRepositoryTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testHasGroupIndicatesIfConfigGroupExists()
{
$config = $this->getRepository();
$config->getLoader()->shouldReceive('exists')->once()->with('group', 'namespace')->andReturn(false);
$this->assertFalse($config->hasGroup('namespace::group'));
}
public function testHasOnTrueReturnsTrue()
{
$config = $this->getRepository();
$options = $this->getDummyOptions();
$config->getLoader()->shouldReceive('load')->once()->with('production', 'app', null)->andReturn($options);
$this->assertTrue($config->has('app.bing'));
$this->assertTrue($config->get('app.bing'));
}
public function testGetReturnsBasicItems()
{
$config = $this->getRepository();
$options = $this->getDummyOptions();
$config->getLoader()->shouldReceive('load')->once()->with('production', 'app', null)->andReturn($options);
$this->assertEquals('bar', $config->get('app.foo'));
$this->assertEquals('breeze', $config->get('app.baz.boom'));
$this->assertEquals('blah', $config->get('app.code', 'blah'));
$this->assertEquals('blah', $config->get('app.code', function() { return 'blah'; }));
}
public function testEntireArrayCanBeReturned()
{
$config = $this->getRepository();
$options = $this->getDummyOptions();
$config->getLoader()->shouldReceive('load')->once()->with('production', 'app', null)->andReturn($options);
$this->assertEquals($options, $config->get('app'));
}
public function testLoaderGetsCalledCorrectForNamespaces()
{
$config = $this->getRepository();
$options = $this->getDummyOptions();
$config->getLoader()->shouldReceive('load')->once()->with('production', 'options', 'namespace')->andReturn($options);
$this->assertEquals('bar', $config->get('namespace::options.foo'));
$this->assertEquals('breeze', $config->get('namespace::options.baz.boom'));
$this->assertEquals('blah', $config->get('namespace::options.code', 'blah'));
$this->assertEquals('blah', $config->get('namespace::options.code', function() { return 'blah'; }));
}
public function testNamespacedAccessedAndPostNamespaceLoadEventIsFired()
{
$config = $this->getRepository();
$options = $this->getDummyOptions();
$config->getLoader()->shouldReceive('load')->once()->with('production', 'options', 'namespace')->andReturn($options);
$config->afterLoading('namespace', function($repository, $group, $items)
{
$items['dayle'] = 'rees';
return $items;
});
$this->assertEquals('bar', $config->get('namespace::options.foo'));
$this->assertEquals('breeze', $config->get('namespace::options.baz.boom'));
$this->assertEquals('blah', $config->get('namespace::options.code', 'blah'));
$this->assertEquals('blah', $config->get('namespace::options.code', function() { return 'blah'; }));
$this->assertEquals('rees', $config->get('namespace::options.dayle'));
}
public function testLoaderUsesNamespaceAsGroupWhenUsingPackagesAndGroupDoesntExist()
{
$config = $this->getRepository();
$options = $this->getDummyOptions();
$config->getLoader()->shouldReceive('addNamespace')->with('namespace', __DIR__);
$config->getLoader()->shouldReceive('cascadePackage')->andReturnUsing(function($env, $package, $group, $items) { return $items; });
$config->getLoader()->shouldReceive('exists')->once()->with('foo', 'namespace')->andReturn(false);
$config->getLoader()->shouldReceive('exists')->once()->with('baz', 'namespace')->andReturn(false);
$config->getLoader()->shouldReceive('load')->once()->with('production', 'config', 'namespace')->andReturn($options);
$config->package('foo/namespace', __DIR__);
$this->assertEquals('bar', $config->get('namespace::foo'));
$this->assertEquals('breeze', $config->get('namespace::baz.boom'));
}
public function testItemsCanBeSet()
{
$config = $this->getRepository();
$config->getLoader()->shouldReceive('load')->once()->with('production', 'foo', null)->andReturn(array('name' => 'dayle'));
$config->set('foo.name', 'taylor');
$this->assertEquals('taylor', $config->get('foo.name'));
$config = $this->getRepository();
$config->getLoader()->shouldReceive('load')->once()->with('production', 'foo', 'namespace')->andReturn(array('name' => 'dayle'));
$config->set('namespace::foo.name', 'taylor');
$this->assertEquals('taylor', $config->get('namespace::foo.name'));
}
public function testPackageRegistersNamespaceAndSetsUpAfterLoadCallback()
{
$config = $this->getMock('Illuminate\Config\Repository', array('addNamespace'), array(m::mock('Illuminate\Config\LoaderInterface'), 'production'));
$config->expects($this->once())->method('addNamespace')->with($this->equalTo('rees'), $this->equalTo(__DIR__));
$config->getLoader()->shouldReceive('cascadePackage')->once()->with('production', 'dayle/rees', 'group', array('foo'))->andReturn(array('bar'));
$config->package('dayle/rees', __DIR__);
$afterLoad = $config->getAfterLoadCallbacks();
$results = call_user_func($afterLoad['rees'], $config, 'group', array('foo'));
$this->assertEquals(array('bar'), $results);
}
protected function getRepository()
{
return new Illuminate\Config\Repository(m::mock('Illuminate\Config\LoaderInterface'), 'production');
}
protected function getDummyOptions()
{
return array('foo' => 'bar', 'baz' => array('boom' => 'breeze'), 'bing' => true);
}
}