diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php index 5192701..e079293 100644 --- a/core/lib/Drupal/Core/Image/Image.php +++ b/core/lib/Drupal/Core/Image/Image.php @@ -74,14 +74,14 @@ public function isValid() { * {@inheritdoc} */ public function getHeight() { - return $this->toolkit->getHeight($this); + return $this->toolkit->getHeight(); } /** * {@inheritdoc} */ public function getWidth() { - return $this->toolkit->getWidth($this); + return $this->toolkit->getWidth(); } /** @@ -95,7 +95,7 @@ public function getFileSize() { * {@inheritdoc} */ public function getMimeType() { - return $this->toolkit->getMimeType($this); + return $this->toolkit->getMimeType(); } /** @@ -129,7 +129,7 @@ public function save($destination = NULL) { } $destination = $destination ?: $this->getSource(); - if ($return = $this->toolkit->save($this, $destination)) { + if ($return = $this->toolkit->save($destination)) { // Clear the cached file size and refresh the image information. clearstatcache(TRUE, $destination); $this->fileSize = filesize($destination); @@ -164,7 +164,7 @@ protected function parseFile($source) { } // Defer file parsing to toolkit. - if ($this->toolkit->parseFile($this, $source)) { + if ($this->toolkit->parseFile($source)) { $this->fileSize = filesize($source); $this->source = $source; $this->valid = TRUE; @@ -207,7 +207,6 @@ public function __call($method, $arguments) { if (is_callable(array($this->toolkit, $method))) { // @todo In https://drupal.org/node/2073759, call_user_func_array() will // be replaced by $this->toolkit->apply($name, $this, $arguments). - array_unshift($arguments, $this); return call_user_func_array(array($this->toolkit, $method), $arguments); } throw new \BadMethodCallException($method); diff --git a/core/lib/Drupal/Core/Image/ImageFactory.php b/core/lib/Drupal/Core/Image/ImageFactory.php index ebd30b5..620cae2 100644 --- a/core/lib/Drupal/Core/Image/ImageFactory.php +++ b/core/lib/Drupal/Core/Image/ImageFactory.php @@ -88,7 +88,10 @@ public function getToolkitId() { */ public function get($source = NULL, $toolkit_id = NULL) { $toolkit_id = $toolkit_id ?: $this->toolkitId; - return new Image($this->toolkitManager->createInstance($toolkit_id), $source); + $toolkit = $this->toolkitManager->createInstance($toolkit_id); + $image = new Image($toolkit, $source); + $toolkit->setImage($image); + return $image; } /** diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php index 4f28a6e..988c85c 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php @@ -7,11 +7,29 @@ namespace Drupal\Core\ImageToolkit; +use Drupal\Core\Image\ImageInterface; use Drupal\Core\Plugin\PluginBase; abstract class ImageToolkitBase extends PluginBase implements ImageToolkitInterface { /** + * The parent Image object. + * + * @var \Drupal\Core\Image\ImageInterface + */ + protected $image; + + /** + * {@inheritdoc} + */ + public function setImage(ImageInterface $image) { + if (!isset($this->image)) { + $this->image = $image; + } + return $this; + } + + /** * {@inheritdoc} */ public function getRequirements() { diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php index 7fbcede..d5fa925 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php @@ -62,8 +62,6 @@ public function settingsFormSubmit($form, &$form_state); /** * Scales an image to the specified size. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. * @param int $width * The new width of the resized image, in pixels. * @param int $height @@ -72,13 +70,11 @@ public function settingsFormSubmit($form, &$form_state); * @return bool * TRUE or FALSE, based on success. */ - public function resize(ImageInterface $image, $width, $height); + public function resize($width, $height); /** * Rotates an image the given number of degrees. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. * @param int $degrees * The number of (clockwise) degrees to rotate the image. * @param string $background @@ -91,13 +87,11 @@ public function resize(ImageInterface $image, $width, $height); * @return bool * TRUE or FALSE, based on success. */ - public function rotate(ImageInterface $image, $degrees, $background = NULL); + public function rotate($degrees, $background = NULL); /** * Crops an image. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. * @param int $x * The starting x offset at which to start the crop, in pixels. * @param int $y @@ -109,45 +103,35 @@ public function rotate(ImageInterface $image, $degrees, $background = NULL); * * @return bool * TRUE or FALSE, based on success. - * - * @see image_crop() */ - public function crop(ImageInterface $image, $x, $y, $width, $height); + public function crop($x, $y, $width, $height); /** * Converts an image resource to grayscale. * * Note that transparent GIFs loose transparency when desaturated. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. The $image->resource value will be modified by this - * call. - * * @return bool * TRUE or FALSE, based on success. */ - public function desaturate(ImageInterface $image); + public function desaturate(); /** * Writes an image resource to a destination file. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. * @param string $destination * A string file URI or path where the image should be saved. * * @return bool * TRUE or FALSE, based on success. */ - public function save(ImageInterface $image, $destination); + public function save($destination); /** * Scales an image while maintaining aspect ratio. * * The resulting image can be smaller for one or both target dimensions. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. * @param int $width * (optional) The target width, in pixels. This value is omitted then the * scaling will based only on the height value. @@ -161,7 +145,7 @@ public function save(ImageInterface $image, $destination); * @return bool * TRUE on success, FALSE on failure. */ - public function scale(ImageInterface $image, $width = NULL, $height = NULL, $upscale = FALSE); + public function scale($width = NULL, $height = NULL, $upscale = FALSE); /** * Scales an image to the exact width and height given. @@ -172,8 +156,6 @@ public function scale(ImageInterface $image, $width = NULL, $height = NULL, $ups * * The resulting image always has the exact target dimensions. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. * @param int $width * The target width, in pixels. * @param int $height @@ -182,54 +164,55 @@ public function scale(ImageInterface $image, $width = NULL, $height = NULL, $ups * @return bool * TRUE on success, FALSE on failure. */ - public function scaleAndCrop(ImageInterface $image, $width, $height); + public function scaleAndCrop($width, $height); /** - * Determines if a file contains a valid image. + * Injects the parent Image object in its toolkit instance. + * + * This allows toolkit code to access methods set on the Image object. * * @param \Drupal\Core\Image\ImageInterface $image * An image object. + * + * @return this + */ + public function setImage(ImageInterface $image); + + /** + * Determines if a file contains a valid image. + * * @param string $source * A string file URI or path where the image should be found. * * @return bool * TRUE if the file could be found and is an image, FALSE otherwise. */ - public function parseFile(ImageInterface $image, $source); + public function parseFile($source); /** * Returns the height of the image. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. - * * @return int|null * The height of the image, or NULL if the image is invalid. */ - public function getHeight(ImageInterface $image); + public function getHeight(); /** * Returns the width of the image. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. - * * @return int|null * The width of the image, or NULL if the image is invalid. */ - public function getWidth(ImageInterface $image); + public function getWidth(); /** * Returns the MIME type of the image file. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. - * * @return string * The MIME type of the image file, or an empty string if the image is * invalid. */ - public function getMimeType(ImageInterface $image); + public function getMimeType(); /** * Gets toolkit requirements in a format suitable for hook_requirements(). diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php index 6dd91cc..164abc1 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php @@ -88,7 +88,7 @@ public function settingsFormSubmit($form, &$form_state) { /** * {@inheritdoc} */ - public function resize(ImageInterface $image, $width, $height) { + public function resize($width, $height) { // @todo Dimensions computation will be moved into a dedicated functionality // in https://drupal.org/node/2108307. $width = (int) round($width); @@ -100,7 +100,7 @@ public function resize(ImageInterface $image, $width, $height) { $res = $this->createTmp($this->getType(), $width, $height); - if (!imagecopyresampled($res, $this->getResource(), 0, 0, 0, 0, $width, $height, $this->getWidth($image), $this->getHeight($image))) { + if (!imagecopyresampled($res, $this->getResource(), 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight())) { return FALSE; } @@ -113,10 +113,10 @@ public function resize(ImageInterface $image, $width, $height) { /** * {@inheritdoc} */ - public function rotate(ImageInterface $image, $degrees, $background = NULL) { + public function rotate($degrees, $background = NULL) { // PHP installations using non-bundled GD do not have imagerotate. if (!function_exists('imagerotate')) { - watchdog('image', 'The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $image->getSource())); + watchdog('image', 'The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $this->image->getSource())); return FALSE; } @@ -162,10 +162,10 @@ public function rotate(ImageInterface $image, $degrees, $background = NULL) { /** * {@inheritdoc} */ - public function crop(ImageInterface $image, $x, $y, $width, $height) { + public function crop($x, $y, $width, $height) { // @todo Dimensions computation will be moved into a dedicated functionality // in https://drupal.org/node/2108307. - $aspect = $this->getHeight($image) / $this->getWidth($image); + $aspect = $this->getHeight() / $this->getWidth(); $height = empty($height) ? $width * $aspect : $height; $width = empty($width) ? $height / $aspect : $width; $width = (int) round($width); @@ -190,10 +190,10 @@ public function crop(ImageInterface $image, $x, $y, $width, $height) { /** * {@inheritdoc} */ - public function desaturate(ImageInterface $image) { + public function desaturate() { // PHP installations using non-bundled GD do not have imagefilter. if (!function_exists('imagefilter')) { - watchdog('image', 'The image %file could not be desaturated because the imagefilter() function is not available in this PHP installation.', array('%file' => $image->getSource())); + watchdog('image', 'The image %file could not be desaturated because the imagefilter() function is not available in this PHP installation.', array('%file' => $this->image->getSource())); return FALSE; } @@ -203,12 +203,12 @@ public function desaturate(ImageInterface $image) { /** * {@inheritdoc} */ - public function scale(ImageInterface $image, $width = NULL, $height = NULL, $upscale = FALSE) { + public function scale($width = NULL, $height = NULL, $upscale = FALSE) { // @todo Dimensions computation will be moved into a dedicated functionality // in https://drupal.org/node/2108307. $dimensions = array( - 'width' => $this->getWidth($image), - 'height' => $this->getHeight($image), + 'width' => $this->getWidth(), + 'height' => $this->getHeight(), ); // Scale the dimensions - if they don't change then just return success. @@ -216,21 +216,21 @@ public function scale(ImageInterface $image, $width = NULL, $height = NULL, $ups return TRUE; } - return $this->resize($image, $dimensions['width'], $dimensions['height']); + return $this->resize($dimensions['width'], $dimensions['height']); } /** * {@inheritdoc} */ - public function scaleAndCrop(ImageInterface $image, $width, $height) { + public function scaleAndCrop($width, $height) { // @todo Dimensions computation will be moved into a dedicated functionality // in https://drupal.org/node/2108307. - $scale = max($width / $this->getWidth($image), $height / $this->getHeight($image)); - $x = ($this->getWidth($image) * $scale - $width) / 2; - $y = ($this->getHeight($image) * $scale - $height) / 2; + $scale = max($width / $this->getWidth(), $height / $this->getHeight()); + $x = ($this->getWidth() * $scale - $width) / 2; + $y = ($this->getHeight() * $scale - $height) / 2; - if ($this->resize($image, $this->getWidth($image) * $scale, $this->getHeight($image) * $scale)) { - return $this->crop($image, $x, $y, $width, $height); + if ($this->resize($this->getWidth() * $scale, $this->getHeight() * $scale)) { + return $this->crop($x, $y, $width, $height); } return FALSE; @@ -265,7 +265,7 @@ protected function load($source) { /** * {@inheritdoc} */ - public function save(ImageInterface $image, $destination) { + public function save($destination) { $scheme = file_uri_scheme($destination); // Work around lack of stream wrapper support in imagejpeg() and imagepng(). if ($scheme && file_stream_wrapper_valid_scheme($scheme)) { @@ -304,11 +304,11 @@ public function save(ImageInterface $image, $destination) { /** * {@inheritdoc} */ - public function parseFile(ImageInterface $image, $source) { + public function parseFile($source) { $data = getimagesize($source); if ($data && is_array($data) && in_array($data[2], static::supportedTypes())) { $this->setType($data[2]); - $this->load($source, $this->getType()); + $this->load($source); return (bool) $this->getResource(); } return FALSE; @@ -362,14 +362,14 @@ public function createTmp($type, $width, $height) { /** * {@inheritdoc} */ - public function getWidth(ImageInterface $image) { + public function getWidth() { return $this->getResource() ? imagesx($this->getResource()) : NULL; } /** * {@inheritdoc} */ - public function getHeight(ImageInterface $image) { + public function getHeight() { return $this->getResource() ? imagesy($this->getResource()) : NULL; } @@ -403,7 +403,7 @@ public function setType($type) { /** * {@inheritdoc} */ - public function getMimeType(ImageInterface $image) { + public function getMimeType() { return $this->getType() ? image_type_to_mime_type($this->getType()) : ''; } diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php index dc60eca..28907cf 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php @@ -58,8 +58,8 @@ function testResize() { // Check the parameters. $calls = $this->imageTestGetAllCalls(); - $this->assertEqual($calls['resize'][0][1], 1, 'Width was passed correctly'); - $this->assertEqual($calls['resize'][0][2], 2, 'Height was passed correctly'); + $this->assertEqual($calls['resize'][0][0], 1, 'Width was passed correctly'); + $this->assertEqual($calls['resize'][0][1], 2, 'Height was passed correctly'); } /** @@ -72,8 +72,8 @@ function testScale() { // Check the parameters. $calls = $this->imageTestGetAllCalls(); - $this->assertEqual($calls['scale'][0][1], 10, 'Width was passed correctly'); - $this->assertEqual($calls['scale'][0][2], 10, 'Height was based off aspect ratio and passed correctly'); + $this->assertEqual($calls['scale'][0][0], 10, 'Width was passed correctly'); + $this->assertEqual($calls['scale'][0][1], 10, 'Height was based off aspect ratio and passed correctly'); } /** @@ -86,8 +86,8 @@ function testScaleAndCrop() { // Check the parameters. $calls = $this->imageTestGetAllCalls(); - $this->assertEqual($calls['scaleAndCrop'][0][1], 5, 'Width was computed and passed correctly'); - $this->assertEqual($calls['scaleAndCrop'][0][2], 10, 'Height was computed and passed correctly'); + $this->assertEqual($calls['scaleAndCrop'][0][0], 5, 'Width was computed and passed correctly'); + $this->assertEqual($calls['scaleAndCrop'][0][1], 10, 'Height was computed and passed correctly'); } /** @@ -99,8 +99,8 @@ function testRotate() { // Check the parameters. $calls = $this->imageTestGetAllCalls(); - $this->assertEqual($calls['rotate'][0][1], 90, 'Degrees were passed correctly'); - $this->assertEqual($calls['rotate'][0][2], 1, 'Background color was passed correctly'); + $this->assertEqual($calls['rotate'][0][0], 90, 'Degrees were passed correctly'); + $this->assertEqual($calls['rotate'][0][1], 1, 'Background color was passed correctly'); } /** @@ -112,10 +112,10 @@ function testCrop() { // Check the parameters. $calls = $this->imageTestGetAllCalls(); - $this->assertEqual($calls['crop'][0][1], 1, 'X was passed correctly'); - $this->assertEqual($calls['crop'][0][2], 2, 'Y was passed correctly'); - $this->assertEqual($calls['crop'][0][3], 3, 'Width was passed correctly'); - $this->assertEqual($calls['crop'][0][4], 4, 'Height was passed correctly'); + $this->assertEqual($calls['crop'][0][0], 1, 'X was passed correctly'); + $this->assertEqual($calls['crop'][0][1], 2, 'Y was passed correctly'); + $this->assertEqual($calls['crop'][0][2], 3, 'Width was passed correctly'); + $this->assertEqual($calls['crop'][0][3], 4, 'Height was passed correctly'); } /** @@ -127,6 +127,6 @@ function testDesaturate() { // Check the parameters. $calls = $this->imageTestGetAllCalls(); - $this->assertEqual(count($calls['desaturate'][0]), 1, 'Only the image was passed.'); + $this->assertEqual(count($calls['desaturate'][0]), 0, 'No arguments were passed.'); } } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php index 74e08b0..51fbe49 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php @@ -70,8 +70,8 @@ public function settingsFormSubmit($form, &$form_state) { /** * {@inheritdoc} */ - public function parseFile(ImageInterface $image, $source) { - $this->logCall('parseFile', array($image)); + public function parseFile($source) { + $this->logCall('parseFile', array($source)); $data = getimagesize($source); if ($data && is_array($data) && in_array($data[2], static::supportedTypes())) { $this->setType($data[2]); @@ -85,8 +85,8 @@ public function parseFile(ImageInterface $image, $source) { /** * {@inheritdoc} */ - public function save(ImageInterface $image, $destination) { - $this->logCall('save', array($image, $destination)); + public function save($destination) { + $this->logCall('save', array($destination)); // Return false so that image_save() doesn't try to chmod the destination // file that we didn't bother to create. return FALSE; @@ -95,48 +95,48 @@ public function save(ImageInterface $image, $destination) { /** * {@inheritdoc} */ - public function crop(ImageInterface $image, $x, $y, $width, $height) { - $this->logCall('crop', array($image, $x, $y, $width, $height)); + public function crop($x, $y, $width, $height) { + $this->logCall('crop', array($x, $y, $width, $height)); return TRUE; } /** * {@inheritdoc} */ - public function resize(ImageInterface $image, $width, $height) { - $this->logCall('resize', array($image, $width, $height)); + public function resize($width, $height) { + $this->logCall('resize', array($width, $height)); return TRUE; } /** * {@inheritdoc} */ - public function rotate(ImageInterface $image, $degrees, $background = NULL) { - $this->logCall('rotate', array($image, $degrees, $background)); + public function rotate($degrees, $background = NULL) { + $this->logCall('rotate', array($degrees, $background)); return TRUE; } /** * {@inheritdoc} */ - public function desaturate(ImageInterface $image) { - $this->logCall('desaturate', array($image)); + public function desaturate() { + $this->logCall('desaturate', array()); return TRUE; } /** * {@inheritdoc} */ - public function scale(ImageInterface $image, $width = NULL, $height = NULL, $upscale = FALSE) { - $this->logCall('scale', array($image, $width, $height, $upscale)); + public function scale($width = NULL, $height = NULL, $upscale = FALSE) { + $this->logCall('scale', array($width, $height, $upscale)); return TRUE; } /** * {@inheritdoc} */ - public function scaleAndCrop(ImageInterface $image, $width, $height) { - $this->logCall('scaleAndCrop', array($image, $width, $height)); + public function scaleAndCrop($width, $height) { + $this->logCall('scaleAndCrop', array($width, $height)); return TRUE; } @@ -161,14 +161,14 @@ protected function logCall($op, $args) { /** * {@inheritdoc} */ - public function getWidth(ImageInterface $image) { + public function getWidth() { return $this->width; } /** * {@inheritdoc} */ - public function getHeight(ImageInterface $image) { + public function getHeight() { return $this->height; } @@ -202,7 +202,7 @@ public function setType($type) { /** * {@inheritdoc} */ - public function getMimeType(ImageInterface $image) { + public function getMimeType() { return $this->getType() ? image_type_to_mime_type($this->getType()) : ''; } diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php index e2542ed..7e8bda1 100644 --- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php @@ -47,6 +47,7 @@ protected function setUp() { ->will($this->returnValue('gd')); $this->image = new Image($this->toolkit, $this->source); + $this->toolkit->setImage($this->image); } /** @@ -130,6 +131,7 @@ public function testSave() { ->method('chmod') ->will($this->returnValue(TRUE)); + $this->toolkit->setImage($image); $image->save(); } @@ -159,6 +161,7 @@ public function testChmodFails() { ->method('chmod') ->will($this->returnValue(FALSE)); + $this->toolkit->setImage($image); $this->assertFalse($image->save()); } @@ -168,6 +171,7 @@ public function testChmodFails() { public function testParseFileFails() { $toolkit = $this->getToolkitMock(); $image = new Image($toolkit, 'magic-foobars.png'); + $toolkit->setImage($image); $this->assertFalse($image->isValid()); $this->assertFalse($image->save()); @@ -179,6 +183,7 @@ public function testParseFileFails() { public function testScaleWidth() { $toolkit = $this->getToolkitMock(array('resize')); $image = new Image($toolkit, $this->source); + $toolkit->setImage($image); $toolkit->expects($this->any()) ->method('resize') @@ -193,6 +198,7 @@ public function testScaleWidth() { public function testScaleHeight() { $toolkit = $this->getToolkitMock(array('resize')); $image = new Image($toolkit, $this->source); + $toolkit->setImage($image); $toolkit->expects($this->any()) ->method('resize') @@ -207,6 +213,7 @@ public function testScaleHeight() { public function testScaleSame() { $toolkit = $this->getToolkitMock(array('resize')); $image = new Image($toolkit, $this->source); + $toolkit->setImage($image); // Dimensions are the same, resize should not be called. $toolkit->expects($this->never()) @@ -223,6 +230,7 @@ public function testScaleSame() { public function testScaleAndCropWidth() { $toolkit = $this->getToolkitMock(array('resize', 'crop')); $image = new Image($toolkit, $this->source); + $toolkit->setImage($image); $toolkit->expects($this->once()) ->method('resize') @@ -242,6 +250,7 @@ public function testScaleAndCropWidth() { public function testScaleAndCropHeight() { $toolkit = $this->getToolkitMock(array('resize', 'crop')); $image = new Image($toolkit, $this->source); + $toolkit->setImage($image); $toolkit->expects($this->once()) ->method('resize') @@ -261,6 +270,7 @@ public function testScaleAndCropHeight() { public function testScaleAndCropFails() { $toolkit = $this->getToolkitMock(array('resize', 'crop')); $image = new Image($toolkit, $this->source); + $toolkit->setImage($image); $toolkit->expects($this->once()) ->method('resize') @@ -297,6 +307,7 @@ public function testScaleAndCropFails() { public function testCrop() { $toolkit = $this->getToolkitMock(array('crop')); $image = new Image($toolkit, $this->source); + $toolkit->setImage($image); $toolkit->expects($this->once()) ->method('crop') @@ -321,6 +332,7 @@ public function testCrop() { public function testDesaturate() { $toolkit = $this->getToolkitMock(array('desaturate')); $image = new Image($toolkit, $this->source); + $toolkit->setImage($image); $toolkit->expects($this->once()) ->method('desaturate'); @@ -333,6 +345,7 @@ public function testDesaturate() { public function testRotate() { $toolkit = $this->getToolkitMock(array('rotate')); $image = new Image($toolkit, $this->source); + $toolkit->setImage($image); $toolkit->expects($this->once()) ->method('rotate');