/** * Run the application * * @param \Symfony\Component\HttpFoundation\Request $request * @return string */ public static function run(Request $request) { self::loadEnv(); // Set things up for the resizer Configurator::validateEnvironment(); $configurator = new Configurator($request); $configurator->setupFile(getenv('ALLOWED_HOSTS')); $configurator->setHeaders(); $image = new Image($configurator->file); return $image->alterImage($configurator->config)->toBlob(); }
/** * @runInSeparateProcess */ public function testItSetsHeaders() { $cache_expires_hours = 6; $request_settings = ['height' => 300, 'width' => 425, 'crop' => false, 'source' => $this->getPlaceholditImage(500, 400)]; $this->setEnvironmentVariables($this->placeholdit_domain, $cache_expires_hours); $request = Mockery::mock(Request::class); $request->shouldReceive('get')->with('height')->andReturn($request_settings['height']); $request->shouldReceive('get')->with('width')->andReturn($request_settings['width']); $request->shouldReceive('get')->with('crop')->andReturn($request_settings['crop']); $request->shouldReceive('get')->with('source')->andReturn($request_settings['source']); $request->shouldReceive('get')->with('min_quality', Image::FULL_COMPRESSION)->andReturn(10); $request->shouldReceive('get')->with('max_quality', image::NO_COMPRESSION)->andReturn(100); $request->shouldReceive('get')->with('max_file_size_bytes')->andReturn(2200); $configurator = new Configurator($request); $file = $configurator->setupFile([$this->placeholdit_domain]); $configurator->setHeaders(); $this->assertEquals($this->getRfcCompliantDate(Carbon::now(), 0), $this->getHeaderValue('Last-Modified')); $cache_age_seconds = $cache_expires_hours * 60 * 60; $this->assertEquals("max-age={$cache_age_seconds}", $this->getHeaderValue('Cache-Control')); $this->assertEquals($file->getMimeType(), $this->getHeaderValue('Content-Type')); $this->assertEquals($this->getRfcCompliantDate(Carbon::now(), $cache_expires_hours), $this->getHeaderValue('Expires')); }