Skip to content

Commit

Permalink
Merge pull request #9440 from samsonasik/refactor-assert-not
Browse files Browse the repository at this point in the history
refactor: use assertNotInstanceOf over assertNull on nullable object return and flip actual/expect on constant check
  • Loading branch information
samsonasik authored Feb 4, 2025
2 parents 74a7861 + 3eae990 commit e89ef62
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions tests/system/Cache/ResponseCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function testCachePageIncomingRequest(): void

$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertNull($cachedResponse);
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);
}

public function testCachePageIncomingRequestWithCacheQueryString(): void
Expand Down Expand Up @@ -159,14 +159,14 @@ public function testCachePageIncomingRequestWithCacheQueryString(): void
$request = $this->createIncomingRequest('foo/bar', ['xfoo' => 'bar', 'bar' => 'baz']);
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertNull($cachedResponse);
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);

// Check cache with another request with the different URI path.
$request = $this->createIncomingRequest('another');

$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertNull($cachedResponse);
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);
}

public function testCachePageIncomingRequestWithHttpMethods(): void
Expand All @@ -186,7 +186,7 @@ public function testCachePageIncomingRequestWithHttpMethods(): void
$request = $this->createIncomingRequest('foo/bar')->withMethod('POST');
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertNull($cachedResponse);
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);
}

public function testCachePageCLIRequest(): void
Expand Down Expand Up @@ -214,7 +214,7 @@ public function testCachePageCLIRequest(): void

$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertNull($cachedResponse);
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);
}

public function testUnserializeError(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Filters/CorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testBeforeDoesNothingWhenCliRequest(): void

$return = $this->cors->before($cliRequest);

$this->assertNull($return);
$this->assertNotInstanceOf(ResponseInterface::class, $return);
}

private function assertHeader(string $name, string $value): void
Expand Down
4 changes: 2 additions & 2 deletions tests/system/HTTP/Files/FileCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public function testFileNoExistSingleFile(): void

$collection = new FileCollection();
$file = $collection->getFile('fileuser');
$this->assertNull($file);
$this->assertNotInstanceOf(UploadedFile::class, $file);
}

public function testFileReturnValidMultipleFiles(): void
Expand Down Expand Up @@ -686,7 +686,7 @@ public function testDoesntHaveFile(): void
$collection = new FileCollection();

$this->assertFalse($collection->hasFile('my-form.detailz.avatars.0'));
$this->assertNull($collection->getFile('my-form.detailz.avatars.0'));
$this->assertNotInstanceOf(UploadedFile::class, $collection->getFile('my-form.detailz.avatars.0'));
}

public function testGetFileMultipleHasNoFile(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public function testVagueDownload(): void

$actual = $response->download();

$this->assertNull($actual);
$this->assertNotInstanceOf(DownloadResponse::class, $actual);
}

public function testPretendMode(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Images/GDHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public function testImageConvert(): void
$this->handler->withFile($this->origin . 'ci-logo.jpeg');
$this->handler->convert(IMAGETYPE_PNG);
$this->handler->save($this->start . 'work/ci-logo.png');
$this->assertSame(exif_imagetype($this->start . 'work/ci-logo.png'), IMAGETYPE_PNG);
$this->assertSame(IMAGETYPE_PNG, exif_imagetype($this->start . 'work/ci-logo.png'));
}

public function testImageConvertPngToWebp(): void
Expand All @@ -420,7 +420,7 @@ public function testImageConvertPngToWebp(): void
$this->handler->convert(IMAGETYPE_WEBP);
$saved = $this->start . 'work/rocket.webp';
$this->handler->save($saved);
$this->assertSame(exif_imagetype($saved), IMAGETYPE_WEBP);
$this->assertSame(IMAGETYPE_WEBP, exif_imagetype($saved));
}

public function testImageReorientLandscape(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Images/ImageMagickHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public function testImageConvert(): void
$this->handler->withFile($this->origin . 'ci-logo.jpeg');
$this->handler->convert(IMAGETYPE_PNG);
$this->handler->save($this->root . 'ci-logo.png');
$this->assertSame(exif_imagetype($this->root . 'ci-logo.png'), IMAGETYPE_PNG);
$this->assertSame(IMAGETYPE_PNG, exif_imagetype($this->root . 'ci-logo.png'));
}

public function testImageReorientLandscape(): void

Check warning on line 453 in tests/system/Images/ImageMagickHandlerTest.php

View workflow job for this annotation

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.5545s from 0.5000s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageReorientLandscape
Expand Down

0 comments on commit e89ef62

Please sign in to comment.