Skip to content

Commit 88e5db1

Browse files
committed
test: Use assertSame for better type strictness
1 parent 4afc88a commit 88e5db1

8 files changed

Lines changed: 55 additions & 54 deletions

tests/AccessTokenTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ class AccessTokenTest extends TestCase
1515
public function testToString(): void
1616
{
1717
$token = new AccessToken;
18-
$this->assertEquals('', $token);
18+
$this->assertSame('', (string) $token);
1919

2020
$token->setToken('foobar');
21-
$this->assertEquals('foobar', $token);
21+
$this->assertSame('foobar', (string) $token);
2222
}
2323

2424
public function testConstructor(): void
2525
{
2626
$token = new AccessToken('foobar', 10);
2727
$this->assertInstanceOf('\DateTime', $token->getExpiresAt());
28-
$this->assertEquals('foobar', $token->getToken());
28+
$this->assertSame('foobar', $token->getToken());
2929

3030
$token = new AccessToken;
3131
$this->assertNull($token->getExpiresAt());

tests/AuthenticatorTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testGetLoginUrl(): void
5757
->shouldReceive('getUrl')->once()->with('www', 'oauth/v2/authorization', $params)->andReturn($expected)
5858
->getMock();
5959

60-
$this->assertEquals($expected, $auth->getLoginUrl($generator));
60+
$this->assertSame($expected, $auth->getLoginUrl($generator));
6161

6262
/*
6363
* Test with a url in the param
@@ -76,7 +76,7 @@ public function testGetLoginUrl(): void
7676
->shouldReceive('getUrl')->once()->with('www', 'oauth/v2/authorization', $params)->andReturn($expected)
7777
->getMock();
7878

79-
$this->assertEquals($expected, $auth->getLoginUrl($generator, ['redirect_uri' => $otherUrl, 'scope' => $scope]));
79+
$this->assertSame($expected, $auth->getLoginUrl($generator, ['redirect_uri' => $otherUrl, 'scope' => $scope]));
8080
}
8181

8282
public function testFetchNewAccessToken(): void
@@ -94,7 +94,7 @@ public function testFetchNewAccessToken(): void
9494
$auth->shouldReceive('getAccessTokenFromCode')->once()->with($generator, $code)->andReturn('at');
9595
$auth->shouldReceive('getCode')->once()->andReturn($code);
9696

97-
$this->assertEquals('at', $auth->fetchNewAccessToken($generator));
97+
$this->assertSame('at', $auth->fetchNewAccessToken($generator));
9898
}
9999

100100
public function testFetchNewAccessTokenFail(): void
@@ -128,7 +128,7 @@ public function testFetchNewAccessTokenNoCode(): void
128128
$auth->shouldReceive('getStorage')->andReturn($storage);
129129
$auth->shouldReceive('getCode')->once();
130130

131-
$this->assertEquals('baz', $auth->fetchNewAccessToken($generator));
131+
$this->assertSame('baz', $auth->fetchNewAccessToken($generator));
132132
}
133133

134134
public function testGetAccessTokenFromCodeEmptyString(): void
@@ -183,7 +183,7 @@ public function testGetAccessTokenFromCode(): void
183183
$response = ['access_token' => 'foobar', 'expires_in' => 10];
184184
$auth = $this->prepareGetAccessTokenFromCode($code, $response);
185185
$token = $method->invoke($auth, $generator, $code);
186-
$this->assertEquals('foobar', $token, 'Standard get access token form code');
186+
$this->assertSame('foobar', (string) $token, 'Standard get access token form code');
187187
}
188188

189189
public function testGetAccessTokenFromCodeNoTokenInResponse(): void
@@ -276,7 +276,7 @@ public function testGetCode(): void
276276
$_REQUEST['code'] = 'foobar';
277277
$_REQUEST['state'] = $state;
278278

279-
$this->assertEquals('foobar', $method->invoke($auth));
279+
$this->assertSame('foobar', $method->invoke($auth));
280280
}
281281

282282
public function testGetCodeInvalidCode(): void
@@ -297,7 +297,7 @@ public function testGetCodeInvalidCode(): void
297297
$_REQUEST['code'] = 'foobar';
298298
$_REQUEST['state'] = 'invalid';
299299

300-
$this->assertEquals('foobar', $method->invoke($auth));
300+
$this->assertSame('foobar', $method->invoke($auth));
301301
}
302302

303303
public function testGetCodeUsedCode(): void
@@ -315,7 +315,7 @@ public function testGetCodeUsedCode(): void
315315

316316
$_REQUEST['code'] = 'foobar';
317317

318-
$this->assertEquals(null, $method->invoke($auth));
318+
$this->assertSame(null, $method->invoke($auth));
319319
}
320320

321321
public function testStorageAccessors(): void
@@ -330,7 +330,7 @@ public function testStorageAccessors(): void
330330

331331
$object = Mockery::mock(DataStorageInterface::class);
332332
$auth->setStorage($object);
333-
$this->assertEquals($object, $method->invoke($auth));
333+
$this->assertSame($object, $method->invoke($auth));
334334
}
335335

336336
/**

tests/Exceptions/LoginErrorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testGetters(): void
1717
{
1818
$error = new LoginError('foo', 'bar');
1919

20-
$this->assertEquals('foo', $error->getName());
21-
$this->assertEquals('bar', $error->getDescription());
20+
$this->assertSame('foo', $error->getName());
21+
$this->assertSame('bar', $error->getDescription());
2222
}
2323
}

tests/Http/ResponseConverterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testConvert(): void
2727

2828
$result = ResponseConverter::convert($response, 'string');
2929
$this->assertTrue(is_string($result));
30-
$this->assertEquals($body, $result);
30+
$this->assertSame($body, $result);
3131

3232
$result = ResponseConverter::convert($response, 'array');
3333
$this->assertTrue(is_array($result));

tests/Http/UrlGeneratorTest.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,63 +30,63 @@ public function testDropLinkedInParams(): void
3030

3131
$test = 'foo=bar&code=foobar&baz=foo';
3232
$expected = '?foo=bar&baz=foo';
33-
$this->assertEquals($expected, $gen->dropLinkedInParams($test));
33+
$this->assertSame($expected, $gen->dropLinkedInParams($test));
3434

3535
$test = 'code=foobar&baz=foo';
3636
$expected = '?baz=foo';
37-
$this->assertEquals($expected, $gen->dropLinkedInParams($test));
37+
$this->assertSame($expected, $gen->dropLinkedInParams($test));
3838

3939
$test = 'foo=bar&code=foobar';
4040
$expected = '?foo=bar';
41-
$this->assertEquals($expected, $gen->dropLinkedInParams($test));
41+
$this->assertSame($expected, $gen->dropLinkedInParams($test));
4242

4343
$test = 'code=foobar';
4444
$expected = '';
45-
$this->assertEquals($expected, $gen->dropLinkedInParams($test));
45+
$this->assertSame($expected, $gen->dropLinkedInParams($test));
4646

4747
$test = '';
4848
$expected = '';
49-
$this->assertEquals($expected, $gen->dropLinkedInParams($test));
49+
$this->assertSame($expected, $gen->dropLinkedInParams($test));
5050

5151
/* ----------------- */
5252

5353
$test = 'foo=bar&code=';
5454
$expected = '?foo=bar';
55-
$this->assertEquals($expected, $gen->dropLinkedInParams($test));
55+
$this->assertSame($expected, $gen->dropLinkedInParams($test));
5656

5757
$test = 'code=';
5858
$expected = '';
59-
$this->assertEquals($expected, $gen->dropLinkedInParams($test));
59+
$this->assertSame($expected, $gen->dropLinkedInParams($test));
6060

6161
$test = 'foo=bar&code';
6262
$expected = '?foo=bar';
63-
$this->assertEquals($expected, $gen->dropLinkedInParams($test));
63+
$this->assertSame($expected, $gen->dropLinkedInParams($test));
6464

6565
$test = 'code';
6666
$expected = '';
67-
$this->assertEquals($expected, $gen->dropLinkedInParams($test));
67+
$this->assertSame($expected, $gen->dropLinkedInParams($test));
6868
}
6969

