Skip to content

Commit

Permalink
Rename conversion repository to conversion registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack97 committed Apr 24, 2019
1 parent a692c32 commit 4887270
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 127 deletions.
2 changes: 1 addition & 1 deletion src/ConversionManager.php → src/ConversionRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Optix\Media\Exceptions\InvalidConversion;

class ConversionManager
class ConversionRegistry
{
protected $conversions = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Facades/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Optix\Media\Facades;

use Optix\Media\ConversionManager;
use Optix\Media\ConversionRegistry;
use Illuminate\Support\Facades\Facade;

class Conversion extends Facade
Expand All @@ -14,6 +14,6 @@ class Conversion extends Facade
*/
protected static function getFacadeAccessor()
{
return ConversionManager::class;
return ConversionRegistry::class;
}
}
8 changes: 4 additions & 4 deletions src/ImageManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

class ImageManipulator
{
protected $conversionManager;
protected $conversionRegistry;

protected $imageManager;

public function __construct(ConversionManager $conversionManager, ImageManager $imageManager)
public function __construct(ConversionRegistry $conversionRegistry, ImageManager $imageManager)
{
$this->conversionManager = $conversionManager;
$this->conversionRegistry = $conversionRegistry;

$this->imageManager = $imageManager;
}
Expand All @@ -31,7 +31,7 @@ public function manipulate(Media $media, array $conversions, $onlyIfMissing = tr
continue;
}

$converter = $this->conversionManager->get($conversion);
$converter = $this->conversionRegistry->get($conversion);

$image = $converter($this->imageManager->make($media->getFullPath()));

Expand Down
2 changes: 1 addition & 1 deletion src/MediaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function register()
__DIR__ . '/../config/media.php', 'media'
);

$this->app->singleton(ConversionManager::class);
$this->app->singleton(ConversionRegistry::class);
}
}
81 changes: 0 additions & 81 deletions tests/ConversionManagerTest.php

This file was deleted.

81 changes: 81 additions & 0 deletions tests/ConversionRegistryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Optix\Media\Tests;

use Optix\Media\ConversionRegistry;
use Optix\Media\Exceptions\InvalidConversion;

