Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from tattersoftware/tests
Add Tests
- Loading branch information
Showing
10 changed files
with
181 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
use CodeIgniter\Files\Exceptions\FileNotFoundException; | ||
use Tatter\Thumbnails\Exceptions\ThumbnailsException; | ||
use Tatter\Thumbnails\Thumbnails; | ||
use Tests\Support\TestCase; | ||
use Tests\Support\Thumbnailers\MockThumbnailer; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class LibraryTest extends TestCase | ||
{ | ||
public function testSetWidth() | ||
{ | ||
$this->thumbnails->setWidth(42); | ||
|
||
$result = $this->getPrivateProperty($this->thumbnails, 'width'); | ||
|
||
$this->assertSame(42, $result); | ||
} | ||
|
||
public function testSetHeight() | ||
{ | ||
$this->thumbnails->setHeight(42); | ||
|
||
$result = $this->getPrivateProperty($this->thumbnails, 'height'); | ||
|
||
$this->assertSame(42, $result); | ||
} | ||
|
||
public function testSetImageType() | ||
{ | ||
$this->thumbnails->setImageType(IMAGETYPE_WBMP); | ||
|
||
$result = $this->getPrivateProperty($this->thumbnails, 'imageType'); | ||
|
||
$this->assertSame(IMAGETYPE_WBMP, $result); | ||
} | ||
|
||
public function testCreatesFile() | ||
{ | ||
$result = $this->thumbnails->create($this->input); | ||
|
||
$this->assertFileExists($result); | ||
} | ||
|
||
public function testCreateThrowsNoFile() | ||
{ | ||
$this->expectException(FileNotFoundException::class); | ||
$this->expectExceptionMessage('File not found: banana'); | ||
|
||
$this->thumbnails->create('banana'); | ||
} | ||
|
||
public function testCreateThrowsNoHandler() | ||
{ | ||
// Disable the universal MockHandler | ||
config('Handlers')->ignoredClasses = [MockThumbnailer::class]; | ||
|
||
// Use a fresh instance to trigger factory re-discovery | ||
$thumbnails = new Thumbnails($this->config); | ||
|
||
$this->expectException(ThumbnailsException::class); | ||
$this->expectExceptionMessage('No handler found for file extension: php'); | ||
|
||
$thumbnails->create(__FILE__); | ||
} | ||
|
||
public function testCreateGathersErrors() | ||
{ | ||
MockThumbnailer::$shouldError = true; | ||
|
||
try { | ||
$this->thumbnails->create(__FILE__); | ||
} catch (ThumbnailsException $e) { | ||
} | ||
|
||
$result = $this->thumbnails->getErrors(); | ||
$this->assertCount(1, $result); | ||
$this->assertSame(['mock' => 'This error happened.'], $result); | ||
} | ||
|
||
public function testCreateThrowsFailure() | ||
{ | ||
MockThumbnailer::$shouldError = true; | ||
|
||
$this->expectException(ThumbnailsException::class); | ||
$this->expectExceptionMessage('Thumbnail creation failed for file: ' . __FILE__); | ||
|
||
$this->thumbnails->create(__FILE__); | ||
} | ||
|
||
public function testCreateUsesHandler() | ||
{ | ||
MockThumbnailer::$didProcess = false; | ||
|
||
$this->thumbnails->setHandler('mock'); | ||
$this->thumbnails->create($this->input); | ||
|
||
$this->assertTrue(MockThumbnailer::$didProcess); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
use Config\Mimes; | ||
use Tatter\Thumbnails\Exceptions\ThumbnailsException; | ||
use Tests\Support\TestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class MimeTest extends TestCase | ||
{ | ||
private $mimeBackup; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
// Ensure no MIME type matches | ||
$this->mimeBackup = Mimes::$mimes; | ||
Mimes::$mimes = []; | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
// Restore MIME types | ||
Mimes::$mimes = $this->mimeBackup; | ||
} | ||
|
||
public function testCreateThrowsNoExtension() | ||
{ | ||
$this->expectException(ThumbnailsException::class); | ||
$this->expectExceptionMessage('Unable to determine file extension for thumbnail handling'); | ||
|
||
$this->thumbnails->create(SUPPORTPATH . 'assets/noext'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
icanhascheeseburger |
This file was deleted.
Oops, something went wrong.