Skip to content

Commit 9522b1f

Browse files
author
Lucas Michot
authored
Use proper tests assertions (#36653)
1 parent 74c9365 commit 9522b1f

8 files changed

+20
-19
lines changed

tests/Bus/BusBatchTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function test_jobs_can_be_added_to_the_batch()
113113

114114
$this->assertEquals(3, $batch->totalJobs);
115115
$this->assertEquals(3, $batch->pendingJobs);
116-
$this->assertTrue(is_string($job->batchId));
116+
$this->assertIsString($job->batchId);
117117
$this->assertInstanceOf(CarbonImmutable::class, $batch->createdAt);
118118
}
119119

@@ -301,7 +301,7 @@ public function test_batch_state_can_be_inspected()
301301
$batch->cancelledAt = now();
302302
$this->assertTrue($batch->cancelled());
303303

304-
$this->assertTrue(is_string(json_encode($batch)));
304+
$this->assertIsString(json_encode($batch));
305305
}
306306

307307
public function test_chain_can_be_added_to_batch()
@@ -334,9 +334,9 @@ public function test_chain_can_be_added_to_batch()
334334
$this->assertEquals(3, $batch->totalJobs);
335335
$this->assertEquals(3, $batch->pendingJobs);
336336
$this->assertSame('test-queue', $chainHeadJob->chainQueue);
337-
$this->assertTrue(is_string($chainHeadJob->batchId));
338-
$this->assertTrue(is_string($secondJob->batchId));
339-
$this->assertTrue(is_string($thirdJob->batchId));
337+
$this->assertIsString($chainHeadJob->batchId);
338+
$this->assertIsString($secondJob->batchId);
339+
$this->assertIsString($thirdJob->batchId);
340340
$this->assertInstanceOf(CarbonImmutable::class, $batch->createdAt);
341341
}
342342

tests/Database/DatabaseEloquentIntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,12 +811,12 @@ public function testBelongsToManyRelationshipModelsAreProperlyHydratedWithSoleQu
811811
$user->friends()->create(['email' => '[email protected]']);
812812

813813
$user->friends()->get()->each(function ($friend) {
814-
$this->assertTrue($friend->pivot instanceof EloquentTestFriendPivot);
814+
$this->assertInstanceOf(EloquentTestFriendPivot::class, $friend->pivot);
815815
});
816816

817817
$soleFriend = $user->friends()->where('email', '[email protected]')->sole();
818818

819-
$this->assertTrue($soleFriend->pivot instanceof EloquentTestFriendPivot);
819+
$this->assertInstanceOf(EloquentTestFriendPivot::class, $soleFriend->pivot);
820820
}
821821

822822
public function testBelongsToManyRelationshipMissingModelExceptionWithSoleQueryWorks()

tests/Http/HttpRequestTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ public function testMagicMethods()
10241024
// Parameter 'foo' is 'bar', then it ISSET and is NOT EMPTY.
10251025
$this->assertSame('bar', $request->foo);
10261026
$this->assertTrue(isset($request->foo));
1027-
$this->assertFalse(empty($request->foo));
1027+
$this->assertNotEmpty($request->foo);
10281028

10291029
// Parameter 'empty' is '', then it ISSET and is EMPTY.
10301030
$this->assertSame('', $request->empty);
@@ -1034,7 +1034,7 @@ public function testMagicMethods()
10341034
// Parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY.
10351035
$this->assertNull($request->undefined);
10361036
$this->assertFalse(isset($request->undefined));
1037-
$this->assertTrue(empty($request->undefined));
1037+
$this->assertEmpty($request->undefined);
10381038

10391039
// Simulates Route parameters.
10401040
$request = Request::create('/example/bar', 'GET', ['xyz' => 'overwritten']);
@@ -1049,18 +1049,18 @@ public function testMagicMethods()
10491049
$this->assertSame('bar', $request->foo);
10501050
$this->assertSame('bar', $request['foo']);
10511051
$this->assertTrue(isset($request->foo));
1052-
$this->assertFalse(empty($request->foo));
1052+
$this->assertNotEmpty($request->foo);
10531053

