/** * Build a storage instance. * * @param AttachedFile $attachment * @return \Codesleeve\Stapler\Storage\StorageableInterface */ public static function create(AttachedFile $attachment) { switch ($attachment->storage) { case 'filesystem': return new Filesystem($attachment); break; case 's3': $s3Client = Stapler::getS3ClientInstance($attachment); return new S3($attachment, $s3Client); break; default: return new Filesystem($attachment); break; } }
/** * Test that the Stapler class can build a single instance of * Aws\S3\S3Client for each model/attachment combo. * * @test * @return void */ public function it_should_be_able_to_create_a_singleton_s3_client_instance_for_each_model_attachment_combo() { $dummyConfig = new AttachmentConfig('TestAttachment', ['styles' => [], 's3_client_config' => ['key' => '', 'secret' => '', 'region' => '', 'scheme' => 'http']]); $mockAttachment = m::mock('Codesleeve\\Stapler\\Attachment')->makePartial(); $mockAttachment->shouldReceive('getInstanceClass')->twice()->andReturn('TestModel'); $mockAttachment->setConfig($dummyConfig); $s3Client1 = Stapler::getS3ClientInstance($mockAttachment); $s3Client2 = Stapler::getS3ClientInstance($mockAttachment); $this->assertInstanceOf('Aws\\S3\\S3Client', $s3Client1); $this->assertSame($s3Client1, $s3Client2); }