|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Coduo\TuTu\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use Coduo\TuTu\Extension; |
|
6
|
|
|
use Coduo\TuTu\ServiceContainer; |
|
7
|
|
|
use PhpSpec\ObjectBehavior; |
|
8
|
|
|
use Prophecy\Argument; |
|
9
|
|
|
use Symfony\Component\ClassLoader\ClassLoader; |
|
10
|
|
|
|
|
11
|
|
|
class MyExtension implements Extension |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var |
|
15
|
|
|
*/ |
|
16
|
|
|
private $argument; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct($argument = null) |
|
19
|
|
|
{ |
|
20
|
|
|
$this->argument = $argument; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param \Coduo\TuTu\ServiceContainer $container |
|
25
|
|
|
*/ |
|
26
|
|
|
public function load(ServiceContainer $container) |
|
27
|
|
|
{ |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return mixed |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getArgument() |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->argument; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
class InitializerSpec extends ObjectBehavior |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
public function let(ClassLoader $classLoader) |
|
42
|
|
|
{ |
|
43
|
|
|
$classLoader->loadClass(Argument::type('string'))->willReturn(false); |
|
44
|
|
|
$this->beConstructedWith($classLoader); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
function it_throws_exception_when_string_is_not_valid_class() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->shouldThrow(new \InvalidArgumentException("asdasd is not valid class.")) |
|
50
|
|
|
->during('initialize', ['asdasd']); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_throws_exception_when_class_is_not_TuTu_extension() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->shouldThrow(new \InvalidArgumentException("Class \"stdClass\" should be an instance of Coduo\\TuTu\\Extension")) |
|
56
|
|
|
->during('initialize', ['stdClass']); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
function it_initialize_TuTu_extension() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->initialize('spec\Coduo\TuTu\Extension\MyExtension')->shouldReturnAnInstanceOf('Coduo\TuTu\Extension'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
function it_initialize_TuTu_extension_with_constructor_arguments() |
|
65
|
|
|
{ |
|
66
|
|
|
$extension = $this->initialize('spec\Coduo\TuTu\Extension\MyExtension', ['test']); |
|
67
|
|
|
$extension->shouldBeAnInstanceOf('Coduo\TuTu\Extension'); |
|
68
|
|
|
$extension->getArgument()->shouldReturn('test'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.