1
0
mirror of https://github.com/Intervention/image.git synced 2025-07-31 11:00:12 +02:00

implemented Argument class

This commit is contained in:
Oliver Vogel
2014-05-14 17:35:17 +02:00
parent 2e98670930
commit eae9d83f8a
61 changed files with 174 additions and 169 deletions

View File

@@ -14,15 +14,9 @@ abstract class AbstractCommand
$this->arguments = $arguments;
}
public function getArgument($key, $default = null)
public function argument($key)
{
// return new \Intervention\Image\Argument($this->arguments, $key);
if (is_array($this->arguments)) {
return array_key_exists($key, $this->arguments) ? $this->arguments[$key] : $default;
}
return $default;
return new \Intervention\Image\Commands\Argument($this, $key);
}
public function getOutput()

View File

@@ -51,6 +51,12 @@ class Argument
switch (strtolower($type)) {
case 'bool':
case 'boolean':
$fail = ! is_bool($value);
$message = sprintf('%s accepts only boolean values as argument %d.', $this->getCommandName(), $this->key + 1);
break;
case 'int':
case 'integer':
$fail = ! is_integer($value);

View File

@@ -8,10 +8,10 @@ class CircleCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$x = $this->getArgument(0);
$y = $this->getArgument(1);
$radius = $this->getArgument(2);
$callback = $this->getArgument(3);
$x = $this->argument(0)->type('numeric')->required()->value();
$y = $this->argument(1)->type('numeric')->required()->value();
$radius = $this->argument(2)->type('numeric')->required()->value();
$callback = $this->argument(3)->type('closure')->value();
$circle_classname = sprintf('\Intervention\Image\%s\Shapes\CircleShape',
$image->getDriver()->getDriverName());

View File

@@ -8,11 +8,11 @@ class EllipseCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$x = $this->getArgument(0);
$y = $this->getArgument(1);
$width = $this->getArgument(2);
$height = $this->getArgument(3);
$callback = $this->getArgument(4);
$x = $this->argument(0)->type('numeric')->required()->value();
$y = $this->argument(1)->type('numeric')->required()->value();
$width = $this->argument(2)->type('numeric')->value(10);
$height = $this->argument(3)->type('numeric')->value(10);
$callback = $this->argument(4)->type('closure')->value();
$ellipse_classname = sprintf('\Intervention\Image\%s\Shapes\EllipseShape',
$image->getDriver()->getDriverName());

View File

@@ -12,7 +12,7 @@ class ExifCommand extends AbstractCommand
);
}
$key = $this->getArgument(0);
$key = $this->argument(0)->value();
$data = exif_read_data($image->dirname .'/'. $image->basename, 'EXIF', false);
if (! is_null($key) && is_array($data)) {

View File

@@ -8,11 +8,11 @@ class LineCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$x1 = $this->getArgument(0);
$y1 = $this->getArgument(1);
$x2 = $this->getArgument(2);
$y2 = $this->getArgument(3);
$callback = $this->getArgument(4);
$x1 = $this->argument(0)->type('numeric')->required()->value();
$y1 = $this->argument(1)->type('numeric')->required()->value();
$x2 = $this->argument(2)->type('numeric')->required()->value();
$y2 = $this->argument(3)->type('numeric')->required()->value();
$callback = $this->argument(4)->type('closure')->value();
$line_classname = sprintf('\Intervention\Image\%s\Shapes\LineShape',
$image->getDriver()->getDriverName());

View File

@@ -8,11 +8,11 @@ class RectangleCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$x1 = $this->getArgument(0);
$y1 = $this->getArgument(1);
$x2 = $this->getArgument(2);
$y2 = $this->getArgument(3);
$callback = $this->getArgument(4);
$x1 = $this->argument(0)->type('numeric')->required()->value();
$y1 = $this->argument(1)->type('numeric')->required()->value();
$x2 = $this->argument(2)->type('numeric')->required()->value();
$y2 = $this->argument(3)->type('numeric')->required()->value();
$callback = $this->argument(4)->type('closure')->value();
$rectangle_classname = sprintf('\Intervention\Image\%s\Shapes\RectangleShape',
$image->getDriver()->getDriverName());

View File

@@ -8,8 +8,8 @@ class ResponseCommand extends AbstractCommand
{
public function execute($image)
{
$format = $this->getArgument(0);
$quality = $this->getArgument(1);
$format = $this->argument(0)->value();
$quality = $this->argument(1)->between(0, 100)->value();
$response = new Response($image, $format, $quality);

View File

@@ -8,10 +8,10 @@ class TextCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$text = $this->getArgument(0);
$x = $this->getArgument(1, 0);
$y = $this->getArgument(2, 0);
$callback = $this->getArgument(3);
$text = $this->argument(0)->required()->value();
$x = $this->argument(1, 0)->type('numeric')->value();
$y = $this->argument(2, 0)->type('numeric')->value();
$callback = $this->argument(3)->type('closure')->value();
$fontclassname = sprintf('\Intervention\Image\%s\Font',
$image->getDriver()->getDriverName());

View File

@@ -6,7 +6,7 @@ class BlurCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$amount = $this->getArgument(0, 1);
$amount = $this->argument(0)->between(0, 100)->value(1);
for ($i=0; $i < intval($amount); $i++) {
imagefilter($image->getCore(), IMG_FILTER_GAUSSIAN_BLUR);

View File

@@ -6,7 +6,7 @@ class BrightnessCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$level = $this->getArgument(0);
$level = $this->argument(0)->between(-100, 100)->required()->value();
return imagefilter($image->getCore(), IMG_FILTER_BRIGHTNESS, ($level * 2.55));
}

View File

@@ -6,9 +6,9 @@ class ColorizeCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$red = $this->getArgument(0);
$green = $this->getArgument(1);
$blue = $this->getArgument(2);
$red = $this->argument(0)->between(-100, 100)->required()->value();
$green = $this->argument(1)->between(-100, 100)->required()->value();
$blue = $this->argument(2)->between(-100, 100)->required()->value();
// normalize colorize levels
$red = round($red * 2.55);

View File

@@ -6,7 +6,7 @@ class ContrastCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$level = $this->getArgument(0);
$level = $this->argument(0)->between(-100, 100)->required()->value();
return imagefilter($image->getCore(), IMG_FILTER_CONTRAST, ($level * -1));
}

View File

@@ -9,10 +9,10 @@ class CropCommand extends ResizeCommand
{
public function execute($image)
{
$width = $this->getArgument(0);
$height = $this->getArgument(1);
$x = $this->getArgument(2);
$y = $this->getArgument(3);
$width = $this->argument(0)->type('integer')->required()->value();
$height = $this->argument(1)->type('integer')->required()->value();
$x = $this->argument(2)->type('integer')->value();
$y = $this->argument(3)->type('integer')->value();
if (is_null($width) || is_null($height)) {
throw new \Intervention\Image\Exception\InvalidArgumentException(

View File

@@ -9,9 +9,9 @@ class FillCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$filling = $this->getArgument(0);
$x = $this->getArgument(1);
$y = $this->getArgument(2);
$filling = $this->argument(0)->value();
$x = $this->argument(1)->type('integer')->value();
$y = $this->argument(2)->type('integer')->value();
$width = $image->getWidth();
$height = $image->getHeight();

View File

@@ -9,8 +9,8 @@ class FitCommand extends ResizeCommand
{
public function execute($image)
{
$width = $this->getArgument(0);
$height = $this->getArgument(1, $width);
$width = $this->argument(0)->type('integer')->value();
$height = $this->argument(1)->type('integer')->value($width);
// calculate size
$fitted = $image->getSize()->fit(new Size($width, $height));

View File

@@ -6,7 +6,7 @@ class FlipCommand extends ResizeCommand
{
public function execute($image)
{
$mode = strtolower($this->getArgument(0, 'h'));
$mode = $this->argument(0)->value('h');
$size = $image->getSize();
$dst = clone $size;

View File

@@ -6,7 +6,7 @@ class GammaCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$gamma = $this->getArgument(0);
$gamma = $this->argument(0)->type('numeric')->required()->value();
return imagegammacorrect($image->getCore(), 1, $gamma);
}

View File

@@ -6,7 +6,7 @@ class HeightenCommand extends ResizeCommand
{
public function execute($image)
{
$height = $this->getArgument(0);
$height = $this->argument(0)->type('integer')->required()->value();
$this->arguments[0] = null;
$this->arguments[1] = $height;

View File

@@ -6,10 +6,10 @@ class InsertCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$source = $this->getArgument(0);
$position = $this->getArgument(1);
$x = intval($this->getArgument(2));
$y = intval($this->getArgument(3));
$source = $this->argument(0)->value();
$position = $this->argument(1)->type('string')->value();
$x = $this->argument(2)->type('integer')->value(0);
$y = $this->argument(3)->type('integer')->value(0);
// build watermark
$watermark = $image->getDriver()->init($source);

View File

@@ -6,7 +6,7 @@ class InterlaceCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$mode = $this->getArgument(0, true);
$mode = $this->argument(0)->type('bool')->value(true);
imageinterlace($image->getCore(), $mode);

View File

@@ -8,8 +8,8 @@ class LimitColorsCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$count = $this->getArgument(0);
$matte = $this->getArgument(1);
$count = $this->argument(0)->value();
$matte = $this->argument(1)->value();
// get current image size
$size = $image->getSize();

View File

@@ -6,8 +6,8 @@ class MaskCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$mask_source = $this->getArgument(0);
$mask_w_alpha = (bool) $this->getArgument(1);
$mask_source = $this->argument(0)->value();
$mask_w_alpha = $this->argument(1)->type('bool')->value(false);
$image_size = $image->getSize();

View File

@@ -6,7 +6,7 @@ class OpacityCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$transparency = $this->getArgument(0);
$transparency = $this->argument(0)->between(0, 100)->required()->value();
// get size of image
$size = $image->getSize();

View File

@@ -8,9 +8,9 @@ class PickColorCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$x = $this->getArgument(0);
$y = $this->getArgument(1);
$format = $this->getArgument(2, 'array');
$x = $this->argument(0)->type('integer')->required()->value();
$y = $this->argument(1)->type('integer')->required()->value();
$format = $this->argument(2)->type('string')->value('array');
// pick color
$color = imagecolorat($image->getCore(), $x, $y);

View File

@@ -8,9 +8,10 @@ class PixelCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$color = new Color($this->getArgument(0));
$x = $this->getArgument(1);
$y = $this->getArgument(2);
$color = $this->argument(0)->required()->value();
$color = new Color($color);
$x = $this->argument(1)->type('integer')->required()->value();
$y = $this->argument(2)->type('integer')->required()->value();
return imagesetpixel($image->getCore(), $x, $y, $color->getInt());
}

View File

@@ -6,7 +6,7 @@ class PixelateCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$size = $this->getArgument(0, 10);
$size = $this->argument(0)->type('integer')->value(10);
return imagefilter($image->getCore(), IMG_FILTER_PIXELATE, $size, true);
}

View File

@@ -9,11 +9,11 @@ class ResizeCanvasCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$width = $this->getArgument(0);
$height = $this->getArgument(1);
$anchor = $this->getArgument(2) ? $this->getArgument(2) : 'center';
$relative = $this->getArgument(3);
$bgcolor = $this->getArgument(4);
$width = $this->argument(0)->type('integer')->required()->value();
$height = $this->argument(1)->type('integer')->required()->value();
$anchor = $this->argument(2)->value('center');
$relative = $this->argument(3)->type('boolean')->value();
$bgcolor = $this->argument(4)->value();
$original_width = $image->getWidth();
$original_height = $image->getHeight();

View File

@@ -6,9 +6,9 @@ class ResizeCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$width = $this->getArgument(0);
$height = $this->getArgument(1);
$constraints = $this->getArgument(2);
$width = $this->argument(0)->value();
$height = $this->argument(1)->value();
$constraints = $this->argument(2)->type('closure')->value();
// resize box
$resized = $image->getSize()->resize($width, $height, $constraints);

View File

@@ -8,8 +8,9 @@ class RotateCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$angle = $this->getArgument(0);
$color = new Color($this->getArgument(1));
$angle = $this->argument(0)->type('numeric')->required()->value();
$color = $this->argument(1)->value();
$color = new Color($color);
// rotate image
$image->setCore(imagerotate($image->getCore(), $angle, $color->getInt()));

View File

@@ -8,10 +8,10 @@ class TrimCommand extends ResizeCommand
{
public function execute($image)
{
$base = $this->getArgument(0);
$away = $this->getArgument(1);
$tolerance = intval($this->getArgument(2, 0));
$feather = intval($this->getArgument(3, 0));
$base = $this->argument(0)->type('string')->value();
$away = $this->argument(1)->value();
$tolerance = $this->argument(2)->type('numeric')->value(0);
$feather = $this->argument(3)->type('numeric')->value(0);
$width = $image->getWidth();
$height = $image->getHeight();

View File

@@ -6,7 +6,7 @@ class WidenCommand extends ResizeCommand
{
public function execute($image)
{
$width = $this->getArgument(0);
$width = $this->argument(0)->type('integer')->required()->value();
$this->arguments[0] = $width;
$this->arguments[1] = null;

View File

@@ -6,7 +6,7 @@ class BlurCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$amount = intval($this->getArgument(0, 1));
$amount = $this->argument(0)->between(0, 100)->value(1);
return $image->getCore()->blurImage(1 * $amount, 0.5 * $amount);
}

View File

@@ -6,7 +6,7 @@ class BrightnessCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$level = $this->getArgument(0);
$level = $this->argument(0)->between(-100, 100)->required()->value();
return $image->getCore()->modulateImage(100 + $level, 100, 100);
}

View File

@@ -6,9 +6,9 @@ class ColorizeCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$red = $this->getArgument(0);
$green = $this->getArgument(1);
$blue = $this->getArgument(2);
$red = $this->argument(0)->between(-100, 100)->required()->value();
$green = $this->argument(1)->between(-100, 100)->required()->value();
$blue = $this->argument(2)->between(-100, 100)->required()->value();
// normalize colorize levels
$red = $this->normalizeLevel($red);

View File

@@ -6,7 +6,7 @@ class ContrastCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$level = $this->getArgument(0);
$level = $this->argument(0)->between(-100, 100)->required()->value();
return $image->getCore()->sigmoidalContrastImage($level > 0, $level / 4, 0);
}

View File

@@ -9,10 +9,10 @@ class CropCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$width = $this->getArgument(0);
$height = $this->getArgument(1);
$x = $this->getArgument(2);
$y = $this->getArgument(3);
$width = $this->argument(0)->type('integer')->required()->value();
$height = $this->argument(1)->type('integer')->required()->value();
$x = $this->argument(2)->type('integer')->value();
$y = $this->argument(3)->type('integer')->value();
if (is_null($width) || is_null($height)) {
throw new \Intervention\Image\Exception\InvalidArgumentException(

View File

@@ -10,9 +10,9 @@ class FillCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$filling = $this->getArgument(0);
$x = $this->getArgument(1);
$y = $this->getArgument(2);
$filling = $this->argument(0)->value();
$x = $this->argument(1)->type('integer')->value();
$y = $this->argument(2)->type('integer')->value();
$imagick = $image->getCore();

View File

@@ -8,8 +8,8 @@ class FitCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$width = $this->getArgument(0);
$height = $this->getArgument(1, $width);
$width = $this->argument(0)->type('integer')->value();
$height = $this->argument(1)->type('integer')->value($width);
// calculate size
$fitted = $image->getSize()->fit(new Size($width, $height));

View File

@@ -6,7 +6,7 @@ class FlipCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$mode = strtolower($this->getArgument(0, 'h'));
$mode = $this->argument(0)->value('h');
if (in_array(strtolower($mode), array(2, 'v', 'vert', 'vertical'))) {
// flip vertical

View File

@@ -6,7 +6,7 @@ class GammaCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$gamma = $this->getArgument(0);
$gamma = $this->argument(0)->type('numeric')->required()->value();
return $image->getCore()->gammaImage($gamma);
}

View File

@@ -6,7 +6,7 @@ class HeightenCommand extends ResizeCommand
{
public function execute($image)
{
$height = $this->getArgument(0);
$height = $this->argument(0)->type('integer')->required()->value();
$this->arguments[0] = null;
$this->arguments[1] = $height;

View File

@@ -8,10 +8,10 @@ class InsertCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$source = $this->getArgument(0);
$position = $this->getArgument(1);
$x = intval($this->getArgument(2));
$y = intval($this->getArgument(3));
$source = $this->argument(0)->value();
$position = $this->argument(1)->type('string')->value();
$x = $this->argument(2)->type('integer')->value(0);
$y = $this->argument(3)->type('integer')->value(0);
// build watermark
$watermark = $image->getDriver()->init($source);

View File

@@ -6,7 +6,7 @@ class InterlaceCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$mode = $this->getArgument(0, true);
$mode = $this->argument(0)->type('bool')->value(true);
if ($mode) {
$mode = \Imagick::INTERLACE_LINE;

View File

@@ -6,8 +6,8 @@ class LimitColorsCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$count = $this->getArgument(0);
$matte = $this->getArgument(1);
$count = $this->argument(0)->value();
$matte = $this->argument(1)->value();
// get current image size
$size = $image->getSize();

View File

@@ -6,8 +6,8 @@ class MaskCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$mask_source = $this->getArgument(0);
$mask_w_alpha = (bool) $this->getArgument(1);
$mask_source = $this->argument(0)->value();
$mask_w_alpha = $this->argument(1)->type('bool')->value(false);
// get imagick
$imagick = $image->getCore();

View File

@@ -6,7 +6,7 @@ class OpacityCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$transparency = $this->getArgument(0);
$transparency = $this->argument(0)->between(0, 100)->required()->value();
return $image->getCore()->setImageOpacity($transparency / 100);
}

View File

@@ -8,9 +8,9 @@ class PickColorCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$x = $this->getArgument(0, 0);
$y = $this->getArgument(1, 0);
$format = $this->getArgument(2, 'array');
$x = $this->argument(0)->type('integer')->required()->value();
$y = $this->argument(1)->type('integer')->required()->value();
$format = $this->argument(2)->type('string')->value('array');
// pick color
$color = new Color($image->getCore()->getImagePixelColor($x, $y));

View File

@@ -8,9 +8,10 @@ class PixelCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$color = new Color($this->getArgument(0));
$x = $this->getArgument(1);
$y = $this->getArgument(2);
$color = $this->argument(0)->required()->value();
$color = new Color($color);
$x = $this->argument(1)->type('integer')->required()->value();
$y = $this->argument(2)->type('integer')->required()->value();
// prepare pixel
$draw = new \ImagickDraw;

View File

@@ -6,7 +6,7 @@ class PixelateCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$size = intval($this->getArgument(0, 10));
$size = $this->argument(0)->type('integer')->value(10);
$width = $image->getWidth();
$height = $image->getHeight();

View File

@@ -6,11 +6,11 @@ class ResizeCanvasCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$width = $this->getArgument(0);
$height = $this->getArgument(1);
$anchor = $this->getArgument(2) ? $this->getArgument(2) : 'center';
$relative = $this->getArgument(3);
$bgcolor = $this->getArgument(4);
$width = $this->argument(0)->type('integer')->required()->value();
$height = $this->argument(1)->type('integer')->required()->value();
$anchor = $this->argument(2)->value('center');
$relative = $this->argument(3)->type('boolean')->value();
$bgcolor = $this->argument(4)->value();
$original_width = $image->getWidth();
$original_height = $image->getHeight();

View File

@@ -6,9 +6,9 @@ class ResizeCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$width = $this->getArgument(0);
$height = $this->getArgument(1);
$constraints = $this->getArgument(2);
$width = $this->argument(0)->value();
$height = $this->argument(1)->value();
$constraints = $this->argument(2)->type('closure')->value();
// resize box
$resized = $image->getSize()->resize($width, $height, $constraints);

View File

@@ -8,8 +8,9 @@ class RotateCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$angle = $this->getArgument(0);
$color = new Color($this->getArgument(1));
$angle = $this->argument(0)->type('numeric')->required()->value();
$color = $this->argument(1)->value();
$color = new Color($color);
// rotate image
$image->getCore()->rotateImage($color->getPixel(), ($angle * -1));

View File

@@ -8,10 +8,10 @@ class TrimCommand extends \Intervention\Image\Commands\AbstractCommand
{
public function execute($image)
{
$base = $this->getArgument(0);
$away = $this->getArgument(1);
$tolerance = intval($this->getArgument(2, 0));
$feather = intval($this->getArgument(3, 0));
$base = $this->argument(0)->type('string')->value();
$away = $this->argument(1)->value();
$tolerance = $this->argument(2)->type('numeric')->value(0);
$feather = $this->argument(3)->type('numeric')->value(0);
$width = $image->getWidth();
$height = $image->getHeight();

View File

@@ -6,7 +6,7 @@ class WidenCommand extends ResizeCommand
{
public function execute($image)
{
$width = $this->getArgument(0);
$width = $this->argument(0)->type('integer')->required()->value();
$this->arguments[0] = $width;
$this->arguments[1] = null;

View File

@@ -7,11 +7,11 @@ class AbstractCommandTest extends PHPUnit_Framework_TestCase
Mockery::close();
}
public function testGetArgument()
public function testArgument()
{
$command = $this->getTestCommand();
$this->assertEquals('foo', $command->getArgument(0));
$this->assertEquals('bar', $command->getArgument(1));
$this->assertEquals('foo', $command->argument(0)->value());
$this->assertEquals('bar', $command->argument(1)->value());
}
public function testGetOutput()

View File

@@ -25,6 +25,10 @@ class ArgumentTest extends PHPUnit_Framework_TestCase
$arg = new Argument($this->getMockedCommand(array(null)));
$arg->required();
$this->validateArgument($arg, null);
$arg = new Argument($this->getMockedCommand(array(0)));
$arg->required();
$this->validateArgument($arg, 0);
}
/**
@@ -85,6 +89,30 @@ class ArgumentTest extends PHPUnit_Framework_TestCase
$arg->type('numeric');
}
public function testTypeBooleanPass()
{
$arg = new Argument($this->getMockedCommand(array()));
$arg->type('boolean');
$this->validateArgument($arg, null);
$arg = new Argument($this->getMockedCommand(array(true)));
$arg->type('boolean');
$this->validateArgument($arg, true);
$arg = new Argument($this->getMockedCommand(array(false)));
$arg->type('boolean');
$this->validateArgument($arg, false);
}
/**
* @expectedException \Intervention\Image\Exception\InvalidArgumentException
*/
public function testTypeBooleanFail()
{
$arg = new Argument($this->getMockedCommand(array('foo')));
$arg->type('boolean');
}
public function testTypeStringPass()
{
$arg = new Argument($this->getMockedCommand(array()));

View File

@@ -17,7 +17,7 @@ class CircleCommandTest extends PHPUnit_Framework_TestCase
$image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getDriver')->once()->andReturn($driver);
$image->shouldReceive('getCore')->once()->andReturn($resource);
$command = new CircleCommand(10, 20, 250);
$command = new CircleCommand(array(10, 20, 250));
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertFalse($command->hasOutput());
@@ -33,7 +33,7 @@ class CircleCommandTest extends PHPUnit_Framework_TestCase
$image->shouldReceive('getDriver')->once()->andReturn($driver);
$image->shouldReceive('getCore')->once()->andReturn($imagick);
$command = new CircleCommand(10, 20, 250);
$command = new CircleCommand(array(10, 20, 250));
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertFalse($command->hasOutput());

View File

@@ -17,7 +17,7 @@ class EllipseCommandTest extends PHPUnit_Framework_TestCase
$image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getDriver')->once()->andReturn($driver);
$image->shouldReceive('getCore')->once()->andReturn($resource);
$command = new EllipseCommand(10, 20, 250, 150);
$command = new EllipseCommand(array(10, 20, 250, 150));
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertFalse($command->hasOutput());
@@ -33,7 +33,7 @@ class EllipseCommandTest extends PHPUnit_Framework_TestCase
$image->shouldReceive('getDriver')->once()->andReturn($driver);
$image->shouldReceive('getCore')->once()->andReturn($imagick);
$command = new EllipseCommand(10, 20, 250, 150);
$command = new EllipseCommand(array(10, 20, 250, 150));
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertFalse($command->hasOutput());

View File

@@ -10,19 +10,6 @@ class PickColorCommandTest extends PHPUnit_Framework_TestCase
Mockery::close();
}
public function testGd()
{
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$image = Mockery::mock('Intervention\Image\Image');
$image->shouldReceive('getCore')->times(2)->andReturn($resource);
$command = new PickColorGd(array());
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertTrue($command->hasOutput());
$this->assertInternalType('array', $command->getOutput());
$this->assertEquals(4, count($command->getOutput()));
}
public function testGdWithCoordinates()
{
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
@@ -49,20 +36,6 @@ class PickColorCommandTest extends PHPUnit_Framework_TestCase
$this->assertEquals('#ffffff', $command->getOutput());
}
public function testImagick()
{
$imagick = Mockery::mock('Imagick');
$imagick->shouldReceive('getimagepixelcolor')->with(0, 0)->andReturn(new ImagickPixel);
$image = Mockery::mock('Intervention\Image\Image');
$image->shouldReceive('getCore')->once()->andReturn($imagick);
$command = new PickColorImagick(array());
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertTrue($command->hasOutput());
$this->assertInternalType('array', $command->getOutput());
$this->assertEquals(4, count($command->getOutput()));
}
public function testImagickWithCoordinates()
{
$imagick = Mockery::mock('Imagick');

View File

@@ -17,7 +17,7 @@ class TextCommandTest extends PHPUnit_Framework_TestCase
$image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getDriver')->once()->andReturn($driver);
$image->shouldReceive('getCore')->once()->andReturn($resource);
$command = new TextCommand('test', 10, 20);
$command = new TextCommand(array('test', 10, 20));
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertFalse($command->hasOutput());