class ConversionRegistryTest extends TestCase
{
/** @test */
public function it_can_register_and_retrieve_specific_conversions()
{
$conversionRegistry = new ConversionRegistry();

$conversionRegistry->register('conversion', function () {
return true;
});

$conversion = $conversionRegistry->get('conversion');

$this->assertTrue($conversion());
}

/** @test */
public function it_can_retrieve_all_the_registered_conversions()
{
$conversionRegistry = new ConversionRegistry();

$conversionRegistry->register('one', function () {
return 'one';
});

$conversionRegistry->register('two', function () {
return 'two';
});

$conversions = $conversionRegistry->all();

$this->assertCount(2, $conversions);
$this->assertEquals('one', $conversions['one']());
$this->assertEquals('two', $conversions['two']());
}

/** @test */
public function there_can_only_be_one_conversion_registered_with_the_same_name()
{
$conversionRegistry = new ConversionRegistry();

$conversionRegistry->register('conversion', function () {
return 'one';
});

$conversionRegistry->register('conversion', function () {
return 'two';
});

$this->assertCount(1, $conversionRegistry->all());
$this->assertEquals('two', $conversionRegistry->get('conversion')());
}

/** @test */
public function it_can_determine_if_a_conversion_has_been_registered()
{
$conversionRegistry = new ConversionRegistry();

$conversionRegistry->register('registered', function () {});

$this->assertTrue($conversionRegistry->exists('registered'));
$this->assertFalse($conversionRegistry->exists('unregistered'));
}

/** @test */
public function it_will_error_when_attempting_to_retrieve_an_unregistered_conversion()
{
$this->expectException(InvalidConversion::class);

$conversionRegistry = new ConversionRegistry();

$conversionRegistry->get('unregistered');
}
}
24 changes: 12 additions & 12 deletions tests/ImageManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Intervention\Image\Image;
use Optix\Media\Models\Media;
use Optix\Media\ImageManipulator;
use Optix\Media\ConversionManager;
use Optix\Media\ConversionRegistry;
use Intervention\Image\ImageManager;
use Illuminate\Filesystem\Filesystem;
use Optix\Media\Exceptions\InvalidConversion;
Expand All @@ -16,9 +16,9 @@ class ImageManipulatorTest extends TestCase
/** @test */
public function it_will_apply_registered_conversions()
{
$conversionManager = new ConversionManager();
$conversionRegistry = new ConversionRegistry();

$conversionManager->register('resize', function (Image $image) {
$conversionRegistry->register('resize', function (Image $image) {
return $image->resize(64);
});

Expand All @@ -33,7 +33,7 @@ public function it_will_apply_registered_conversions()
$imageManager = Mockery::mock(ImageManager::class);
$imageManager->shouldReceive('make')->once()->andReturn($image);

$manipulator = new ImageManipulator($conversionManager, $imageManager);
$manipulator = new ImageManipulator($conversionRegistry, $imageManager);

$media = Mockery::mock(Media::class)->makePartial();
$media->file_name = 'file-name.png';
Expand All @@ -53,9 +53,9 @@ public function it_will_apply_registered_conversions()
/** @test */
public function it_will_only_apply_conversions_to_an_image()
{
$conversionManager = new ConversionManager();
$conversionRegistry = new ConversionRegistry();

$conversionManager->register('resize', function ($image) {
$conversionRegistry->register('resize', function ($image) {
return $image->resize(64);
});

Expand All @@ -64,7 +64,7 @@ public function it_will_only_apply_conversions_to_an_image()
// Assert that the conversion was not applied...
$imageManager->shouldNotReceive('make');

$manipulator = new ImageManipulator($conversionManager, $imageManager);
$manipulator = new ImageManipulator($conversionRegistry, $imageManager);

$media = new Media(['mime_type' => 'text/html']);

Expand All @@ -76,14 +76,14 @@ public function it_will_ignore_unregistered_conversions()
{
$this->expectException(InvalidConversion::class);

$conversionManager = new ConversionManager();
$conversionRegistry = new ConversionRegistry();

$imageManager = Mockery::mock(ImageManager::class);

// Assert that the conversion was not applied...
$imageManager->shouldNotReceive('make');

$manipulator = new ImageManipulator($conversionManager, $imageManager);
$manipulator = new ImageManipulator($conversionRegistry, $imageManager);

$media = new Media(['mime_type' => 'image/png']);

Expand All @@ -93,9 +93,9 @@ public function it_will_ignore_unregistered_conversions()
/** @test */
public function it_will_skip_conversions_if_the_converted_image_already_exists()
{
$conversionManager = new ConversionManager();
$conversionRegistry = new ConversionRegistry();

$conversionManager->register('resize', function (Image $image) use (&$conversionApplied) {
$conversionRegistry->register('resize', function (Image $image) use (&$conversionApplied) {
return $image;
});

Expand All @@ -104,7 +104,7 @@ public function it_will_skip_conversions_if_the_converted_image_already_exists()
// Assert that the conversion was not applied...
$imageManager->shouldNotReceive('make');

$manipulator = new ImageManipulator($conversionManager, $imageManager);
$manipulator = new ImageManipulator($conversionRegistry, $imageManager);

$media = Mockery::mock(Media::class)->makePartial();
$media->file_name = 'file-name.png';
Expand Down
27 changes: 1 addition & 26 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ protected function setUp()
{
parent::setUp();

$this->withFactories(__DIR__ . '/database/factories');

$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
$this->withFactories(__DIR__ . '/database/factories');
}

protected function getPackageProviders($app)
Expand All @@ -32,28 +31,4 @@ protected function getEnvironmentSetUp($app)
'prefix' => ''
]);
}

// protected function setUpDatabase($app)
// {
// $schema = $app['db']->connection()->getSchemaBuilder();
//
// $schema->create('test_models', function (Blueprint $table) {
// $table->increments('id');
// $table->timestamps();
// });
//
// $schema->create('custom_media', function (Blueprint $table) {
// $table->increments('id');
// $table->string('name');
// $table->string('file_name');
// $table->string('disk');
// $table->string('mime_type');
// $table->unsignedInteger('size');
// $table->string('custom_attribute');
// $table->timestamps();
// });
//
// require_once __DIR__ . '/../database/migrations/create_media_table.stub';
// (new \CreateMediaTable())->up();
// }
}

0 comments on commit 4887270

Please sign in to comment.