7070
public function testGetUrl(): void
7171
{
7272
$gen = new DummyUrlGenerator;
7373

7474
$expected = 'https://api.linkedin.com/?bar=baz';
75-
$this->assertEquals($expected, $gen->getUrl('api', '', ['bar' => 'baz']), 'No path');
75+
$this->assertSame($expected, $gen->getUrl('api', '', ['bar' => 'baz']), 'No path');
7676

7777
$expected = 'https://api.linkedin.com/foobar';
78-
$this->assertEquals($expected, $gen->getUrl('api', 'foobar'), 'Path does not begin with forward slash');
79-
$this->assertEquals($expected, $gen->getUrl('api', '/foobar'), 'Path begins with forward slash');
78+
$this->assertSame($expected, $gen->getUrl('api', 'foobar'), 'Path does not begin with forward slash');
79+
$this->assertSame($expected, $gen->getUrl('api', '/foobar'), 'Path begins with forward slash');
8080

8181
$expected = 'https://api.linkedin.com/foobar?bar=baz';
82-
$this->assertEquals($expected, $gen->getUrl('api', 'foobar', ['bar' => 'baz']), 'One parameter');
82+
$this->assertSame($expected, $gen->getUrl('api', 'foobar', ['bar' => 'baz']), 'One parameter');
8383

8484
$expected = 'https://api.linkedin.com/foobar?bar=baz&a=b&c=d';
85-
$this->assertEquals($expected, $gen->getUrl('api', 'foobar', ['bar' => 'baz', 'a' => 'b', 'c' => 'd']), 'Many parameters');
85+
$this->assertSame($expected, $gen->getUrl('api', 'foobar', ['bar' => 'baz', 'a' => 'b', 'c' => 'd']), 'Many parameters');
8686

8787
$expected = 'https://api.linkedin.com/foobar?bar=baz%20a%20b';
8888
$notExpected = 'https://api.linkedin.com/foobar?bar=baz+a+b';
89-
$this->assertEquals($expected, $gen->getUrl('api', 'foobar', ['bar' => 'baz a b']), 'Use of PHP_QUERY_RFC3986');
89+
$this->assertSame($expected, $gen->getUrl('api', 'foobar', ['bar' => 'baz a b']), 'Use of PHP_QUERY_RFC3986');
9090
$this->assertNotEquals($notExpected, $gen->getUrl('api', 'foobar', ['bar' => 'baz a b']), 'Dont use PHP_QUERY_RFC1738');
9191
}
9292

