Skip to content

Commit bc91991

Browse files
committed
[Testing] Use assertEqualsWithDelta() when possible
1 parent 1c33359 commit bc91991

File tree

8 files changed

+22
-22
lines changed

8 files changed

+22
-22
lines changed

tests/system/Config/BaseConfigTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testUseDefaultValueTypeIntAndFloatValues(): void
8080
$dotenv->load();
8181
$config = new SimpleConfig();
8282

83-
$this->assertSame(0.0, $config->float);
83+
$this->assertEqualsWithDelta(0.0, $config->float, PHP_FLOAT_EPSILON);
8484
$this->assertSame(999, $config->int);
8585
}
8686

tests/system/Database/Live/SelectTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ public function testSelectAvg(): void
8686
{
8787
$result = $this->db->table('job')->selectAvg('id')->get()->getRow();
8888

89-
$this->assertSame(2.5, (float) $result->id);
89+
$this->assertEqualsWithDelta(2.5, (float) $result->id, PHP_FLOAT_EPSILON);
9090
}
9191

9292
public function testSelectAvgWithAlias(): void
9393
{
9494
$result = $this->db->table('job')->selectAvg('id', 'xam')->get()->getRow();
9595

96-
$this->assertSame(2.5, (float) $result->xam);
96+
$this->assertEqualsWithDelta(2.5, (float) $result->xam, PHP_FLOAT_EPSILON);
9797
}
9898

9999
public function testSelectSum(): void

tests/system/Entity/EntityTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,12 @@ public function testCastFloat(): void
373373
$entity->second = 3;
374374

375375
$this->assertIsFloat($entity->second);
376-
$this->assertSame(3.0, $entity->second);
376+
$this->assertEqualsWithDelta(3.0, $entity->second, PHP_FLOAT_EPSILON);
377377

378378
$entity->second = '3.6';
379379

380380
$this->assertIsFloat($entity->second);
381-
$this->assertSame(3.6, $entity->second);
381+
$this->assertEqualsWithDelta(3.6, $entity->second, PHP_FLOAT_EPSILON);
382382
}
383383

384384
public function testCastDouble(): void
@@ -388,12 +388,12 @@ public function testCastDouble(): void
388388
$entity->third = 3;
389389

390390
$this->assertIsFloat($entity->third);
391-
$this->assertSame(3.0, $entity->third);
391+
$this->assertEqualsWithDelta(3.0, $entity->third, PHP_FLOAT_EPSILON);
392392

393393
$entity->third = '3.6';
394394

395395
$this->assertIsFloat($entity->third);
396-
$this->assertSame(3.6, $entity->third);
396+
$this->assertEqualsWithDelta(3.6, $entity->third, PHP_FLOAT_EPSILON);
397397
}
398398

399399
public function testCastString(): void

tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ public function testHeaderContentLengthNotSharedBetweenClients(): void
267267
public function testOptionsDelay(): void
268268
{
269269
$request = $this->getRequest();
270-
$this->assertSame(0.0, $request->getDelay());
270+
$this->assertEqualsWithDelta(0.0, $request->getDelay(), PHP_FLOAT_EPSILON);
271271

272272
$options = [
273273
'delay' => 2000,
274274
'headers' => ['fruit' => 'apple'],
275275
];
276276
$request = $this->getRequest($options);
277-
$this->assertSame(2.0, $request->getDelay());
277+
$this->assertEqualsWithDelta(2.0, $request->getDelay(), PHP_FLOAT_EPSILON);
278278
}
279279

280280
public function testPatchSetsCorrectMethod(): void
@@ -356,10 +356,10 @@ public function testRequestSetsBasicCurlOptions(): void
356356
$this->assertTrue($options[CURLOPT_FRESH_CONNECT]);
357357

358358
$this->assertArrayHasKey(CURLOPT_TIMEOUT_MS, $options);
359-
$this->assertSame(0.0, $options[CURLOPT_TIMEOUT_MS]);
359+
$this->assertEqualsWithDelta(0.0, $options[CURLOPT_TIMEOUT_MS], PHP_FLOAT_EPSILON);
360360

361361
$this->assertArrayHasKey(CURLOPT_CONNECTTIMEOUT_MS, $options);
362-
$this->assertSame(150000.0, $options[CURLOPT_CONNECTTIMEOUT_MS]);
362+
$this->assertEqualsWithDelta(150000.0, $options[CURLOPT_CONNECTTIMEOUT_MS], PHP_FLOAT_EPSILON);
363363
}
364364

365365
public function testAuthBasicOption(): void
@@ -734,7 +734,7 @@ public function testSendWithDelay(): void
734734
$request->get('products');
735735

736736
// we still need to check the code coverage to make sure this was done
737-
$this->assertSame(0.1, $request->getDelay());
737+
$this->assertEqualsWithDelta(0.1, $request->getDelay(), PHP_FLOAT_EPSILON);
738738
}
739739

740740
public function testSendContinued(): void

