-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInjectExceptionTest.php
91 lines (80 loc) · 2.96 KB
/
InjectExceptionTest.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
<?php
use \Sixx\DependencyInjection\Inject;
use \Sixx\DependencyInjection\ServiceContainer;
class InjectExceptionTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
require_once __DIR__ . "/TestClasses/Classes.php";
}
/**
* @expectedException \Sixx\DependencyInjection\Exceptions\InjectException
* @expectedExceptionMessage Inject error: class SomethingElse not exist.
*/
public function testExceptionNotExistClass()
{
Inject::instantiation("SomethingElse");
}
/**
* @expectedException \Sixx\DependencyInjection\Exceptions\InjectException
* @expectedExceptionMessage Inject error: method SomeMethod in ChildClass not exist or not public.
*/
public function testExceptionNotExistMethod()
{
Inject::method("ChildClass", "SomeMethod");
}
/**
* @expectedException \Sixx\DependencyInjection\Exceptions\InjectException
* @expectedExceptionMessage Inject error: method testProtected in ChildClass not exist or not public.
*/
public function testExceptionNotPublicMethod()
{
Inject::method("ChildClass", "testProtected");
}
/**
* @expectedException \Sixx\DependencyInjection\Exceptions\InjectMustImplementException
* @expectedExceptionMessage Inject error: class Start must implement INext
*/
public function testExceptionClassMustImplement()
{
Inject::bind("INext", "Start");
Inject::method("ChildClass", "hello");
}
/**
* @expectedException \Sixx\DependencyInjection\Exceptions\InjectRequiredParameterException
* @expectedExceptionMessage Inject error: required parameter [start] in ChildClass::hello is not specified.
*/
public function testExceptionRequiredParameter()
{
Inject::bind("INext", "Next");
Inject::method("ChildClass", "hello", ["c" => "wer"]);
}
/**
* @expectedException \Sixx\DependencyInjection\Exceptions\InjectMustImplementException
* @expectedExceptionMessage Inject error: class Start must implement INext
*/
public function testExceptionClassMustImplements()
{
$class = new ServiceContainer();
$class->bind("INext", "Start");
$class->isInjected("INext");
}
/**
* @expectedException \Sixx\DependencyInjection\Exceptions\InjectRequiredParameterException
* @expectedExceptionMessage Inject error: required parameter [c] in SimpleParameter::__construct is not specified.
*/
public function testExceptionRequiredParameterDifferent()
{
Inject::bind("INext", "Next");
Inject::instantiation("SimpleParameter", ["c" => new Next()]);
}
/**
* @expectedException \Sixx\DependencyInjection\Exceptions\InjectNotInjectedException
* @expectedExceptionMessage Inject error: interface INext exist but not injected yet.
*/
public function testExceptionNotInjected()
{
Inject::flushServices();
Inject::instantiation("INext");
}
}