Skip to content

Commit 0d09978

Browse files
authored
Apply rector PHPUnit assertion cleanups (#60807)
Runs AssertTrueFalseToSpecificMethodRector, AssertSameTrueFalseToAssertTrueFalseRector, ExpressionCreateMockToCreateStubRector, AssertSameBoolNullToSpecificMethodRector, AssertInstanceOfComparisonRector, and AssertNotOperatorRector, then drops the now-satisfied rules from rector.php.
1 parent 01abe68 commit 0d09978

31 files changed

Lines changed: 114 additions & 126 deletions

rector.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@
4747
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;
4848
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector;
4949
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector;
50-
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertInstanceOfComparisonRector;
5150
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertIssetToSpecificMethodRector;
52-
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertNotOperatorRector;
53-
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameBoolNullToSpecificMethodRector;
54-
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameTrueFalseToAssertTrueFalseRector;
55-
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector;
5651
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\ScalarArgumentToExpectedParamTypeRector;
5752
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\StringCastAssertStringContainsStringRector;
5853
use Rector\PHPUnit\CodeQuality\Rector\StmtsAwareInterface\DeclareStrictTypesTestsRector;
@@ -70,12 +65,7 @@
7065
AssertEmptyNullableObjectToAssertInstanceofRector::class,
7166
AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector::class,
7267
AssertEqualsToSameRector::class,
73-
AssertInstanceOfComparisonRector::class,
7468
AssertIssetToSpecificMethodRector::class,
75-
AssertNotOperatorRector::class,
76-
AssertSameBoolNullToSpecificMethodRector::class,
77-
AssertSameTrueFalseToAssertTrueFalseRector::class,
78-
AssertTrueFalseToSpecificMethodRector::class,
7969
CreateStubOverCreateMockArgRector::class,
8070
DataProviderArrayItemsNewLinedRector::class,
8171
DeclareStrictTypesTestsRector::class,

src/Illuminate/Foundation/Testing/Concerns/InteractsWithExceptionHandling.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ protected function assertDoesntThrow(Closure $test)
233233
$exceptionMessage = $exception->getMessage();
234234
}
235235

236-
Assert::assertTrue(
237-
! $thrown,
236+
Assert::assertFalse(
237+
$thrown,
238238
sprintf('Unexpected exception of type %s with message %s was thrown.', $exceptionClass ?? null, $exceptionMessage ?? null)
239239
);
240240

src/Illuminate/Queue/InteractsWithQueue.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ public function assertNotDeleted()
122122
{
123123
$this->ensureQueueInteractionsHaveBeenFaked();
124124

125-
PHPUnit::assertTrue(
126-
! $this->job->isDeleted(),
125+
PHPUnit::assertFalse(
126+
$this->job->isDeleted(),
127127
'Job was unexpectedly deleted.'
128128
);
129129

@@ -202,8 +202,8 @@ public function assertNotFailed()
202202
{
203203
$this->ensureQueueInteractionsHaveBeenFaked();
204204

205-
PHPUnit::assertTrue(
206-
! $this->job->hasFailed(),
205+
PHPUnit::assertFalse(
206+
$this->job->hasFailed(),
207207
'Job was unexpectedly failed manually.'
208208
);
209209

@@ -249,8 +249,8 @@ public function assertNotReleased()
249249
{
250250
$this->ensureQueueInteractionsHaveBeenFaked();
251251

252-
PHPUnit::assertTrue(
253-
! $this->job->isReleased(),
252+
PHPUnit::assertFalse(
253+
$this->job->isReleased(),
254254
'Job was unexpectedly released.'
255255
);
256256

src/Illuminate/Support/Testing/Fakes/ExceptionHandlerFake.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ public function assertReported(Closure|string $exception)
7171
);
7272

7373
if (is_string($exception)) {
74-
Assert::assertTrue(
75-
in_array($exception, array_map(get_class(...), $this->reported), true),
74+
Assert::assertContains(
75+
$exception,
76+
array_map(get_class(...), $this->reported),
7677
$message,
7778
);
7879

tests/Auth/AuthGuardTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function testAttemptReturnsUserInterface()
112112
});
113113
$events->shouldReceive('dispatch')->once()->with(m::type(Attempting::class));
114114
$events->shouldReceive('dispatch')->once()->with(m::type(Validated::class));
115-
$user = $this->createMock(Authenticatable::class);
115+
$user = $this->createStub(Authenticatable::class);
116116
$guard->getProvider()->shouldReceive('retrieveByCredentials')->once()->andReturn($user);
117117
$guard->getProvider()->shouldReceive('validateCredentials')->with($user, ['foo'])->andReturn(true);
118118
$guard->getProvider()->shouldReceive('rehashPasswordIfRequired')->with($user, ['foo'])->once();
@@ -192,7 +192,7 @@ public function testAttemptRehashesPasswordWhenRequired()
192192
});
193193
$events->shouldReceive('dispatch')->once()->with(m::type(Attempting::class));
194194
$events->shouldReceive('dispatch')->once()->with(m::type(Validated::class));
195-
$user = $this->createMock(Authenticatable::class);
195+
$user = $this->createStub(Authenticatable::class);
196196
$guard->getProvider()->shouldReceive('retrieveByCredentials')->once()->andReturn($user);
197197
$guard->getProvider()->shouldReceive('validateCredentials')->with($user, ['foo'])->andReturn(true);
198198
$guard->getProvider()->shouldReceive('rehashPasswordIfRequired')->with($user, ['foo'])->once();
@@ -212,7 +212,7 @@ public function testAttemptDoesntRehashPasswordWhenDisabled()
212212
});
213213
$events->shouldReceive('dispatch')->once()->with(m::type(Attempting::class));
214214
$events->shouldReceive('dispatch')->once()->with(m::type(Validated::class));
215-
$user = $this->createMock(Authenticatable::class);
215+
$user = $this->createStub(Authenticatable::class);
216216
$guard->getProvider()->shouldReceive('retrieveByCredentials')->once()->andReturn($user);
217217
$guard->getProvider()->shouldReceive('validateCredentials')->with($user, ['foo'])->andReturn(true);
218218
$guard->getProvider()->shouldNotReceive('rehashPasswordIfRequired');

tests/Cache/CacheRateLimiterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function testAttemptsCallbackReturnsCallbackReturn()
163163
return 'foo';
164164
}, 1));
165165