tests/system/HTTP/CURLRequestTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ public function testHeaderContentLengthNotSharedBetweenClients(): void
250250
public function testOptionsDelay(): void
251251
{
252252
$request = $this->getRequest();
253-
$this->assertSame(0.0, $request->getDelay());
253+
$this->assertEqualsWithDelta(0.0, $request->getDelay(), PHP_FLOAT_EPSILON);
254254

255255
$options = [
256256
'delay' => 2000,
257257
'headers' => ['fruit' => 'apple'],
258258
];
259259
$request = $this->getRequest($options);
260-
$this->assertSame(2.0, $request->getDelay());
260+
$this->assertEqualsWithDelta(2.0, $request->getDelay(), PHP_FLOAT_EPSILON);
261261
}
262262

263263
public function testPatchSetsCorrectMethod(): void
@@ -339,10 +339,10 @@ public function testRequestSetsBasicCurlOptions(): void
339339
$this->assertTrue($options[CURLOPT_FRESH_CONNECT]);
340340

341341
$this->assertArrayHasKey(CURLOPT_TIMEOUT_MS, $options);
342-
$this->assertSame(0.0, $options[CURLOPT_TIMEOUT_MS]);
342+
$this->assertEqualsWithDelta(0.0, $options[CURLOPT_TIMEOUT_MS], PHP_FLOAT_EPSILON);
343343

344344
$this->assertArrayHasKey(CURLOPT_CONNECTTIMEOUT_MS, $options);
345-
$this->assertSame(150000.0, $options[CURLOPT_CONNECTTIMEOUT_MS]);
345+
$this->assertEqualsWithDelta(150000.0, $options[CURLOPT_CONNECTTIMEOUT_MS], PHP_FLOAT_EPSILON);
346346
}
347347

348348
public function testAuthBasicOption(): void
@@ -717,7 +717,7 @@ public function testSendWithDelay(): void
717717
$request->get('products');
718718

719719
// we still need to check the code coverage to make sure this was done
720-
$this->assertSame(0.1, $request->getDelay());
720+
$this->assertEqualsWithDelta(0.1, $request->getDelay(), PHP_FLOAT_EPSILON);
721721
}
722722

723723
public function testSendContinued(): void

tests/system/HTTP/IncomingRequestTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public function testCanGetAVariableFromJson(): void
348348
$this->assertSame('buzz', $jsonVar->fizz);
349349
$this->assertSame('buzz', $request->getJsonVar('baz.fizz'));
350350
$this->assertSame(123, $request->getJsonVar('int'));
351-
$this->assertSame(3.14, $request->getJsonVar('float'));
351+
$this->assertEqualsWithDelta(3.14, $request->getJsonVar('float'), PHP_FLOAT_EPSILON);
352352
$this->assertTrue($request->getJsonVar('true'));
353353
$this->assertFalse($request->getJsonVar('false'));
354354
$this->assertNull($request->getJsonVar('null'));
@@ -379,7 +379,7 @@ public function testGetJsonVarAsArray(): void
379379
$this->assertSame('buzz', $jsonVar['fizz']);
380380
$this->assertSame('bar', $jsonVar['foo']);
381381
$this->assertSame(123, $jsonVar['int']);
382-
$this->assertSame(3.14, $jsonVar['float']);
382+
$this->assertEqualsWithDelta(3.14, $jsonVar['float'], PHP_FLOAT_EPSILON);
383383
$this->assertTrue($jsonVar['true']);
384384
$this->assertFalse($jsonVar['false']);
385385
$this->assertNull($jsonVar['null']);

tests/system/Session/Handlers/Database/RedisHandlerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testSavePathTimeoutFloat(): void
9393

9494
$savePath = $this->getPrivateProperty($handler, 'savePath');
9595

96-
$this->assertSame(2.5, $savePath['timeout']);
96+
$this->assertEqualsWithDelta(2.5, $savePath['timeout'], PHP_FLOAT_EPSILON);
9797
}
9898

9999
public function testSavePathTimeoutInt(): void
@@ -104,7 +104,7 @@ public function testSavePathTimeoutInt(): void
104104

105105
$savePath = $this->getPrivateProperty($handler, 'savePath');
106106

107-
$this->assertSame(10.0, $savePath['timeout']);
107+
$this->assertEqualsWithDelta(10.0, $savePath['timeout'], PHP_FLOAT_EPSILON);
108108
}
109109

110110
public function testOpen(): void

tests/system/Throttle/ThrottleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function testFlooding(): void
185185
$throttler = $throttler->setTestTime($time + 10);
186186

187187
$this->assertTrue($throttler->check('127.0.0.1', $rate, MINUTE, 0));
188-
$this->assertSame(10.0, round($this->cache->get('throttler_127.0.0.1')));
188+
$this->assertEqualsWithDelta(10.0, round($this->cache->get('throttler_127.0.0.1')), PHP_FLOAT_EPSILON);
189189
}
190190

191191
/**

0 commit comments

Comments
 (0)