1
- <?php
1
+ <?php namespace Userdesk \ Tests \ Subscription ;
2
2
3
3
use Illuminate \Foundation \Testing \WithoutMiddleware ;
4
4
use Illuminate \Foundation \Testing \DatabaseMigrations ;
5
5
use Illuminate \Foundation \Testing \DatabaseTransactions ;
6
6
7
7
use Userdesk \Subscription \SubscriptionFactory ;
8
8
9
- class SubscriptionFactoryTest extends Orchestra \Testbench \TestCase
9
+ use Config ;
10
+
11
+ class SubscriptionFactoryTest extends \Orchestra \Testbench \TestCase
10
12
{
11
13
14
+ /**
15
+ * @covers Userdesk\Subscription\SubscriptionFactory::createService
16
+ */
12
17
public function testCreateServiceThrowsExceptionIfNoConfig (){
13
18
$ this ->setExpectedException ('\\Userdesk\Subscription\Exceptions\SubscriptionException ' );
14
19
$ factory = new SubscriptionFactory ();
15
20
$ service = $ factory ->createService ('paypal ' );
16
21
}
17
22
23
+ /**
24
+ * @covers Userdesk\Subscription\SubscriptionFactory::createService
25
+ * @covers Userdesk\Subscription\SubscriptionFactory::fullyQualifiedServiceName
26
+ * @covers Userdesk\Subscription\SubscriptionFactory::buildService
27
+ */
18
28
public function testCreateServiceNonExistentService () {
19
29
Config::
set (
'subscription.services.foo.email ' ,
'[email protected] ' );
20
30
@@ -24,6 +34,11 @@ public function testCreateServiceNonExistentService() {
24
34
$ this ->assertNull ($ service );
25
35
}
26
36
37
+ /**
38
+ * @covers Userdesk\Subscription\SubscriptionFactory::createService
39
+ * @covers Userdesk\Subscription\SubscriptionFactory::fullyQualifiedServiceName
40
+ * @covers Userdesk\Subscription\SubscriptionFactory::buildService
41
+ */
27
42
public function testCreateServicePreLoaded (){
28
43
Config::
set (
'subscription.services.paypal.email ' ,
'[email protected] ' );
29
44
@@ -32,7 +47,40 @@ public function testCreateServicePreLoaded(){
32
47
33
48
$ this ->assertInstanceOf ('Userdesk \\Subscription \\Services \\Paypal ' , $ service );
34
49
}
50
+
51
+ /**
52
+ * @covers Userdesk\Subscription\SubscriptionFactory::registerService
53
+ */
54
+ public function testRegisterServiceThrowsExceptionIfNonExistentClass (){
55
+ $ this ->setExpectedException ('\\Userdesk\Subscription\Exceptions\SubscriptionException ' );
56
+ $ factory = new SubscriptionFactory ();
57
+ $ factory ->registerService ('foo ' , 'bar ' );
58
+ }
59
+
60
+ /**
61
+ * @covers Userdesk\Subscription\SubscriptionFactory::registerService
62
+ */
63
+ public function testRegisterServiceThrowsExceptionIfClassNotFulfillsContract (){
64
+ $ this ->setExpectedException ('\\Userdesk\Subscription\Exceptions\SubscriptionException ' );
65
+ $ factory = new SubscriptionFactory ();
66
+ $ factory ->registerService ('foo ' , 'Userdesk \\Subscription \\SubscriptionFactory ' );
67
+ }
35
68
69
+ /**
70
+ * @covers Userdesk\Subscription\SubscriptionFactory::registerService
71
+ */
72
+ public function testRegisterServiceSuccessIfClassFulfillsContract (){
73
+ $ factory = new SubscriptionFactory ();
74
+ $ this ->assertInstanceOf (
75
+ 'Userdesk \\Subscription \\SubscriptionFactory ' ,
76
+ $ factory ->registerService ('foo ' , 'Userdesk \\Subscription \\Mocks \\MockService ' )
77
+ );
78
+ }
79
+
80
+ /**
81
+ * @covers Userdesk\Subscription\SubscriptionFactory::registerServiceAlias
82
+ * @covers Userdesk\Subscription\SubscriptionFactory::registerService
83
+ */
36
84
public function testRegisterServiceAlias (){
37
85
Config::
set (
'subscription.services.paypal.email ' ,
'[email protected] ' );
38
86
Config::
set (
'subscription.services.alias.email ' ,
'[email protected] ' );
@@ -49,6 +97,12 @@ public function testRegisterServiceAlias(){
49
97
$ this ->assertInstanceOf ('Userdesk \\Subscription \\Services \\Paypal ' , $ newService );
50
98
}
51
99
100
+ /**
101
+ * @covers Userdesk\Subscription\SubscriptionFactory::createService
102
+ * @covers Userdesk\Subscription\SubscriptionFactory::fullyQualifiedServiceName
103
+ * @covers Userdesk\Subscription\SubscriptionFactory::registerService
104
+ * @covers Userdesk\Subscription\SubscriptionFactory::buildService
105
+ */
52
106
public function testCreateServiceUserRegistered (){
53
107
Config::
set (
'subscription.services.foo.email ' ,
'[email protected] ' );
54
108
@@ -61,6 +115,23 @@ public function testCreateServiceUserRegistered(){
61
115
62
116
$ newService = $ factory ->createService ('foo ' );
63
117
64
- $ this ->assertInstanceOf ('Userdesk \\Subscription \\Contracts \\Processor ' , $ newService );
118
+ $ this ->assertInstanceOf ('Userdesk \\Subscription \\Contracts \\Service ' , $ newService );
119
+ }
120
+
121
+ /**
122
+ * @covers Userdesk\Subscription\SubscriptionFactory::createService
123
+ * @covers Userdesk\Subscription\SubscriptionFactory::fullyQualifiedServiceName
124
+ * @covers Userdesk\Subscription\SubscriptionFactory::registerService
125
+ * @covers Userdesk\Subscription\SubscriptionFactory::buildService
126
+ */
127
+ public function testCreateServiceUserRegisteredOverridesPreLoaded (){
128
+ Config::
set (
'subscription.services.paypal.email ' ,
'[email protected] ' );
129
+
130
+ $ factory = new SubscriptionFactory ();
131
+ $ factory ->registerService ('paypal ' , 'Userdesk\Subscription\Mocks\MockService ' );
132
+
133
+ $ service = $ factory ->createService ('paypal ' );
134
+
135
+ $ this ->assertInstanceOf ('Userdesk \\Subscription \\Mocks \\MockService ' , $ service );
65
136
}
66
137
}
0 commit comments