Skip to content

Commit 08c7ba6

Browse files
authored
chore(tests): use assertSame for strict equals (#478)
1 parent 213924f commit 08c7ba6

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

tests/CachedKeySetTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testWithExistingKeyId()
9393
$this->getMockEmptyCache()
9494
);
9595
$this->assertInstanceOf(Key::class, $cachedKeySet['foo']);
96-
$this->assertEquals('foo', $cachedKeySet['foo']->getAlgorithm());
96+
$this->assertSame('foo', $cachedKeySet['foo']->getAlgorithm());
9797
}
9898

9999
public function testWithDefaultAlg()
@@ -108,7 +108,7 @@ public function testWithDefaultAlg()
108108
'baz256'
109109
);
110110
$this->assertInstanceOf(Key::class, $cachedKeySet['baz']);
111-
$this->assertEquals('baz256', $cachedKeySet['baz']->getAlgorithm());
111+
$this->assertSame('baz256', $cachedKeySet['baz']->getAlgorithm());
112112
}
113113

114114
public function testKeyIdIsCached()
@@ -132,7 +132,7 @@ public function testKeyIdIsCached()
132132
$cache->reveal()
133133
);
134134
$this->assertInstanceOf(Key::class, $cachedKeySet['foo']);
135-
$this->assertEquals('foo', $cachedKeySet['foo']->getAlgorithm());
135+
$this->assertSame('foo', $cachedKeySet['foo']->getAlgorithm());
136136
}
137137

138138
public function testCachedKeyIdRefresh()
@@ -165,10 +165,10 @@ public function testCachedKeyIdRefresh()
165165
$cache->reveal()
166166
);
167167
$this->assertInstanceOf(Key::class, $cachedKeySet['foo']);
168-
$this->assertEquals('foo', $cachedKeySet['foo']->getAlgorithm());
168+
$this->assertSame('foo', $cachedKeySet['foo']->getAlgorithm());
169169

170170
$this->assertInstanceOf(Key::class, $cachedKeySet['bar']);
171-
$this->assertEquals('bar', $cachedKeySet['bar']->getAlgorithm());
171+
$this->assertSame('bar', $cachedKeySet['bar']->getAlgorithm());
172172
}
173173

174174
public function testCacheItemWithExpiresAfter()
@@ -204,7 +204,7 @@ public function testCacheItemWithExpiresAfter()
204204
$expiresAfter
205205
);
206206
$this->assertInstanceOf(Key::class, $cachedKeySet['foo']);
207-
$this->assertEquals('foo', $cachedKeySet['foo']->getAlgorithm());
207+
$this->assertSame('foo', $cachedKeySet['foo']->getAlgorithm());
208208
}
209209

210210
public function testJwtVerify()
@@ -233,7 +233,7 @@ public function testJwtVerify()
233233

234234
$result = JWT::decode($msg, $cachedKeySet);
235235

236-
$this->assertEquals('foo', $result->sub);
236+
$this->assertSame('foo', $result->sub);
237237
}
238238

239239
public function testRateLimit()
@@ -290,7 +290,7 @@ public function testFullIntegration(string $jwkUri): void
290290
$this->assertArrayHasKey($kid, $cachedKeySet);
291291
$key = $cachedKeySet[$kid];
292292
$this->assertInstanceOf(Key::class, $key);
293-
$this->assertEquals($keys['keys'][0]['alg'], $key->getAlgorithm());
293+
$this->assertSame($keys['keys'][0]['alg'], $key->getAlgorithm());
294294
}
295295

296296
public function provideFullIntegration()

tests/JWKTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testParsePrivateKeyWithoutAlgWithDefaultAlgParameter()
6767
unset($jwkSet['keys'][0]['alg']);
6868

6969
$jwks = JWK::parseKeySet($jwkSet, 'foo');
70-
$this->assertEquals('foo', $jwks['jwk1']->getAlgorithm());
70+
$this->assertSame('foo', $jwks['jwk1']->getAlgorithm());
7171
}
7272

7373
public function testParseKeyWithEmptyDValue()
@@ -143,7 +143,7 @@ public function testDecodeByJwkKeySet($pemFile, $jwkFile, $alg)
143143
$keys = JWK::parseKeySet($jwkSet);
144144
$result = JWT::decode($msg, $keys);
145145

146-
$this->assertEquals('foo', $result->sub);
146+
$this->assertSame('foo', $result->sub);
147147
}
148148