@@ -95,10 +95,10 @@ public function testGetUrlWithParams(): void
9595
$gen = new UrlGenerator;
9696

9797
$expected = 'https://api.linkedin.com/endpoint?bar=baz&format=json';
98-
$this->assertEquals($expected, $gen->getUrl('api', 'endpoint?bar=baz', ['format' => 'json']));
98+
$this->assertSame($expected, $gen->getUrl('api', 'endpoint?bar=baz', ['format' => 'json']));
9999

100100
$expected = 'https://api.linkedin.com/endpoint?bar=baz&bar=baz';
101-
$this->assertEquals($expected, $gen->getUrl('api', 'endpoint?bar=baz', ['bar' => 'baz']));
101+
$this->assertSame($expected, $gen->getUrl('api', 'endpoint?bar=baz', ['bar' => 'baz']));
102102
}
103103

104104
public function testGetCurrentURL(): void
@@ -114,7 +114,7 @@ public function testGetCurrentURL(): void
114114

115115
// fake the HPHP $_SERVER globals
116116
$_SERVER['REQUEST_URI'] = '/unit-tests.php?one=one&two=two&three=three';
117-
$this->assertEquals(
117+
$this->assertSame(
118118
'http://www.test.com/unit-tests.php?one=one&two=two&three=three',
119119
$gen->getCurrentUrl(),
120120
'getCurrentUrl function is changing the current URL',
@@ -124,15 +124,15 @@ public function testGetCurrentURL(): void
124124
// an = sign was present, and sometimes it was not)
125125
// first test when equal signs are present
126126
$_SERVER['REQUEST_URI'] = '/unit-tests.php?one=&two=&three=';
127-
$this->assertEquals(
127+
$this->assertSame(
128128
'http://www.test.com/unit-tests.php?one=&two=&three=',
129129
$gen->getCurrentUrl(),
130130
'getCurrentUrl function is changing the current URL',
131131
);
132132

133133
// now confirm that
134134
$_SERVER['REQUEST_URI'] = '/unit-tests.php?one&two&three';
135-
$this->assertEquals(
135+
$this->assertSame(
136136
'http://www.test.com/unit-tests.php?one&two&three',
137137
$gen->getCurrentUrl(),
138138
'getCurrentUrl function is changing the current URL',
@@ -152,7 +152,7 @@ public function testGetCurrentURLPort80(): void
152152

153153
// test port 80
154154
$_SERVER['REQUEST_URI'] = '/foobar.php';
155-
$this->assertEquals(
155+
$this->assertSame(
156156
'http://www.test.com/foobar.php',
157157
$gen->getCurrentUrl(),
158158
'port 80 should not be shown',
@@ -172,7 +172,7 @@ public function testGetCurrentURLPort8080(): void
172172

173173
// test non default port 8080
174174
$_SERVER['REQUEST_URI'] = '/foobar.php';
175-
$this->assertEquals(
175+
$this->assertSame(
176176
'http://www.test.com:8080/foobar.php',
177177
$gen->getCurrentUrl(),
178178
'port 80 should not be shown',
@@ -185,21 +185,21 @@ public function testHttpHost(): void
185185
$_SERVER['HTTP_HOST'] = $real;
186186
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'evil.com';
187187
$gen = new DummyUrlGenerator;
188-
$this->assertEquals($real, $gen->getHttpHost());
188+
$this->assertSame($real, $gen->getHttpHost());
189189
}
190190

191191
public function testHttpProtocolApache(): void
192192
{
193193
$_SERVER['HTTPS'] = 'on';
194194
$gen = new DummyUrlGenerator;
195-
$this->assertEquals('https', $gen->getHttpProtocol());
195+
$this->assertSame('https', $gen->getHttpProtocol());
196196
}
197197

198198
public function testHttpProtocolNginx(): void
199199
{
200200
$_SERVER['SERVER_PORT'] = '443';
201201
$gen = new DummyUrlGenerator;
202-
$this->assertEquals('https', $gen->getHttpProtocol());
202+
$this->assertSame('https', $gen->getHttpProtocol());
203203
}
204204

205205
public function testHttpHostForwarded(): void
@@ -209,7 +209,7 @@ public function testHttpHostForwarded(): void
209209
$_SERVER['HTTP_X_FORWARDED_HOST'] = $real;
210210
$gen = new DummyUrlGenerator;
211211
$gen->setTrustForwarded(true);
212-
$this->assertEquals($real, $gen->getHttpHost());
212+
$this->assertSame($real, $gen->getHttpHost());
213213
}
214214

215215
public function testHttpProtocolForwarded(): void
@@ -218,17 +218,17 @@ public function testHttpProtocolForwarded(): void
218218
$_SERVER['HTTP_X_FORWARDED_PROTO'] = 'http';
219219
$gen = new DummyUrlGenerator;
220220
$gen->setTrustForwarded(true);
221-
$this->assertEquals('http', $gen->getHttpProtocol());
221+
$this->assertSame('http', $gen->getHttpProtocol());
222222
}
223223

224224
public function testHttpProtocolForwardedSecure(): void
225225
{
226226
$_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
227227
$gen = new DummyUrlGenerator;
228-
$this->assertEquals('http', $gen->getHttpProtocol());
228+
$this->assertSame('http', $gen->getHttpProtocol());
229229

230230
$gen->setTrustForwarded(true);
231-
$this->assertEquals('https', $gen->getHttpProtocol());
231+
$this->assertSame('https', $gen->getHttpProtocol());
232232
}
233233
}
234234

tests/LinkedInTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#[UsesClass(GlobalVariableGetter::class)]
2727
#[UsesClass(ResponseConverter::class)]
2828
#[UsesClass(LoginError::class)]
29+
#[UsesClass(RequestManager::class)]
2930
class LinkedInTest extends MockeryTestCase
3031
{
3132
public const APP_ID = '123456789';
@@ -70,7 +71,7 @@ public function testApi(): void
7071
$linkedIn->shouldReceive('getRequestManager')->once()->andReturn($requestManager);
7172

7273
$result = $linkedIn->api($method, $resource, ['query' => $urlParams, 'json' => $postParams]);
73-
$this->assertEquals($expected, $result);
74+
$this->assertSame($expected, $result);
7475
}
7576

7677
public function testIsAuthenticated(): void
@@ -105,8 +106,8 @@ public function testAccessTokenAccessors(): void
105106
$linkedIn->shouldReceive('getAuthenticator')->once()->andReturn($auth);
106107

107108
// Make sure we go to the authenticator only once
108-
$this->assertEquals($token, $linkedIn->getAccessToken());
109-
$this->assertEquals($token, $linkedIn->getAccessToken());
109+
$this->assertSame($token, (string) $linkedIn->getAccessToken());
110+
$this->assertSame($token, (string) $linkedIn->getAccessToken());
110111
}
111112

112113
public function testGeneratorAccessors(): void
@@ -120,7 +121,7 @@ public function testGeneratorAccessors(): void
120121

121122
$object = Mockery::mock(UrlGenerator::class);
122123
$linkedIn->setUrlGenerator($object);
123-
$this->assertEquals($object, $get->invoke($linkedIn));
124+
$this->assertSame($object, $get->invoke($linkedIn));
124125
}
125126

126127
public function testHasError(): void
@@ -145,8 +146,8 @@ public function testGetError(): void
145146
$_GET['error'] = 'foo';
146147
$_GET['error_description'] = 'bar';
147148

148-
$this->assertEquals('foo', $linkedIn->getError()->getName());
149-
$this->assertEquals('bar', $linkedIn->getError()->getDescription());
149+
$this->assertSame('foo', $linkedIn->getError()->getName());
150+
$this->assertSame('bar', $linkedIn->getError()->getDescription());
150151
}
151152

152153
public function testGetErrorWithMissingDescription(): void
@@ -157,7 +158,7 @@ public function testGetErrorWithMissingDescription(): void
157158

158159
$_GET['error'] = 'foo';
159160

160-
$this->assertEquals('foo', $linkedIn->getError()->getName());
161+
$this->assertSame('foo', $linkedIn->getError()->getName());
161162
$this->assertNull($linkedIn->getError()->getDescription());
162163
}
163164

tests/Storage/IlluminateSessionStorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testGet(): void
4949
$expected = 'foobar';
5050
Session::shouldReceive('get')->once()->with($this->prefix . 'code')->andReturn($expected);
5151
$result = $this->storage->get('code');
52-
$this->assertEquals($expected, $result);
52+
$this->assertSame($expected, $result);
5353

5454
Session::shouldReceive('get')->once()->with($this->prefix . 'state')->andReturn(null);
5555
$result = $this->storage->get('state');

tests/Storage/SessionStorageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function setUp(): void
3333
public function testSet(): void
3434
{
3535
$this->storage->set('code', 'foobar');
36-
$this->assertEquals($_SESSION[$this->prefix . 'code'], 'foobar');
36+
$this->assertSame($_SESSION[$this->prefix . 'code'], 'foobar');
3737
}
3838

3939
public function testSetFail(): void
@@ -51,7 +51,7 @@ public function testGet(): void
5151
$expected = 'foobar';
5252
$_SESSION[$this->prefix . 'code'] = $expected;
5353
$result = $this->storage->get('code');
54-
$this->assertEquals($expected, $result);
54+
$this->assertSame($expected, $result);
5555
}
5656

5757
public function testClear(): void

0 commit comments

Comments
 (0)