Skip to content

Commit

Permalink
Merge pull request #3 from diamonddevgroup/move-facade-phpdocs
Browse files Browse the repository at this point in the history
Moves methods to class-level and makes them static
  • Loading branch information
olivervogel authored Feb 4, 2024
2 parents 8392765 + 53a9d2e commit 13d018b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor/
.phpunit.result.cache
composer.lock
phpunit.xml
coverage/
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"intervention/image": "^3"
},
"require-dev": {
"phpunit/phpunit": "^9"
"phpunit/phpunit": "^9",
"orchestra/testbench": "^8.18"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion config/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| Image Driver
|--------------------------------------------------------------------------
|
| Intervention Image supports "GD Library" and "Imagick" to process images
| Intervention Image supports GD Library and Imagick to process images
| internally. Depending on your PHP setup, you can choose one of them.
|
| Included options:
Expand Down
6 changes: 3 additions & 3 deletions src/Facades/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Illuminate\Support\Facades\Facade;

/**
* @method \Intervention\Image\ImageManager static read(mixed $input, string|array|DecoderInterface $decoders = [])
* @method \Intervention\Image\ImageManager static create(int $width, int $height)
* @method \Intervention\Image\ImageManager static animate(callable $callback)
* @method static \Intervention\Image\Interfaces\ImageInterface read(mixed $input, string|array|\Intervention\Image\Interfaces\DecoderInterface $decoders = [])
* @method static \Intervention\Image\Interfaces\ImageInterface create(int $width, int $height)
* @method static \Intervention\Image\Interfaces\ImageInterface animate(callable $callback)
*/
class Image extends Facade
{
Expand Down
2 changes: 2 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
providers:
- Intervention\Image\Laravel\ServiceProvider
58 changes: 55 additions & 3 deletions tests/FacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,75 @@

namespace Intervention\Image\Laravel\Tests;

use PHPUnit\Framework\TestCase;
use Error;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Laravel\Facades\Image;
use ReflectionClass;
use TypeError;
use ValueError;

class FacadeTest extends TestCase
{
public function testFacade()
public function testImageFacadeIsASubclassOfFacade(): void
{
$facade = new ReflectionClass('Illuminate\Support\Facades\Facade');
$reflection = new ReflectionClass('Intervention\Image\Laravel\Facades\Image');
$this->assertTrue($reflection->isSubclassOf($facade));
}

public function testFacadeAccessor()
public function testFacadeAccessorReturnsImage(): void
{
$reflection = new ReflectionClass('Intervention\Image\Laravel\Facades\Image');
$method = $reflection->getMethod('getFacadeAccessor');
$method->setAccessible(true);
$this->assertSame('image', $method->invoke(null));
}

public function testReadAnImage(): void
{
Storage::fake('images');
$input = UploadedFile::fake()->image('image.jpg');
$result = Image::read($input);
$this->assertInstanceOf(ImageInterface::class, $result);
}

public function testThrowsExceptionWhenReadingNonExistentImage(): void
{
$this->expectException(DecoderException::class);
$input = 'path/to/non_existent_image.jpg';
Image::read($input);
}

public function testCreateAnImage(): void
{
$width = 200;
$height = 200;
$result = Image::create($width, $height);
$this->assertInstanceOf(ImageInterface::class, $result);
}

public function testThrowsExceptionWhenCreatingImageWithInvalidDimensions(): void
{
$this->expectException(ValueError::class);
$width = -200;
$height = 200;
Image::create($width, $height);
}

public function testAnimateAnImage(): void
{
$callback = function () {};
$result = Image::animate($callback);
$this->assertInstanceOf(ImageInterface::class, $result);
}

public function testThrowsExceptionWhenAnimatingImageWithInvalidCallback(): void
{
$this->expectException(TypeError::class);
$callback = 'not_callable';
Image::animate($callback);
}
}
13 changes: 13 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Intervention\Image\Laravel\Tests;

use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase as TestBenchTestCase;

abstract class TestCase extends TestBenchTestCase
{
use WithWorkbench;
}

0 comments on commit 13d018b

Please sign in to comment.