/
BootstrapperL5ServiceProviderSpec.php
149 lines (131 loc) · 5.24 KB
/
BootstrapperL5ServiceProviderSpec.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
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
144
145
146
147
148
149
<?php
namespace spec\Bootstrapper {
use Bootstrapper\BootstrapperServiceProvider;
use PhpSpec\Exception\Example\SkippingException;
use PhpSpec\Exception\Exception;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class BootstrapperL5ServiceProviderSpec extends ObjectBehavior
{
/**
* @var FakeApp
*/
protected $app;
function let()
{
$this->app = new FakeApp();
$this->beConstructedWith($this->app);
}
function it_is_initializable()
{
$this->shouldHaveType('Bootstrapper\BootstrapperL5ServiceProvider');
}
function it_can_register_things()
{
$this->register();
$classes = [
'bootstrapper::accordion' => 'Bootstrapper\\Accordion',
'bootstrapper::alert' => 'Bootstrapper\\Alert',
'bootstrapper::badge' => 'Bootstrapper\\Badge',
'bootstrapper::breadcrumb' => 'Bootstrapper\\Breadcrumb',
'bootstrapper::buttongroup' => 'Bootstrapper\\ButtonGroup',
'bootstrapper::button' => 'Bootstrapper\\Button',
'bootstrapper::carousel' => 'Bootstrapper\\Carousel',
'bootstrapper::config' => 'Bootstrapper\\Bridges\\Config\\Laravel5Config',
'bootstrapper::controlgroup' => 'Bootstrapper\\ControlGroup',
'bootstrapper::dropdownbutton' => 'Bootstrapper\\DropdownButton',
'bootstrapper::form' => 'Bootstrapper\\Form',
'bootstrapper::icon' => 'Bootstrapper\\Icon',
'bootstrapper::image' => 'Bootstrapper\\Image',
'bootstrapper::inputgroup' => 'Bootstrapper\\InputGroup',
'bootstrapper::label' => 'Bootstrapper\\Label',
'bootstrapper::helpers' => 'Bootstrapper\\Helpers',
'bootstrapper::mediaobject' => 'Bootstrapper\\MediaObject',
'bootstrapper::modal' => 'Bootstrapper\\Modal',
'bootstrapper::navbar' => 'Bootstrapper\\Navbar',
'bootstrapper::navigation' => 'Bootstrapper\\Navigation',
'bootstrapper::panel' => 'Bootstrapper\\Panel',
'bootstrapper::progressbar' => 'Bootstrapper\\ProgressBar',
'bootstrapper::tabbable' => 'Bootstrapper\\Tabbable',
'bootstrapper::table' => 'Bootstrapper\\Table',
'bootstrapper::thumbnail' => 'Bootstrapper\\Thumbnail',
];
foreach($classes as $class => $className)
{
if (!$this->app->make($class) instanceof $className)
{
throw new Exception("Expected an instance of $className when resolving $class. Instead recieved: " . get_class($this->app->make($class)));
}
}
}
}
class FakeApp implements \ArrayAccess
{
protected $registered = [];
protected $classes = [];
public function bind($abstract, $concrete = null, $shared = false)
{
$this->registered[$abstract] = $concrete;
}
public function make($abstract, $parameters = array())
{
switch($abstract)
{
case 'config':
$mock = \Mockery::mock('Illuminate\\Contracts\\Config\\Repository');
$mock->shouldReceive('get')->andReturn([]);
$mock->shouldReceive('set');
return $mock;
case 'html':
$mock = \Mockery::mock('Illuminate\\Html\\HtmlBuilder');
return $mock;
case 'url':
$mock = \Mockery::mock('Illuminate\\Routing\\UrlGenerator');
return $mock;
case 'session.store':
$mock = \Mockery::mock('Illuminate\\Session\\Store');
$mock->shouldReceive('getToken');
$mock->shouldReceive('token');
return $mock;
case 'files':
$mock = \Mockery::mock('Files');
$mock->shouldReceive('isDirectory');
return $mock;
case 'view':
$mock = \Mockery::mock('Illuminate\Contracts\View\Factory');
return $mock;
}
if (!isset($this->registered[$abstract]))
{
throw new \Exception("'$abstract' isn't defined yet");
}
if (!isset($this->classes[$abstract])) {
$this->classes[$abstract] = $this->registered[$abstract]($this);
}
return $this->classes[$abstract];
}
public function offsetExists($offset)
{
return isset($this->registered[$offset]);
}
public function offsetGet($offset)
{
return $this->make($offset);
}
public function offsetSet($offset, $value)
{
return $this->bind($offset, $value);
}
public function offsetUnset($offset)
{
unset($this->registered[$offset]);
unset($this->classes[$offset]);
}
}
}
namespace {
function config_path()
{
return '';
}
}