/** * @inheritDoc */ public function uploads() { return $this->morphMany(Upload::getModelClass(), 'uploadable'); }
/** * Get Uploads * * The Uploads related to this Model. * @return Illuminate\Support\Collection */ public function getUploads() { return Cache::tags($this->getTags('uploads'))->remember($this->getCacheId('uploads'), self::CACHE_LONG, function () { $uploads = $this->uploads()->get(); if ($uploads->count()) { $uploads = $uploads->map(function ($upload) { return Upload::make($upload); }); } return $uploads; }); }
/** * @inheritDoc */ public function boot() { $this->publishes([__DIR__ . '/../resources/migrations/' => database_path('migrations')], 'migrations'); Facade::boot(); }
public function testUploads() { $model = 'C4tech\\Upload\\Model'; Upload::shouldReceive('getModelClass')->withNoArgs()->once()->andReturn($model); $this->verifyMorphMany('uploads', $model, 'uploadable'); }
public function testGetUploads() { $tag = 'test-tag'; $object = Mockery::mock('C4tech\\Upload\\Contracts\\UploadModelInterface'); $new_object = 'Demo!'; $collection = Mockery::mock('Illuminate\\Support\\Collection[map]', [[$object]]); $new_collection = 'TestCollection'; $this->repo->shouldReceive('getTags')->with('uploads')->once()->andReturn([$tag]); $this->repo->shouldReceive('getCacheId')->with('uploads')->once()->andReturn($tag); $this->repo->shouldReceive('uploads->get')->withNoArgs()->once()->andReturn($collection); Upload::shouldReceive('make')->with($object)->once()->andReturn($new_object); $collection->shouldReceive('map')->with(Mockery::on(function ($closure) use($object, $new_object) { expect($closure($object))->equals($new_object); return true; }))->once()->andReturn($new_collection); Cache::shouldReceive('tags->remember')->with([$tag])->with($tag, Mockery::type('integer'), Mockery::on(function ($closure) use($new_collection) { expect($closure())->equals($new_collection); return true; }))->once()->andReturn(true); expect($this->repo->getUploads())->true(); }