10541054
// Router parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY.
10551055
$this->assertNull($request->undefined);
10561056
$this->assertFalse(isset($request->undefined));
1057-
$this->assertTrue(empty($request->undefined));
1057+
$this->assertEmpty($request->undefined);
10581058

10591059
// Special case: router parameter 'xyz' is 'overwritten' by QueryString, then it ISSET and is NOT EMPTY.
10601060
// Basically, QueryStrings have priority over router parameters.
10611061
$this->assertSame('overwritten', $request->xyz);
10621062
$this->assertTrue(isset($request->foo));
1063-
$this->assertFalse(empty($request->foo));
1063+
$this->assertNotEmpty($request->foo);
10641064

10651065
// Simulates empty QueryString and Routes.
10661066
$request = Request::create('/', 'GET');
@@ -1074,7 +1074,7 @@ public function testMagicMethods()
10741074
// Parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY.
10751075
$this->assertNull($request->undefined);
10761076
$this->assertFalse(isset($request->undefined));
1077-
$this->assertTrue(empty($request->undefined));
1077+
$this->assertEmpty($request->undefined);
10781078

10791079
// Special case: simulates empty QueryString and Routes, without the Route Resolver.
10801080
// It'll happen when you try to get a parameter outside a route.
@@ -1083,7 +1083,7 @@ public function testMagicMethods()
10831083
// Parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY.
10841084
$this->assertNull($request->undefined);
10851085
$this->assertFalse(isset($request->undefined));
1086-
$this->assertTrue(empty($request->undefined));
1086+
$this->assertEmpty($request->undefined);
10871087
}
10881088

10891089
public function testHttpRequestFlashCallsSessionFlashInputWithInputData()

tests/Integration/Database/DatabaseEloquentModelCustomCastingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function testBasicCustomCasting()
106106

107107
$model = new TestEloquentModelWithCustomCast;
108108
$model->birthday_at = now();
109-
$this->assertTrue(is_string($model->toArray()['birthday_at']));
109+
$this->assertIsString($model->toArray()['birthday_at']);
110110
}
111111

112112
public function testGetOriginalWithCastValueObjects()

tests/Integration/Database/DatabaseSchemaBuilderAlterTableWithEnumTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Schema\Blueprint;
66
use Illuminate\Support\Facades\Schema;
7+
use stdClass;
78

89
class DatabaseSchemaBuilderAlterTableWithEnumTest extends DatabaseMySqlTestCase
910
{
@@ -30,7 +31,7 @@ public function testGetAllTablesAndColumnListing()
3031
$tables = Schema::getAllTables();
3132

3233
$this->assertCount(1, $tables);
33-
$this->assertSame('stdClass', get_class($tables[0]));
34+
$this->assertInstanceOf(stdClass::class, $tables[0]);
3435

3536
$tableProperties = array_values((array) $tables[0]);
3637
$this->assertEquals(['users', 'BASE TABLE'], $tableProperties);

tests/Integration/Http/ResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ public function testCollectionResourcesAreCountable()
781781
$collection = new PostCollectionResource($posts);
782782

783783
$this->assertCount(2, $collection);
784-
$this->assertSame(2, count($collection));
784+
$this->assertCount(2, $collection);
785785
}
786786

787787
public function testKeysArePreservedIfTheResourceIsFlaggedToPreserveKeys()

tests/Validation/ValidationAddFailureTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testAddFailureExists()
2525
$validator = $this->makeValidator();
2626
$method_name = 'addFailure';
2727
$this->assertTrue(method_exists($validator, $method_name));
28-
$this->assertTrue(is_callable([$validator, $method_name]));
28+
$this->assertIsCallable([$validator, $method_name]);
2929
}
3030

3131
public function testAddFailureIsFunctional()

tests/Validation/ValidationValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5238,7 +5238,7 @@ public function message()
52385238
);
52395239

52405240
$this->assertFalse($v->passes());
5241-
$this->assertTrue(is_array($v->failed()['foo.foo.bar']));
5241+
$this->assertIsArray($v->failed()['foo.foo.bar']);
52425242
}
52435243

52445244
public function testImplicitCustomValidationObjects()

0 commit comments

Comments
 (0)