166-
$this->assertSame(false, $rateLimiter->attempt('key', 1, function () {
166+
$this->assertFalse($rateLimiter->attempt('key', 1, function () {
167167
return false;
168168
}, 1));
169169

tests/Cache/ConcurrencyLimiterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function () {
237237

238238
public function testFunnelThrowsExceptionWhenStoreDoesNotSupportLocks()
239239
{
240-
$store = $this->createMock(Store::class);
240+
$store = $this->createStub(Store::class);
241241
$repository = new Repository($store);
242242

243243
$this->assertNotInstanceOf(LockProvider::class, $store);

tests/Container/ContainerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public function testResolutionOfClassWithDefaultParameters()
327327
$container = new Container;
328328
$instance = $container->make(ContainerClassWithDefaultValueStub::class);
329329
$this->assertInstanceOf(ContainerConcreteStub::class, $instance->noDefault);
330-
$this->assertSame(null, $instance->default);
330+
$this->assertNull($instance->default);
331331

332332
$container->bind(ContainerConcreteStub::class, fn () => new ContainerConcreteStub);
333333
$instance = $container->make(ContainerClassWithDefaultValueStub::class);

tests/Database/DatabaseConnectionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public function testDisconnectClearsTransactionManagerState()
275275

276276
public function testBeganTransactionFiresEventsIfSet()
277277
{
278-
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
278+
$pdo = $this->createStub(DatabaseConnectionTestMockPDO::class);
279279
$connection = $this->getMockConnection(['getName'], $pdo);
280280
$connection->method('getName')->willReturn('name');
281281
$connection->setEventDispatcher($events = m::mock(Dispatcher::class));
@@ -285,7 +285,7 @@ public function testBeganTransactionFiresEventsIfSet()
285285

286286
public function testCommittedFiresEventsIfSet()
287287
{
288-
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
288+
$pdo = $this->createStub(DatabaseConnectionTestMockPDO::class);
289289
$connection = $this->getMockConnection(['getName'], $pdo);
290290
$connection->method('getName')->willReturn('name');
291291
$connection->setEventDispatcher($events = m::mock(Dispatcher::class));
@@ -295,7 +295,7 @@ public function testCommittedFiresEventsIfSet()
295295

296296
public function testCommittingFiresEventsIfSet()
297297
{
298-
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
298+
$pdo = $this->createStub(DatabaseConnectionTestMockPDO::class);
299299
$connection = $this->getMockConnection(['getName', 'transactionLevel'], $pdo);
300300
$connection->method('getName')->willReturn('name');
301301
$connection->method('transactionLevel')->willReturn(1);
@@ -307,7 +307,7 @@ public function testCommittingFiresEventsIfSet()
307307

308308
public function testRollBackedFiresEventsIfSet()
309309
{
310-
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
310+
$pdo = $this->createStub(DatabaseConnectionTestMockPDO::class);
311311
$connection = $this->getMockConnection(['getName'], $pdo);
312312
$connection->method('getName')->willReturn('name');
313313
$connection->beginTransaction();
@@ -318,7 +318,7 @@ public function testRollBackedFiresEventsIfSet()
318318

319319
public function testRedundantRollBackFiresNoEvent()
320320
{
321-
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
321+
$pdo = $this->createStub(DatabaseConnectionTestMockPDO::class);
322322
$connection = $this->getMockConnection(['getName'], $pdo);
323323
$connection->method('getName')->willReturn('name');
324324
$connection->setEventDispatcher($events = m::mock(Dispatcher::class));
@@ -450,7 +450,7 @@ public function testRunMethodRetriesOnFailure()
450450
{
451451
$method = (new ReflectionClass(Connection::class))->getMethod('run');
452452

453-
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
453+
$pdo = $this->createStub(DatabaseConnectionTestMockPDO::class);
454454
$mock = $this->getMockConnection(['tryAgainIfCausedByLostConnection'], $pdo);
455455
$mock->expects($this->once())->method('tryAgainIfCausedByLostConnection');
456456

tests/Database/DatabaseEloquentCollectionTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public function testMappingToNonModelsReturnsABaseCollection()
355355
return 'not-a-model';
356356
});
357357

358-
$this->assertEquals(BaseCollection::class, get_class($c));
358+
$this->assertInstanceOf(BaseCollection::class, $c);
359359
}
360360

361361
public function testMapWithKeys()
@@ -384,7 +384,7 @@ public function testMapWithKeysToNonModelsReturnsABaseCollection()
384384
return [$key++ => 'not-a-model'];
385385
});
386386

387-
$this->assertEquals(BaseCollection::class, get_class($c));
387+
$this->assertInstanceOf(BaseCollection::class, $c);
388388
}
389389

390390
public function testCollectionDiffsWithGivenCollection()
@@ -612,15 +612,15 @@ public function testNonModelRelatedMethods()
612612
{
613613
$a = new Collection([['foo' => 'bar'], ['foo' => 'baz']]);
614614
$b = new Collection(['a', 'b', 'c']);
615-
$this->assertEquals(BaseCollection::class, get_class($a->pluck('foo')));
616-
$this->assertEquals(BaseCollection::class, get_class($a->keys()));
617-
$this->assertEquals(BaseCollection::class, get_class($a->collapse()));
618-
$this->assertEquals(BaseCollection::class, get_class($a->flatten()));
619-
$this->assertEquals(BaseCollection::class, get_class($a->zip(['a', 'b'], ['c', 'd'])));
620-
$this->assertEquals(BaseCollection::class, get_class($a->countBy('foo')));
621-
$this->assertEquals(BaseCollection::class, get_class($b->flip()));
622-
$this->assertEquals(BaseCollection::class, get_class($a->partition('foo', '=', 'bar')));
623-
$this->assertEquals(BaseCollection::class, get_class($a->partition('foo', 'bar')));
615+
$this->assertInstanceOf(BaseCollection::class, $a->pluck('foo'));
616+
$this->assertInstanceOf(BaseCollection::class, $a->keys());
617+
$this->assertInstanceOf(BaseCollection::class, $a->collapse());
618+
$this->assertInstanceOf(BaseCollection::class, $a->flatten());
619+
$this->assertInstanceOf(BaseCollection::class, $a->zip(['a', 'b'], ['c', 'd']));
620+
$this->assertInstanceOf(BaseCollection::class, $a->countBy('foo'));
621+
$this->assertInstanceOf(BaseCollection::class, $b->flip());
622+
$this->assertInstanceOf(BaseCollection::class, $a->partition('foo', '=', 'bar'));
623+
$this->assertInstanceOf(BaseCollection::class, $a->partition('foo', 'bar'));
624624
}
625625

626626
public function testMakeVisibleRemovesHiddenAndIncludesVisible()

0 commit comments

Comments
 (0)