149149
public function provideDecodeByJwkKeySet()
@@ -165,6 +165,6 @@ public function testDecodeByMultiJwkKeySet()
165165

166166
$result = JWT::decode($msg, self::$keys);
167167

168-
$this->assertEquals('bar', $result->sub);
168+
$this->assertSame('bar', $result->sub);
169169
}
170170
}

tests/JWTTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testValidToken()
7373
];
7474
$encoded = JWT::encode($payload, 'my_key', 'HS256');
7575
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
76-
$this->assertEquals($decoded->message, 'abc');
76+
$this->assertSame($decoded->message, 'abc');
7777
}
7878

7979
public function testValidTokenWithLeeway()
@@ -85,7 +85,7 @@ public function testValidTokenWithLeeway()
8585
];
8686
$encoded = JWT::encode($payload, 'my_key', 'HS256');
8787
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
88-
$this->assertEquals($decoded->message, 'abc');
88+
$this->assertSame($decoded->message, 'abc');
8989
JWT::$leeway = 0;
9090
}
9191

@@ -99,7 +99,7 @@ public function testExpiredTokenWithLeeway()
9999
$this->expectException(ExpiredException::class);
100100
$encoded = JWT::encode($payload, 'my_key', 'HS256');
101101
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
102-
$this->assertEquals($decoded->message, 'abc');
102+
$this->assertSame($decoded->message, 'abc');
103103
JWT::$leeway = 0;
104104
}
105105

@@ -113,7 +113,7 @@ public function testValidTokenWithNbf()
113113
];
114114
$encoded = JWT::encode($payload, 'my_key', 'HS256');
115115
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
116-
$this->assertEquals($decoded->message, 'abc');
116+
$this->assertSame($decoded->message, 'abc');
117117
}
118118

119119
public function testValidTokenWithNbfLeeway()
@@ -125,7 +125,7 @@ public function testValidTokenWithNbfLeeway()
125125
];
126126
$encoded = JWT::encode($payload, 'my_key', 'HS256');
127127
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
128-
$this->assertEquals($decoded->message, 'abc');
128+
$this->assertSame($decoded->message, 'abc');
129129
JWT::$leeway = 0;
130130
}
131131

@@ -151,7 +151,7 @@ public function testValidTokenWithIatLeeway()
151151
];
152152
$encoded = JWT::encode($payload, 'my_key', 'HS256');
153153
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
154-
$this->assertEquals($decoded->message, 'abc');
154+
$this->assertSame($decoded->message, 'abc');
155155
JWT::$leeway = 0;
156156
}
157157

@@ -301,7 +301,7 @@ public function testEdDsaEncodeDecode()
301301

302302
$pubKey = base64_encode(sodium_crypto_sign_publickey($keyPair));
303303
$decoded = JWT::decode($msg, new Key($pubKey, 'EdDSA'));
304-
$this->assertEquals('bar', $decoded->foo);
304+
$this->assertSame('bar', $decoded->foo);
305305
}
306306

307307
public function testInvalidEdDsaEncodeDecode()
@@ -350,7 +350,7 @@ public function testDecodesArraysInJWTAsArray()
350350
$payload = ['foo' => [1, 2, 3]];
351351
$jwt = JWT::encode($payload, $key, 'HS256');
352352
$decoded = JWT::decode($jwt, new Key($key, 'HS256'));
353-
$this->assertEquals($payload['foo'], $decoded->foo);
353+
$this->assertSame($payload['foo'], $decoded->foo);
354354
}
355355

356356
/**
@@ -367,7 +367,7 @@ public function testEncodeDecode($privateKeyFile, $publicKeyFile, $alg)
367367
$publicKey = file_get_contents($publicKeyFile);
368368
$decoded = JWT::decode($encoded, new Key($publicKey, $alg));
369369

370-
$this->assertEquals('bar', $decoded->foo);
370+
$this->assertSame('bar', $decoded->foo);
371371
}
372372

373373
public function provideEncodeDecode()
@@ -393,6 +393,6 @@ public function testEncodeDecodeWithResource()
393393
// Verify decoding succeeds
394394
$decoded = JWT::decode($encoded, new Key($resource, 'RS512'));
395395

396-
$this->assertEquals('bar', $decoded->foo);
396+
$this->assertSame('bar', $decoded->foo);
397397
}
398398
}

0 commit comments

Comments
 (0)