diff --git a/.gitattributes b/.gitattributes index 80102b6f..53b0a935 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,8 +5,6 @@ /module/CLI/test-resources export-ignore /module/Core/test export-ignore /module/Core/test-db export-ignore -/module/PreviewGenerator/test export-ignore -/module/PreviewGenerator/test-db export-ignore /module/Rest/test export-ignore /module/Rest/test-api export-ignore .gitattributes export-ignore diff --git a/README.md b/README.md index 9d0911c6..892dc6a6 100644 --- a/README.md +++ b/README.md @@ -215,12 +215,6 @@ Those tasks can be performed using shlink's CLI tool, so it should be easy to sc > You don't need this if you use Shlink v1.17.0 or newer, since now it downloads/updates the geolocation database automatically just before trying to use it. -* Generate website previews: `/path/to/shlink/bin/cli short-url:process-previews` - - Running this will improve the performance of the `doma.in/abc123/preview` URLs, which return a preview of the site. - - > **Important!** Generating previews is considered deprecated and the feature will be removed in Shlink v2. - *Any of these commands accept the `-q` flag, which makes it not display any output. This is recommended when configuring the commands as cron jobs.* ## Update to new version @@ -274,33 +268,32 @@ Options: -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: - help Displays help for a command - list Lists commands + help Displays help for a command + list Lists commands api-key - api-key:disable Disables an API key. - api-key:generate Generates a new valid API key. - api-key:list Lists all the available API keys. + api-key:disable Disables an API key. + api-key:generate Generates a new valid API key. + api-key:list Lists all the available API keys. config - config:generate-charset [DEPRECATED] Generates a character set sample just by shuffling the default one, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ". Then it can be set in the SHORTCODE_CHARS environment variable - config:generate-secret [DEPRECATED] Generates a random secret string that can be used for JWT token encryption + config:generate-charset [DEPRECATED] Generates a character set sample just by shuffling the default one, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ". Then it can be set in the SHORTCODE_CHARS environment variable + config:generate-secret [DEPRECATED] Generates a random secret string that can be used for JWT token encryption db - db:create Creates the database needed for shlink to work. It will do nothing if the database already exists - db:migrate Runs database migrations, which will ensure the shlink database is up to date. + db:create Creates the database needed for shlink to work. It will do nothing if the database already exists + db:migrate Runs database migrations, which will ensure the shlink database is up to date. short-url - short-url:delete [short-code:delete] Deletes a short URL - short-url:generate [shortcode:generate|short-code:generate] Generates a short URL for provided long URL and returns it - short-url:list [shortcode:list|short-code:list] List all short URLs - short-url:parse [shortcode:parse|short-code:parse] Returns the long URL behind a short code - short-url:process-previews [shortcode:process-previews|short-code:process-previews] [DEPRECATED] Processes and generates the previews for every URL, improving performance for later web requests. - short-url:visits [shortcode:visits|short-code:visits] Returns the detailed visits information for provided short code + short-url:delete [short-code:delete] Deletes a short URL + short-url:generate [shortcode:generate|short-code:generate] Generates a short URL for provided long URL and returns it + short-url:list [shortcode:list|short-code:list] List all short URLs + short-url:parse [shortcode:parse|short-code:parse] Returns the long URL behind a short code + short-url:visits [shortcode:visits|short-code:visits] Returns the detailed visits information for provided short code tag - tag:create Creates one or more tags. - tag:delete Deletes one or more tags. - tag:list Lists existing tags. - tag:rename Renames one existing tag. + tag:create Creates one or more tags. + tag:delete Deletes one or more tags. + tag:list Lists existing tags. + tag:rename Renames one existing tag. visit - visit:locate [visit:process] Resolves visits origin locations. - visit:update-db [DEPRECATED] Updates the GeoLite2 database file used to geolocate IP addresses + visit:locate [visit:process] Resolves visits origin locations. + visit:update-db [DEPRECATED] Updates the GeoLite2 database file used to geolocate IP addresses ``` > This product includes GeoLite2 data created by MaxMind, available from [https://www.maxmind.com](https://www.maxmind.com) diff --git a/bin/wkhtmltoimage b/bin/wkhtmltoimage deleted file mode 100755 index 1459957b..00000000 Binary files a/bin/wkhtmltoimage and /dev/null differ diff --git a/composer.json b/composer.json index 2f33ce98..0b2c1d93 100644 --- a/composer.json +++ b/composer.json @@ -71,8 +71,7 @@ "psr-4": { "Shlinkio\\Shlink\\CLI\\": "module/CLI/src", "Shlinkio\\Shlink\\Rest\\": "module/Rest/src", - "Shlinkio\\Shlink\\Core\\": "module/Core/src", - "Shlinkio\\Shlink\\PreviewGenerator\\": "module/PreviewGenerator/src/" + "Shlinkio\\Shlink\\Core\\": "module/Core/src" }, "files": [ "module/Core/functions/functions.php" @@ -86,8 +85,7 @@ "ShlinkioTest\\Shlink\\Core\\": [ "module/Core/test", "module/Core/test-db" - ], - "ShlinkioTest\\Shlink\\PreviewGenerator\\": "module/PreviewGenerator/test" + ] } }, "scripts": { diff --git a/config/autoload/preview-generation.global.php b/config/autoload/preview-generation.global.php deleted file mode 100644 index 93696000..00000000 --- a/config/autoload/preview-generation.global.php +++ /dev/null @@ -1,12 +0,0 @@ - [ - 'files_location' => 'data/cache', - ], - -]; diff --git a/config/config.php b/config/config.php index ad18fd20..855f5d41 100644 --- a/config/config.php +++ b/config/config.php @@ -23,7 +23,6 @@ return (new ConfigAggregator\ConfigAggregator([ CLI\ConfigProvider::class, Rest\ConfigProvider::class, EventDispatcher\ConfigProvider::class, - PreviewGenerator\ConfigProvider::class, new ConfigAggregator\PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'), env('APP_ENV') === 'test' ? new ConfigAggregator\PhpFileProvider('config/test/*.global.php') diff --git a/docs/swagger/paths/{shortCode}_preview.json b/docs/swagger/paths/{shortCode}_preview.json deleted file mode 100644 index 98df559c..00000000 --- a/docs/swagger/paths/{shortCode}_preview.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "get": { - "deprecated": true, - "operationId": "shortUrlPreview", - "tags": [ - "URL Shortener" - ], - "summary": "Short URL preview image", - "description": "Returns the preview of the page behind a short URL", - "parameters": [ - { - "name": "shortCode", - "in": "path", - "description": "The short code to resolve.", - "required": true, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "Image in PNG format", - "content": { - "image/png": { - "schema": { - "type": "string", - "format": "binary" - } - } - } - } - } - } -} diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index d924b8a0..e49a9ee1 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -105,9 +105,6 @@ "/{shortCode}/qr-code": { "$ref": "paths/{shortCode}_qr-code.json" }, - "/{shortCode}/preview": { - "$ref": "paths/{shortCode}_preview.json" - }, "/rest/v1/authenticate": { "$ref": "paths/v1_authenticate.json" diff --git a/module/CLI/config/cli.config.php b/module/CLI/config/cli.config.php index 0d5d5d5b..255b215f 100644 --- a/module/CLI/config/cli.config.php +++ b/module/CLI/config/cli.config.php @@ -12,7 +12,6 @@ return [ Command\ShortUrl\ResolveUrlCommand::NAME => Command\ShortUrl\ResolveUrlCommand::class, Command\ShortUrl\ListShortUrlsCommand::NAME => Command\ShortUrl\ListShortUrlsCommand::class, Command\ShortUrl\GetVisitsCommand::NAME => Command\ShortUrl\GetVisitsCommand::class, - Command\ShortUrl\GeneratePreviewCommand::NAME => Command\ShortUrl\GeneratePreviewCommand::class, Command\ShortUrl\DeleteShortUrlCommand::NAME => Command\ShortUrl\DeleteShortUrlCommand::class, Command\Visit\LocateVisitsCommand::NAME => Command\Visit\LocateVisitsCommand::class, diff --git a/module/CLI/config/dependencies.config.php b/module/CLI/config/dependencies.config.php index c89a0ad7..feb1eeae 100644 --- a/module/CLI/config/dependencies.config.php +++ b/module/CLI/config/dependencies.config.php @@ -12,7 +12,6 @@ use Shlinkio\Shlink\Core\Service; use Shlinkio\Shlink\Installer\Factory\ProcessHelperFactory; use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdater; use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; -use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGenerator; use Shlinkio\Shlink\Rest\Service\ApiKeyService; use Symfony\Component\Console as SymfonyCli; use Symfony\Component\Lock\LockFactory; @@ -34,7 +33,6 @@ return [ Command\ShortUrl\ResolveUrlCommand::class => ConfigAbstractFactory::class, Command\ShortUrl\ListShortUrlsCommand::class => ConfigAbstractFactory::class, Command\ShortUrl\GetVisitsCommand::class => ConfigAbstractFactory::class, - Command\ShortUrl\GeneratePreviewCommand::class => ConfigAbstractFactory::class, Command\ShortUrl\DeleteShortUrlCommand::class => ConfigAbstractFactory::class, Command\Visit\LocateVisitsCommand::class => ConfigAbstractFactory::class, @@ -64,7 +62,6 @@ return [ Command\ShortUrl\ResolveUrlCommand::class => [Service\UrlShortener::class], Command\ShortUrl\ListShortUrlsCommand::class => [Service\ShortUrlService::class, 'config.url_shortener.domain'], Command\ShortUrl\GetVisitsCommand::class => [Service\VisitsTracker::class], - Command\ShortUrl\GeneratePreviewCommand::class => [Service\ShortUrlService::class, PreviewGenerator::class], Command\ShortUrl\DeleteShortUrlCommand::class => [Service\ShortUrl\DeleteShortUrlService::class], Command\Visit\LocateVisitsCommand::class => [ diff --git a/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php b/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php deleted file mode 100644 index 081fa94f..00000000 --- a/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php +++ /dev/null @@ -1,76 +0,0 @@ -shortUrlService = $shortUrlService; - $this->previewGenerator = $previewGenerator; - } - - protected function configure(): void - { - $this - ->setName(self::NAME) - ->setAliases(self::ALIASES) - ->setDescription( - '[DEPRECATED] Processes and generates the previews for every URL, improving performance for later web ' - . 'requests.' - ); - } - - protected function execute(InputInterface $input, OutputInterface $output): ?int - { - $page = 1; - do { - $shortUrls = $this->shortUrlService->listShortUrls($page); - $page += 1; - - foreach ($shortUrls as $shortUrl) { - $this->processUrl($shortUrl->getLongUrl(), $output); - } - } while ($page <= $shortUrls->count()); - - (new SymfonyStyle($input, $output))->success('Finished processing all URLs'); - return ExitCodes::EXIT_SUCCESS; - } - - private function processUrl($url, OutputInterface $output): void - { - try { - $output->write(sprintf('Processing URL %s...', $url)); - $this->previewGenerator->generatePreview($url); - $output->writeln(' Success!'); - } catch (PreviewGenerationException $e) { - $output->writeln(' Error'); - if ($output->isVerbose()) { - $this->getApplication()->renderThrowable($e, $output); - } - } - } -} diff --git a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php deleted file mode 100644 index e4029231..00000000 --- a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php +++ /dev/null @@ -1,92 +0,0 @@ -previewGenerator = $this->prophesize(PreviewGenerator::class); - $this->shortUrlService = $this->prophesize(ShortUrlService::class); - - $command = new GeneratePreviewCommand($this->shortUrlService->reveal(), $this->previewGenerator->reveal()); - $app = new Application(); - $app->add($command); - - $this->commandTester = new CommandTester($command); - } - - /** @test */ - public function previewsForEveryUrlAreGenerated() - { - $paginator = $this->createPaginator([ - new ShortUrl('http://foo.com'), - new ShortUrl('https://bar.com'), - new ShortUrl('http://baz.com/something'), - ]); - $this->shortUrlService->listShortUrls(1)->willReturn($paginator)->shouldBeCalledOnce(); - - $generatePreview1 = $this->previewGenerator->generatePreview('http://foo.com')->willReturn(''); - $generatePreview2 = $this->previewGenerator->generatePreview('https://bar.com')->willReturn(''); - $generatePreview3 = $this->previewGenerator->generatePreview('http://baz.com/something')->willReturn(''); - - $this->commandTester->execute([]); - $output = $this->commandTester->getDisplay(); - - $this->assertStringContainsString('Processing URL http://foo.com', $output); - $this->assertStringContainsString('Processing URL https://bar.com', $output); - $this->assertStringContainsString('Processing URL http://baz.com/something', $output); - $this->assertStringContainsString('Finished processing all URLs', $output); - $generatePreview1->shouldHaveBeenCalledOnce(); - $generatePreview2->shouldHaveBeenCalledOnce(); - $generatePreview3->shouldHaveBeenCalledOnce(); - } - - /** @test */ - public function exceptionWillOutputError() - { - $items = [ - new ShortUrl('http://foo.com'), - new ShortUrl('https://bar.com'), - new ShortUrl('http://baz.com/something'), - ]; - $paginator = $this->createPaginator($items); - $this->shortUrlService->listShortUrls(1)->willReturn($paginator)->shouldBeCalledOnce(); - $this->previewGenerator->generatePreview(Argument::any())->willThrow(PreviewGenerationException::class) - ->shouldBeCalledTimes(count($items)); - - $this->commandTester->execute([]); - $output = $this->commandTester->getDisplay(); - $this->assertEquals(count($items), substr_count($output, 'Error')); - } - - protected function createPaginator(array $items) - { - $paginator = new Paginator(new ArrayAdapter($items)); - $paginator->setItemCountPerPage(count($items)); - - return $paginator; - } -} diff --git a/module/Core/config/dependencies.config.php b/module/Core/config/dependencies.config.php index 0ebdae7d..34759868 100644 --- a/module/Core/config/dependencies.config.php +++ b/module/Core/config/dependencies.config.php @@ -8,7 +8,6 @@ use Doctrine\Common\Cache\Cache; use Psr\EventDispatcher\EventDispatcherInterface; use Shlinkio\Shlink\Core\ErrorHandler; use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; -use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGenerator; use Zend\Expressive\Router\RouterInterface; use Zend\Expressive\Template\TemplateRendererInterface; use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; @@ -37,7 +36,6 @@ return [ Action\RedirectAction::class => ConfigAbstractFactory::class, Action\PixelAction::class => ConfigAbstractFactory::class, Action\QrCodeAction::class => ConfigAbstractFactory::class, - Action\PreviewAction::class => ConfigAbstractFactory::class, Middleware\QrCodeCacheMiddleware::class => ConfigAbstractFactory::class, ], @@ -74,7 +72,6 @@ return [ 'Logger_Shlink', ], Action\QrCodeAction::class => [RouterInterface::class, Service\UrlShortener::class, 'Logger_Shlink'], - Action\PreviewAction::class => [PreviewGenerator::class, Service\UrlShortener::class, 'Logger_Shlink'], Middleware\QrCodeCacheMiddleware::class => [Cache::class], ], diff --git a/module/Core/config/routes.config.php b/module/Core/config/routes.config.php index b38222df..d636ed23 100644 --- a/module/Core/config/routes.config.php +++ b/module/Core/config/routes.config.php @@ -37,23 +37,6 @@ return [ ], 'allowed_methods' => [RequestMethod::METHOD_GET], ], - - // Deprecated routes - [ - 'name' => 'short-url-preview', - 'path' => '/{shortCode}/preview', - 'middleware' => Action\PreviewAction::class, - 'allowed_methods' => [RequestMethod::METHOD_GET], - ], - [ - 'name' => 'short-url-qr-code-old', - 'path' => '/qr/{shortCode}[/{size:[0-9]+}]', - 'middleware' => [ - Middleware\QrCodeCacheMiddleware::class, - Action\QrCodeAction::class, - ], - 'allowed_methods' => [RequestMethod::METHOD_GET], - ], ], ]; diff --git a/module/Core/src/Action/PreviewAction.php b/module/Core/src/Action/PreviewAction.php deleted file mode 100644 index d243f12c..00000000 --- a/module/Core/src/Action/PreviewAction.php +++ /dev/null @@ -1,63 +0,0 @@ -previewGenerator = $previewGenerator; - $this->urlShortener = $urlShortener; - $this->logger = $logger ?: new NullLogger(); - } - - /** - * Process an incoming server request and return a response, optionally delegating - * to the next middleware component to create the response. - * - * @param Request $request - * @param RequestHandlerInterface $handler - * - * @return Response - */ - public function process(Request $request, RequestHandlerInterface $handler): Response - { - $shortCode = $request->getAttribute('shortCode'); - - try { - $url = $this->urlShortener->shortCodeToUrl($shortCode); - $imagePath = $this->previewGenerator->generatePreview($url->getLongUrl()); - return $this->generateImageResponse($imagePath); - } catch (ShortUrlNotFoundException | PreviewGenerationException $e) { - $this->logger->warning('An error occurred while generating preview image. {e}', ['e' => $e]); - return $handler->handle($request); - } - } -} diff --git a/module/Core/test/Action/PreviewActionTest.php b/module/Core/test/Action/PreviewActionTest.php deleted file mode 100644 index 0725c957..00000000 --- a/module/Core/test/Action/PreviewActionTest.php +++ /dev/null @@ -1,76 +0,0 @@ -previewGenerator = $this->prophesize(PreviewGenerator::class); - $this->urlShortener = $this->prophesize(UrlShortener::class); - $this->action = new PreviewAction($this->previewGenerator->reveal(), $this->urlShortener->reveal()); - } - - /** @test */ - public function correctShortCodeReturnsImageResponse(): void - { - $shortCode = 'abc123'; - $url = 'foobar.com'; - $shortUrl = new ShortUrl($url); - $path = __FILE__; - $this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl)->shouldBeCalledOnce(); - $this->previewGenerator->generatePreview($url)->willReturn($path)->shouldBeCalledOnce(); - - $resp = $this->action->process( - (new ServerRequest())->withAttribute('shortCode', $shortCode), - $this->prophesize(RequestHandlerInterface::class)->reveal() - ); - - $this->assertEquals(filesize($path), $resp->getHeaderLine('Content-length')); - $this->assertEquals((new finfo(FILEINFO_MIME))->file($path), $resp->getHeaderLine('Content-type')); - } - - /** @test */ - public function invalidShortCodeExceptionFallsBackToNextMiddleware(): void - { - $shortCode = 'abc123'; - $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(ShortUrlNotFoundException::class) - ->shouldBeCalledOnce(); - $delegate = $this->prophesize(RequestHandlerInterface::class); - $process = $delegate->handle(Argument::any())->willReturn(new Response()); - - $this->action->process( - (new ServerRequest())->withAttribute('shortCode', $shortCode), - $delegate->reveal() - ); - - $process->shouldHaveBeenCalledOnce(); - } -} diff --git a/module/PreviewGenerator/config/dependencies.config.php b/module/PreviewGenerator/config/dependencies.config.php deleted file mode 100644 index dc7ceb96..00000000 --- a/module/PreviewGenerator/config/dependencies.config.php +++ /dev/null @@ -1,27 +0,0 @@ - [ - 'factories' => [ - Image\ImageBuilder::class => Image\ImageBuilderFactory::class, - Service\PreviewGenerator::class => ConfigAbstractFactory::class, - ], - ], - - ConfigAbstractFactory::class => [ - Service\PreviewGenerator::class => [ - Image\ImageBuilder::class, - Filesystem::class, - 'config.preview_generation.files_location', - ], - ], - -]; diff --git a/module/PreviewGenerator/src/ConfigProvider.php b/module/PreviewGenerator/src/ConfigProvider.php deleted file mode 100644 index 1bc2f7c5..00000000 --- a/module/PreviewGenerator/src/ConfigProvider.php +++ /dev/null @@ -1,16 +0,0 @@ - [ - Image::class => ImageFactory::class, - ]]); - } -} diff --git a/module/PreviewGenerator/src/Image/ImageBuilderInterface.php b/module/PreviewGenerator/src/Image/ImageBuilderInterface.php deleted file mode 100644 index d11daab0..00000000 --- a/module/PreviewGenerator/src/Image/ImageBuilderInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -get('config')['wkhtmltopdf']; - $image = new Image($config['images'] ?? null); - - if ($options['url'] ?? null) { - $image->setPage($options['url']); - } - - return $image; - } -} diff --git a/module/PreviewGenerator/src/Service/PreviewGenerator.php b/module/PreviewGenerator/src/Service/PreviewGenerator.php deleted file mode 100644 index 54e967aa..00000000 --- a/module/PreviewGenerator/src/Service/PreviewGenerator.php +++ /dev/null @@ -1,58 +0,0 @@ -location = $location; - $this->imageBuilder = $imageBuilder; - $this->filesystem = $filesystem; - } - - /** - * Generates and stores preview for provided website and returns the path to the image file - * - * @throws PreviewGenerationException - */ - public function generatePreview(string $url): string - { - $image = $this->imageBuilder->build(Image::class, ['url' => $url]); - - // If the file already exists, return its path - $cacheId = sprintf('preview_%s.%s', urlencode($url), $image->type); - $path = $this->location . '/' . $cacheId; - if ($this->filesystem->exists($path)) { - return $path; - } - - // Save and check if an error occurred - $image->saveAs($path); - $error = $image->getError(); - if (! empty($error)) { - throw PreviewGenerationException::fromImageError($error); - } - - // Cache the path and return it - return $path; - } -} diff --git a/module/PreviewGenerator/src/Service/PreviewGeneratorInterface.php b/module/PreviewGenerator/src/Service/PreviewGeneratorInterface.php deleted file mode 100644 index 26aefda0..00000000 --- a/module/PreviewGenerator/src/Service/PreviewGeneratorInterface.php +++ /dev/null @@ -1,18 +0,0 @@ -configProvider = new ConfigProvider(); - } - - /** @test */ - public function configIsReturned(): void - { - $config = ($this->configProvider)(); - - $this->assertArrayHasKey('dependencies', $config); - } -} diff --git a/module/PreviewGenerator/test/Image/ImageBuilderFactoryTest.php b/module/PreviewGenerator/test/Image/ImageBuilderFactoryTest.php deleted file mode 100644 index 0319dafc..00000000 --- a/module/PreviewGenerator/test/Image/ImageBuilderFactoryTest.php +++ /dev/null @@ -1,28 +0,0 @@ -factory = new ImageBuilderFactory(); - } - - /** @test */ - public function serviceIsCreated() - { - $instance = $this->factory->__invoke(new ServiceManager(), ''); - $this->assertInstanceOf(ImageBuilder::class, $instance); - } -} diff --git a/module/PreviewGenerator/test/Image/ImageFactoryTest.php b/module/PreviewGenerator/test/Image/ImageFactoryTest.php deleted file mode 100644 index e9b9fc8e..00000000 --- a/module/PreviewGenerator/test/Image/ImageFactoryTest.php +++ /dev/null @@ -1,54 +0,0 @@ -factory = new ImageFactory(); - } - - /** @test */ - public function noPageIsSetWhenOptionsAreNotProvided() - { - /** @var Image $image */ - $image = $this->factory->__invoke(new ServiceManager(['services' => [ - 'config' => ['wkhtmltopdf' => []], - ]]), ''); - $this->assertInstanceOf(Image::class, $image); - - $ref = new ReflectionObject($image); - $page = $ref->getProperty('_page'); - $page->setAccessible(true); - $this->assertNull($page->getValue($image)); - } - - /** @test */ - public function aPageIsSetWhenOptionsIncludeTheUrl() - { - $expectedPage = 'foo/bar.html'; - - /** @var Image $image */ - $image = $this->factory->__invoke(new ServiceManager(['services' => [ - 'config' => ['wkhtmltopdf' => []], - ]]), '', ['url' => $expectedPage]); - $this->assertInstanceOf(Image::class, $image); - - $ref = new ReflectionObject($image); - $page = $ref->getProperty('_page'); - $page->setAccessible(true); - $this->assertEquals($expectedPage, $page->getValue($image)); - } -} diff --git a/module/PreviewGenerator/test/Service/PreviewGeneratorTest.php b/module/PreviewGenerator/test/Service/PreviewGeneratorTest.php deleted file mode 100644 index 035a976b..00000000 --- a/module/PreviewGenerator/test/Service/PreviewGeneratorTest.php +++ /dev/null @@ -1,85 +0,0 @@ -image = $this->prophesize(Image::class); - $this->filesystem = $this->prophesize(Filesystem::class); - - $this->generator = new PreviewGenerator(new ImageBuilder(new ServiceManager(), [ - 'factories' => [ - Image::class => function () { - return $this->image->reveal(); - }, - ], - ]), $this->filesystem->reveal(), 'dir'); - } - - /** @test */ - public function alreadyProcessedElementsAreNotProcessed() - { - $url = 'http://foo.com'; - $this->filesystem->exists(sprintf('dir/preview_%s.png', urlencode($url)))->willReturn(true) - ->shouldBeCalledOnce(); - $this->image->saveAs(Argument::cetera())->shouldBeCalledTimes(0); - $this->assertEquals(sprintf('dir/preview_%s.png', urlencode($url)), $this->generator->generatePreview($url)); - } - - /** @test */ - public function nonProcessedElementsAreProcessed() - { - $url = 'http://foo.com'; - $cacheId = sprintf('preview_%s.png', urlencode($url)); - $expectedPath = 'dir/' . $cacheId; - - $this->filesystem->exists(sprintf('dir/preview_%s.png', urlencode($url)))->willReturn(false) - ->shouldBeCalledOnce(); - - $this->image->saveAs($expectedPath)->shouldBeCalledOnce(); - $this->image->getError()->willReturn('')->shouldBeCalledOnce(); - $this->assertEquals($expectedPath, $this->generator->generatePreview($url)); - } - - /** @test */ - public function errorWhileGeneratingPreviewThrowsException() - { - $url = 'http://foo.com'; - $cacheId = sprintf('preview_%s.png', urlencode($url)); - $expectedPath = 'dir/' . $cacheId; - - $this->filesystem->exists(sprintf('dir/preview_%s.png', urlencode($url)))->willReturn(false) - ->shouldBeCalledOnce(); - - $this->image->saveAs($expectedPath)->shouldBeCalledOnce(); - $this->image->getError()->willReturn('Error!!')->shouldBeCalledOnce(); - - $this->expectException(PreviewGenerationException::class); - - $this->generator->generatePreview($url); - } -} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 67d08507..03f73521 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,9 +15,6 @@ ./module/CLI/test - - ./module/PreviewGenerator/test -