From e19eb0f98b72125a9cc23d365fdba30252e8c779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Sto=CC=88hr?= Date: Wed, 8 Feb 2023 13:52:04 +0100 Subject: [PATCH] Add test for IiifUrlReader --- Build/Test/docker-compose.yml | 2 +- Build/Test/unit-php74/Dockerfile | 49 +++++++++++++++++++++++++ Tests/Unit/Common/IiifUrlReaderTest.php | 40 ++++++++++++++++++++ composer.json | 4 +- 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 Build/Test/unit-php74/Dockerfile create mode 100644 Tests/Unit/Common/IiifUrlReaderTest.php diff --git a/Build/Test/docker-compose.yml b/Build/Test/docker-compose.yml index 4d35c1e8ac..06a824fc9a 100644 --- a/Build/Test/docker-compose.yml +++ b/Build/Test/docker-compose.yml @@ -126,7 +126,7 @@ services: " unit: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest + build: unit-${DOCKER_PHP_IMAGE} user: "${HOST_UID}:${HOST_GID}" volumes: - ${DLF_ROOT}:${DLF_ROOT} diff --git a/Build/Test/unit-php74/Dockerfile b/Build/Test/unit-php74/Dockerfile new file mode 100644 index 0000000000..f7772612c6 --- /dev/null +++ b/Build/Test/unit-php74/Dockerfile @@ -0,0 +1,49 @@ +FROM php:7.4-alpine +MAINTAINER Christian Kuhn + +# We use convenient install-php-extensions script to manage additional php extensions +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN apk add --no-cache \ + bash \ + file \ + git \ + graphicsmagick \ + grep \ + patch \ + && chmod +x /usr/local/bin/install-php-extensions \ + && sync \ + && install-php-extensions \ + apcu \ + bcmath \ + bz2 \ + @composer-2 \ + gd \ + gettext \ + gmp \ + intl \ + memcached \ + mysqli \ + opcache \ + pdo_mysql \ + pdo_pgsql \ + pdo_sqlsrv \ + pgsql \ + pspell \ + redis \ + soap \ + sockets \ + sqlsrv \ + sysvsem \ + # we need to pin xdebug to a specific version now, as 3.2+ is not compatible with image php version + xdebug-3.1.5 \ + zip \ + && mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \ + && sed -i s/';phar.readonly = On'/'phar.readonly = Off'/ $PHP_INI_DIR/php.ini \ + && sed -i s/'memory_limit = 128M'/'memory_limit = 2G'/ $PHP_INI_DIR/php.ini \ + && sed -i s/'max_execution_time = 30'/'max_execution_time = 240'/ $PHP_INI_DIR/php.ini \ + && sed -i s/';max_input_vars = 1000'/'max_input_vars = 1500'/ $PHP_INI_DIR/php.ini \ + && echo "xdebug.max_nesting_level = 400" >> $PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini \ + && echo "apc.enable_cli=1" >> $PHP_INI_DIR/conf.d/docker-php-ext-apcu.ini \ + && echo "apc.slam_defense=0" >> $PHP_INI_DIR/conf.d/docker-php-ext-apcu.ini \ + && rm -rf /var/cache/apk/* diff --git a/Tests/Unit/Common/IiifUrlReaderTest.php b/Tests/Unit/Common/IiifUrlReaderTest.php new file mode 100644 index 0000000000..a9c3759abc --- /dev/null +++ b/Tests/Unit/Common/IiifUrlReaderTest.php @@ -0,0 +1,40 @@ +start(); + } + + public static function tearDownAfterClass() : void { + // stopping the web server during tear down allows us to reuse the port for later tests + self::$mockServer->stop(); + } + + /** + * @test + * @group getContent + */ + public function getContentCheck() { + $iiifUrlReader = new IiifUrlReader(); + + $correctUrl = self::$mockServer->setResponseOfPath('/correctPath', new Response('Correct result')); + $this->assertSame('Correct result', $iiifUrlReader->getContent($correctUrl)); + + $incorrectUrl = self::$mockServer->setResponseOfPath('/incorrectPath', + new Response('', [], 500)); + $this->assertSame('', $iiifUrlReader->getContent($incorrectUrl)); + } +} diff --git a/composer.json b/composer.json index 51068d7c76..7201172ec7 100644 --- a/composer.json +++ b/composer.json @@ -40,12 +40,14 @@ "solarium/solarium": "^5.2" }, "require-dev": { + "ext-sockets": "*", "spatie/phpunit-watcher": "^1.23", "typo3/cms-backend": "^9.5.31|^10.4.34", "typo3/cms-fluid": "^9.5.31|^10.4.34", "typo3/cms-fluid-styled-content": "^9.5.31|^10.4.34", "typo3/cms-frontend": "^9.5.31|^10.4.34", - "typo3/testing-framework": "^4.15.5|^6.16.6" + "typo3/testing-framework": "^4.15.5|^6.16.6", + "donatj/mock-webserver": "^2.6" }, "replace": { "typo3-ter/dlf": "self.version"