3
3
4
4
require __DIR__ . '/../../../vendor/autoload.php ' ;
5
5
6
+ use PHPUnit \Framework \TestCase ;
6
7
use Upwork \API \Debug as ApiDebug ;
7
8
use Upwork \API \Config as ApiConfig ;
8
9
use Upwork \API \Client as Client ;
9
10
10
- class ClientTest extends \PHPUnit_Framework_TestCase
11
+ class ClientTest extends TestCase
11
12
{
12
13
/**
13
14
* @test
@@ -37,14 +38,13 @@ public function testGetServer()
37
38
'consumerSecret ' => 'secret '
38
39
)
39
40
);
40
- $ reflection = new \ReflectionClass (' Upwork\API\Client ' );
41
+ $ reflection = new \ReflectionClass (\ Upwork \API \Client::class );
41
42
$ property = $ reflection ->getProperty ('_server ' );
42
43
$ property ->setAccessible (true );
43
44
$ helper = new Client ($ config );
44
45
$ property ->setValue ($ helper , new \StdClass );
45
46
$ server = $ helper ->getServer ();
46
47
47
- $ this ->assertAttributeInstanceOf ('StdClass ' , '_server ' , $ helper );
48
48
$ this ->assertInstanceOf ('StdClass ' , $ server );
49
49
}
50
50
@@ -59,12 +59,14 @@ public function testGetRequestToken()
59
59
'consumerSecret ' => 'secret '
60
60
)
61
61
);
62
- $ reflection = new \ReflectionClass (' Upwork\API\Client ' );
62
+ $ reflection = new \ReflectionClass (\ Upwork \API \Client::class );
63
63
$ property = $ reflection ->getProperty ('_server ' );
64
64
$ property ->setAccessible (true );
65
65
$ helper = new Client ($ config );
66
66
67
- $ stub = $ this ->getMock ('StdClass ' , array ('setupRequestToken ' ));
67
+ $ stub = $ this ->getMockBuilder (stdClass::class)
68
+ ->setMethods (['setupRequestToken ' ])
69
+ ->getMock ();
68
70
$ stub ->expects ($ this ->any ())
69
71
->method ('setupRequestToken ' )
70
72
->will ($ this ->returnValue ('testtoken ' ));
@@ -85,12 +87,14 @@ public function testAuth()
85
87
'consumerSecret ' => 'secret '
86
88
)
87
89
);
88
- $ reflection = new \ReflectionClass (' Upwork\API\Client ' );
90
+ $ reflection = new \ReflectionClass (\ Upwork \API \Client::class );
89
91
$ property = $ reflection ->getProperty ('_server ' );
90
92
$ property ->setAccessible (true );
91
93
$ helper = new Client ($ config );
92
94
93
- $ stub = $ this ->getMock ('StdClass ' , array ('option ' , 'auth ' ));
95
+ $ stub = $ this ->getMockBuilder (stdClass::class)
96
+ ->setMethods (['option ' , 'auth ' ])
97
+ ->getMock ();
94
98
$ stub ->expects ($ this ->any ())
95
99
->method ('option ' )
96
100
->will ($ this ->returnValue (true ));
@@ -114,14 +118,16 @@ public function testRequest()
114
118
'consumerSecret ' => 'secret '
115
119
)
116
120
);
117
- $ reflection = new \ReflectionClass (' Upwork\API\Client ' );
121
+ $ reflection = new \ReflectionClass (\ Upwork \API \Client::class );
118
122
$ property = $ reflection ->getProperty ('_server ' );
119
123
$ property ->setAccessible (true );
120
124
$ method = $ reflection ->getMethod ('_request ' );
121
125
$ method ->setAccessible (true );
122
126
$ helper = new Client ($ config );
123
127
124
- $ stub = $ this ->getMock ('StdClass ' , array ('option ' , 'request ' ));
128
+ $ stub = $ this ->getMockBuilder (stdClass::class)
129
+ ->setMethods (['option ' , 'request ' ])
130
+ ->getMock ();
125
131
$ stub ->expects ($ this ->any ())
126
132
->method ('option ' )
127
133
->will ($ this ->returnValue (true ));
@@ -134,7 +140,7 @@ public function testRequest()
134
140
$ response = $ method ->invoke ($ helper , 'GET ' , 'http://www.upwork.com/api/auth/v1/info ' , array ());
135
141
$ this ->assertInstanceOf ('StdClass ' , $ response );
136
142
$ this ->assertObjectHasAttribute ('a ' , $ response );
137
- $ this ->assertInternalType ( ' string ' , $ response ->a );
143
+ $ this ->assertIsString ( $ response ->a );
138
144
$ this ->assertSame ('b ' , $ response ->a );
139
145
}
140
146
@@ -150,9 +156,21 @@ public function testRunMethod()
150
156
)
151
157
);
152
158
153
- $ stub = $ this ->getMock ('Upwork\API\Client ' , array ('_request ' ), array ($ config ));
159
+ $ stub = $ this ->getMockBuilder (\Upwork \API \Client::class)
160
+ ->enableArgumentCloning ()
161
+ ->setConstructorArgs ([$ config ])
162
+ ->getMock ();
154
163
$ stub ->expects ($ this ->any ())
155
- ->method ('_request ' )
164
+ ->method ('get ' )
165
+ ->will ($ this ->returnValue ('response ' ));
166
+ $ stub ->expects ($ this ->any ())
167
+ ->method ('post ' )
168
+ ->will ($ this ->returnValue ('response ' ));
169
+ $ stub ->expects ($ this ->any ())
170
+ ->method ('put ' )
171
+ ->will ($ this ->returnValue ('response ' ));
172
+ $ stub ->expects ($ this ->any ())
173
+ ->method ('delete ' )
156
174
->will ($ this ->returnValue ('response ' ));
157
175
158
176
foreach (array ('get ' , 'post ' , 'put ' , 'delete ' ) as $ method ) {
0 commit comments