Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Apr 17, 2021
1 parent 052b05a commit 1843fa8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 91 deletions.
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
}
],
"require": {
"php": ">=7.3",
"php": "^7.3",
"imagine/imagine": "^1.2",
"orchestra/support-core": "^6.0",
"orchestra/support-providers": "^6.0"
},
"require-dev": {
"illuminate/bus": "^8.0",
"illuminate/container": "^8.0",
"mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^9.0"
"orchestra/testbench": "^6.15"
},
"autoload": {
"psr-4": {
Expand Down
105 changes: 19 additions & 86 deletions tests/ImagineServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,26 @@
use Illuminate\Container\Container;
use Mockery as m;
use Orchestra\Imagine\ImagineServiceProvider;
use PHPUnit\Framework\TestCase;
use Orchestra\Testbench\TestCase;

class ImagineServiceProviderTest extends TestCase
{
/**
* Teardown the test environment.
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
public function tearDown(): void
protected function getPackageProviders($app)
{
m::close();
return [ImagineServiceProvider::class];
}

/** @test */
public function it_can_register_expected_services()
{
$app = m::mock('Illuminate\Container\Container, \Illuminate\Contracts\Foundation\Application')->makePartial();
$config = m::mock('Illuminate\Contracts\Config\Repository');
$app->instance('config', $config);

$config->shouldReceive('get')->once()->with('orchestra.imagine')->andReturn([]);

$stub = new ImagineServiceProvider($app);
$stub->register();

$this->assertInstanceOf('Orchestra\Imagine\ImagineManager', $app['orchestra.imagine']);
$this->assertInstanceOf('Orchestra\Imagine\ImagineManager', $this->app['orchestra.imagine']);
}

/**
Expand All @@ -38,29 +33,9 @@ public function it_can_register_expected_services()
*/
public function it_can_boot_using_gd()
{
$app = m::mock('Illuminate\Container\Container, \Illuminate\Contracts\Foundation\Application')->makePartial();
$config = m::mock('Illuminate\Contracts\Config\Repository');
$files = m::mock('Illuminate\Filesystem\Filesystem');

$app->instance('config', $config);
$app->instance('files', $files);

$app->shouldReceive('basePath')->andReturn(__DIR__.'/../');

$files->shouldReceive('isDirectory')->andReturn(false);
$config->shouldReceive('get')->once()->with('orchestra.imagine')->andReturn(['driver' => 'gd']);

$stub = m::mock('Orchestra\Imagine\ImagineServiceProvider[bootUsingLaravel]', [$app])
->shouldAllowMockingProtectedMethods();

$stub->shouldReceive('bootUsingLaravel')->once()->with(realpath(__DIR__.'/../'))->andReturnNull();

$stub->register();
$stub->boot();

$this->assertInstanceOf('Imagine\Gd\Imagine', $app->make('Imagine\Image\ImagineInterface'));
$this->assertInstanceOf('Imagine\Gd\Imagine', $app['orchestra.imagine']->driver());
$this->assertInstanceOf('Imagine\Gd\Imagine', $app['orchestra.imagine']->driver('gd'));
$this->assertInstanceOf('Imagine\Gd\Imagine', $this->app->make('Imagine\Image\ImagineInterface'));
$this->assertInstanceOf('Imagine\Gd\Imagine', $this->app['orchestra.imagine']->driver());
$this->assertInstanceOf('Imagine\Gd\Imagine', $this->app['orchestra.imagine']->driver('gd'));
}

/**
Expand All @@ -69,29 +44,9 @@ public function it_can_boot_using_gd()
*/
public function it_can_boot_using_imagick()
{
$app = m::mock('Illuminate\Container\Container, \Illuminate\Contracts\Foundation\Application')->makePartial();
$config = m::mock('Illuminate\Contracts\Config\Repository');
$files = m::mock('Illuminate\Filesystem\Filesystem');

$app->instance('config', $config);
$app->instance('files', $files);

$app->shouldReceive('basePath')->andReturn(__DIR__.'/../');

$files->shouldReceive('isDirectory')->andReturn(false);
$config->shouldReceive('get')->once()->with('orchestra.imagine')->andReturn(['driver' => 'imagick']);

$stub = m::mock('Orchestra\Imagine\ImagineServiceProvider[bootUsingLaravel]', [$app])
->shouldAllowMockingProtectedMethods();

$stub->shouldReceive('bootUsingLaravel')->once()->with(realpath(__DIR__.'/../'))->andReturnNull();

$stub->register();
$stub->boot();

$this->assertInstanceOf('Imagine\Imagick\Imagine', $app->make('Imagine\Image\ImagineInterface'));
$this->assertInstanceOf('Imagine\Imagick\Imagine', $app['orchestra.imagine']->driver());
$this->assertInstanceOf('Imagine\Imagick\Imagine', $app['orchestra.imagine']->driver('imagick'));
$this->assertInstanceOf('Imagine\Imagick\Imagine', $this->app->make('Imagine\Image\ImagineInterface'));
$this->assertInstanceOf('Imagine\Imagick\Imagine', $this->app['orchestra.imagine']->driver());
$this->assertInstanceOf('Imagine\Imagick\Imagine', $this->app['orchestra.imagine']->driver('imagick'));
}

/**
Expand All @@ -100,38 +55,16 @@ public function it_can_boot_using_imagick()
*/
public function it_can_boot_using_gmagick()
{
$app = m::mock('Illuminate\Container\Container, \Illuminate\Contracts\Foundation\Application')->makePartial();
$config = m::mock('Illuminate\Contracts\Config\Repository');
$files = m::mock('Illuminate\Filesystem\Filesystem');

$app->instance('config', $config);
$app->instance('files', $files);

$app->shouldReceive('basePath')->andReturn(__DIR__.'/../');

$files->shouldReceive('isDirectory')->andReturn(false);
$config->shouldReceive('get')->once()->with('orchestra.imagine')->andReturn(['driver' => 'gmagick']);

$stub = m::mock('Orchestra\Imagine\ImagineServiceProvider[bootUsingLaravel]', [$app])
->shouldAllowMockingProtectedMethods();

$stub->shouldReceive('bootUsingLaravel')->once()->with(realpath(__DIR__.'/../'))->andReturnNull();

$stub->register();
$stub->boot();

$this->assertInstanceOf('Imagine\Gmagick\Imagine', $app->make('Imagine\Image\ImagineInterface'));
$this->assertInstanceOf('Imagine\Gmagick\Imagine', $app['orchestra.imagine']->driver());
$this->assertInstanceOf('Imagine\Gmagick\Imagine', $app['orchestra.imagine']->driver('gmagick'));
$this->assertInstanceOf('Imagine\Gmagick\Imagine', $this->app->make('Imagine\Image\ImagineInterface'));
$this->assertInstanceOf('Imagine\Gmagick\Imagine', $this->app['orchestra.imagine']->driver());
$this->assertInstanceOf('Imagine\Gmagick\Imagine', $this->app['orchestra.imagine']->driver('gmagick'));
}

/** @test */
public function it_provides_expected_services()
{
$app = new Container();

$stub = new ImagineServiceProvider($app);

$this->assertContains('orchestra.imagine', $stub->provides());
$this->assertContains('orchestra.imagine', with(new ImagineServiceProvider($app))->provides());
}
}

0 comments on commit 1843fa8

Please sign in to comment.