ResizerTest
extends TestCase
in package
Uses
GDAssertTrait
Table of Contents
- COMMON_FIXTURES = ['reset' => 'testReset_testResize0x0_testResizeAutoLandscape1x1', 'square' => 'testResizeAutoSquare25x50_testResizeAutoSquare50x25_testResizeAutoSquare50x50_testResizeFitSquare50x50']
- Fixtures that are common to multiple tests (reduce number of images and noise for identical results)
- FIXTURE_PATH = __DIR__ . '/../../fixtures/'
- FIXTURE_SRC_BASE_PATH = self::FIXTURE_PATH . 'resizer/source/'
- FIXTURE_TARGET_PATH = self::FIXTURE_PATH . 'resizer/target/'
- GENERATE_NEW_FIXTURES = alse
- SRC_LANDSCAPE_ROTATED = 'landscape_rotated.jpg'
- SRC_LANDSCAPE_TRANSPARENT = 'landscape_transparent.png'
- SRC_PORTRAIT = 'portrait.gif'
- SRC_SQUARE = 'square.jpg'
- TMP_TEST_FILE_PATH = self::FIXTURE_PATH . 'tmp/'
- $extension : string
- $resizer : Resizer
- $source : string
- $target : string
- $tmpTarget : string
- createApplication() : HttpKernelInterface
- Creates the application.
- testCrop10x15() : mixed
- Given a Resizer with any image When the crop method is called with startX, startY, newWidth and newHeight parameters Then the saved image should be cropped as expected
- testNothing() : mixed
- testReset() : mixed
- Given a Resizer with any image When the resize method is called with altering parameters followed by the reset method Then the saved image should be the same as the original one (size, color and transparency)
- testResize0x0() : mixed
- Given a Resizer with any image When the resize method is called with 0x0 Then the saved image should be the same as the original one (size, color and transparency)
- testResize0x20() : mixed
- Given a Resizer with any image When the resize method is called with 0x20 Then the saved image should have a height of 20 and its width set automatically
- testResize20x0() : mixed
- Given a Resizer with any image When the resize method is called with 20x0 Then the saved image should have a width of 20 and its height set automatically
- testResizeAutoExifRotated30x30() : mixed
- Given a Resizer with a JPG image which has an EXIF tag (Rotation=8) When the resize method is called with the auto mode and 30x30 dimensions Then the saved image should have the EXIF rotation applied and
- testResizeAutoLandscape1x1() : mixed
- Given a Resizer with a transparent landscape image When the resize method is called with the auto parameter and 1x1 dimensions Then the saved image should be the same as the original one (size, color and transparency)
- testResizeAutoLandscape1x5() : mixed
- Given a Resizer with a transparent landscape image When the resize method is called with the auto parameter and 1x5 dimensions Then the saved image should be have a height of 5 and an automatic width
- testResizeAutoLandscape25() : mixed
- Given a Resizer with a landscape image When the resize method is called with the auto parameter and 25x50 dimensions Then the saved image should have a width of 25 and its height set automatically
- testResizeAutoLandscape25x1() : mixed
- Given a Resizer with a transparent landscape image When the resize method is called with the auto parameter and 50x1 dimensions Then the saved image should have a width a 25 and an automatic height
- testResizeAutoPortrait50() : mixed
- Given a Resizer with a portrait image When the resize method is called with the auto parameter and 25x50 dimensions Then the saved image should have a height of 50 and its width set automatically
- testResizeAutoSquare25x50() : mixed
- Given a Resizer with a square image When the resize method is called with the auto parameter and a 25x50 dimension Then the saved image should have be 50x50 (largest dimension takes over)
- testResizeAutoSquare50x25() : mixed
- Given a Resizer with a square image When the resize method is called with the auto parameter and a 50x25 dimension Then the saved image should have be 50x50 (largest dimension takes over)
- testResizeAutoSquare50x50() : mixed
- Given a Resizer with a square image When the resize method is called with the auto parameter and a 50x50 dimension Then the saved image should have be 50x50
- testResizeExact10x15() : mixed
- Given a Resizer with a square image When the resize method is called with the exact mode and 10x1=15 dimensions Then the saved image should be 10x15 and distorted
- testResizeFitLandscape30x30() : mixed
- Given a Resizer with a landscape image When the resize method is called with the fit mode and 30x30 dimensions Then the saved image should have a width of 30 and an automatic height
- testResizeFitPortrait30x30() : mixed
- Given a Resizer with a landscape image When the resize method is called with the fit mode and 30x30 dimensions Then the saved image should have a height of 30 and an automatic width
- testResizeFitSquare50x50() : mixed
- Given a Resizer with a square image When the resize method is called with the fit mode and 50x50 dimensions Then the saved image should have be 50x50
- testResizeLandscape10x1() : mixed
- Given a Resizer with any image When the resize method is called with the landscape mode and 10x1 dimensions Then the saved image should have a width of 10 and an automatic height
- testResizePortrait1x10() : mixed
- Given a Resizer with any image When the resize method is called with the portrait mode and 1x10 dimensions Then the saved image should have a width of 10 and an automatic height
- testSharpen() : mixed
- Given a Resizer with any image When the sharpen method is called with a valid value Then the saved image should be sharpened by the given value
- assertImageSameAsFixture() : mixed
- Assert that the current Resizer image, once saved, is the same as the fixture which corresponds to the given method name.
- buildTargetFixturePath() : string
- Build the full path to the target fixture from a test method name.
- callProtectedMethod() : mixed
- createFixtureResizer() : mixed
- Create the Resizer instance from the declared source image.
- generateFixture() : mixed
- Generate a fixture image for the given method name using current Resizer instance.
- setSource() : mixed
- Set the source path and set the extension to match.
- tearDown() : mixed
- Remove the temporary file after running each test.
Constants
COMMON_FIXTURES
Fixtures that are common to multiple tests (reduce number of images and noise for identical results)
public
mixed
COMMON_FIXTURES
= ['reset' => 'testReset_testResize0x0_testResizeAutoLandscape1x1', 'square' => 'testResizeAutoSquare25x50_testResizeAutoSquare50x25_testResizeAutoSquare50x50_testResizeFitSquare50x50']
FIXTURE_PATH
public
mixed
FIXTURE_PATH
= __DIR__ . '/../../fixtures/'
FIXTURE_SRC_BASE_PATH
public
mixed
FIXTURE_SRC_BASE_PATH
= self::FIXTURE_PATH . 'resizer/source/'
FIXTURE_TARGET_PATH
public
mixed
FIXTURE_TARGET_PATH
= self::FIXTURE_PATH . 'resizer/target/'
GENERATE_NEW_FIXTURES
public
mixed
GENERATE_NEW_FIXTURES
= alse
SRC_LANDSCAPE_ROTATED
public
mixed
SRC_LANDSCAPE_ROTATED
= 'landscape_rotated.jpg'
SRC_LANDSCAPE_TRANSPARENT
public
mixed
SRC_LANDSCAPE_TRANSPARENT
= 'landscape_transparent.png'
SRC_PORTRAIT
public
mixed
SRC_PORTRAIT
= 'portrait.gif'
SRC_SQUARE
public
mixed
SRC_SQUARE
= 'square.jpg'
TMP_TEST_FILE_PATH
public
mixed
TMP_TEST_FILE_PATH
= self::FIXTURE_PATH . 'tmp/'
Properties
$extension
protected
string
$extension
The path to the extension of the target file
$resizer
protected
Resizer
$resizer
The Resizer instance (unit under test)
$source
protected
string
$source
The path to the source image
$target
protected
string
$target
The path to the target image (fixture)
$tmpTarget
protected
string
$tmpTarget
The path to the image being generated by the test
Methods
createApplication()
Creates the application.
public
createApplication() : HttpKernelInterface
Return values
HttpKernelInterface —testCrop10x15()
Given a Resizer with any image When the crop method is called with startX, startY, newWidth and newHeight parameters Then the saved image should be cropped as expected
public
testCrop10x15() : mixed
Tags
Return values
mixed —testNothing()
public
testNothing() : mixed
Return values
mixed —testReset()
Given a Resizer with any image When the resize method is called with altering parameters followed by the reset method Then the saved image should be the same as the original one (size, color and transparency)
public
testReset() : mixed
Tags
Return values
mixed —testResize0x0()
Given a Resizer with any image When the resize method is called with 0x0 Then the saved image should be the same as the original one (size, color and transparency)
public
testResize0x0() : mixed
Tags
Return values
mixed —testResize0x20()
Given a Resizer with any image When the resize method is called with 0x20 Then the saved image should have a height of 20 and its width set automatically
public
testResize0x20() : mixed
Tags
Return values
mixed —testResize20x0()
Given a Resizer with any image When the resize method is called with 20x0 Then the saved image should have a width of 20 and its height set automatically
public
testResize20x0() : mixed
Tags
Return values
mixed —testResizeAutoExifRotated30x30()
Given a Resizer with a JPG image which has an EXIF tag (Rotation=8) When the resize method is called with the auto mode and 30x30 dimensions Then the saved image should have the EXIF rotation applied and
public
testResizeAutoExifRotated30x30() : mixed
Tags
Return values
mixed —testResizeAutoLandscape1x1()
Given a Resizer with a transparent landscape image When the resize method is called with the auto parameter and 1x1 dimensions Then the saved image should be the same as the original one (size, color and transparency)
public
testResizeAutoLandscape1x1() : mixed
Tags
Return values
mixed —testResizeAutoLandscape1x5()
Given a Resizer with a transparent landscape image When the resize method is called with the auto parameter and 1x5 dimensions Then the saved image should be have a height of 5 and an automatic width
public
testResizeAutoLandscape1x5() : mixed
Tags
Return values
mixed —testResizeAutoLandscape25()
Given a Resizer with a landscape image When the resize method is called with the auto parameter and 25x50 dimensions Then the saved image should have a width of 25 and its height set automatically
public
testResizeAutoLandscape25() : mixed
Tags
Return values
mixed —testResizeAutoLandscape25x1()
Given a Resizer with a transparent landscape image When the resize method is called with the auto parameter and 50x1 dimensions Then the saved image should have a width a 25 and an automatic height
public
testResizeAutoLandscape25x1() : mixed
Tags
Return values
mixed —testResizeAutoPortrait50()
Given a Resizer with a portrait image When the resize method is called with the auto parameter and 25x50 dimensions Then the saved image should have a height of 50 and its width set automatically
public
testResizeAutoPortrait50() : mixed
Tags
Return values
mixed —testResizeAutoSquare25x50()
Given a Resizer with a square image When the resize method is called with the auto parameter and a 25x50 dimension Then the saved image should have be 50x50 (largest dimension takes over)
public
testResizeAutoSquare25x50() : mixed
Tags
Return values
mixed —testResizeAutoSquare50x25()
Given a Resizer with a square image When the resize method is called with the auto parameter and a 50x25 dimension Then the saved image should have be 50x50 (largest dimension takes over)
public
testResizeAutoSquare50x25() : mixed
Tags
Return values
mixed —testResizeAutoSquare50x50()
Given a Resizer with a square image When the resize method is called with the auto parameter and a 50x50 dimension Then the saved image should have be 50x50
public
testResizeAutoSquare50x50() : mixed
Tags
Return values
mixed —testResizeExact10x15()
Given a Resizer with a square image When the resize method is called with the exact mode and 10x1=15 dimensions Then the saved image should be 10x15 and distorted
public
testResizeExact10x15() : mixed
Tags
Return values
mixed —testResizeFitLandscape30x30()
Given a Resizer with a landscape image When the resize method is called with the fit mode and 30x30 dimensions Then the saved image should have a width of 30 and an automatic height
public
testResizeFitLandscape30x30() : mixed
Tags
Return values
mixed —testResizeFitPortrait30x30()
Given a Resizer with a landscape image When the resize method is called with the fit mode and 30x30 dimensions Then the saved image should have a height of 30 and an automatic width
public
testResizeFitPortrait30x30() : mixed
Tags
Return values
mixed —testResizeFitSquare50x50()
Given a Resizer with a square image When the resize method is called with the fit mode and 50x50 dimensions Then the saved image should have be 50x50
public
testResizeFitSquare50x50() : mixed
Tags
Return values
mixed —testResizeLandscape10x1()
Given a Resizer with any image When the resize method is called with the landscape mode and 10x1 dimensions Then the saved image should have a width of 10 and an automatic height
public
testResizeLandscape10x1() : mixed
Tags
Return values
mixed —testResizePortrait1x10()
Given a Resizer with any image When the resize method is called with the portrait mode and 1x10 dimensions Then the saved image should have a width of 10 and an automatic height
public
testResizePortrait1x10() : mixed
Tags
Return values
mixed —testSharpen()
Given a Resizer with any image When the sharpen method is called with a valid value Then the saved image should be sharpened by the given value
public
testSharpen() : mixed
Tags
Return values
mixed —assertImageSameAsFixture()
Assert that the current Resizer image, once saved, is the same as the fixture which corresponds to the given method name.
protected
assertImageSameAsFixture(string $methodName) : mixed
Parameters
- $methodName : string
-
Method name
Tags
Return values
mixed —buildTargetFixturePath()
Build the full path to the target fixture from a test method name.
protected
buildTargetFixturePath(string $methodName) : string
Parameters
- $methodName : string
-
Method name
Return values
string —Full path to target fixture
callProtectedMethod()
protected
static callProtectedMethod(mixed $object, mixed $name[, mixed $params = [] ]) : mixed
Parameters
- $object : mixed
- $name : mixed
- $params : mixed = []
Return values
mixed —createFixtureResizer()
Create the Resizer instance from the declared source image.
protected
createFixtureResizer() : mixed
Tags
Return values
mixed —generateFixture()
Generate a fixture image for the given method name using current Resizer instance.
protected
generateFixture(string $methodName) : mixed
This image has to be validated manually once to ensure the result is as expected.
Parameters
- $methodName : string
Tags
Return values
mixed —setSource()
Set the source path and set the extension to match.
protected
setSource(string $source) : mixed
Parameters
- $source : string
-
Path to the source image for the Resizer
Return values
mixed —tearDown()
Remove the temporary file after running each test.
protected
tearDown() : mixed