blessing-skin-server/tests/ListenersTest/CacheSkinPreviewTest.php

43 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Tests;
use Cache;
use Event;
use Mockery;
use Storage;
use App\Models\Texture;
use App\Events\GetSkinPreview;
use Illuminate\Http\UploadedFile;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CacheSkinPreviewTest extends TestCase
{
use DatabaseTransactions;
public function testHandle()
{
2019-04-05 09:19:08 +08:00
option(['enable_preview_cache' => true]);
$provider = new \App\Providers\EventServiceProvider(app());
$provider->boot();
2019-04-03 23:16:23 +08:00
Storage::fake('textures');
$skin = factory(Texture::class)->create();
Storage::disk('textures')
->putFileAs('.', UploadedFile::fake()->image($skin->hash), $skin->hash);
$mock = Mockery::mock('overload:Minecraft');
$mock->shouldReceive('generatePreviewFromSkin')->andReturn(imagecreatetruecolor(1, 1));
event(new GetSkinPreview($skin, 45));
$this->assertTrue(Cache::has("preview-{$skin->tid}-45"));
$cape = factory(Texture::class, 'cape')->create();
Storage::disk('textures')
->putFileAs('.', UploadedFile::fake()->image($cape->hash), $cape->hash);
$mock->shouldReceive('generatePreviewFromCape')->andReturn(imagecreatetruecolor(1, 1));
event(new GetSkinPreview($cape, 45));
$this->assertTrue(Cache::has("preview-{$cape->tid}-45"));
}
}