/** * @param string $data name of the assert * * @return string * @throws ExceptionMissingAsset */ public function encode($data) { //skip if external resource if (filter_var($data, FILTER_VALIDATE_URL)) { return $data; } $file = $this->directory->getFile($data); if ($file->exists()) { return sprintf(self::DATA_PREFIX, $file->getMimeType(), base64_encode($file->read())); } throw new ExceptionMissingAsset('Assets ' . $data . ' not found at ' . $file->getPrefix()); }
/** * Test has and delete file function with valid file */ public function testHasAndDeleteWithValidFile() { $tmpFile = uniqid() . '.php'; $resource = fopen(__DIR__ . '/samples/43bytes.php', 'r'); $streamFixture = \GuzzleHttp\Psr7\stream_for($resource); $file = $this->instance->getFile($tmpFile); $file->write($streamFixture); $this->assertTrue($file->exists()); $this->assertTrue($file->delete()); fclose($resource); $streamFixture->close(); }