From 5361f33cc15df95dd7370ac4f71755fee5133b79 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 1 Nov 2019 09:52:56 +0100 Subject: [PATCH] Some more refactorings --- Dockerfile | 2 +- bin/test/run-api-tests.sh | 2 +- composer.json | 2 +- data/infra/swoole.Dockerfile | 3 ++- docker-compose.yml | 1 + .../Shlinkio.Shlink.Core.Entity.ShortUrl.php | 1 - module/Core/src/Util/TagManagerTrait.php | 14 +++++--------- .../test-api/Action/CreateShortUrlActionTest.php | 4 ++-- 8 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4303b3dd..b1dbcd77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ LABEL maintainer="Alejandro Celaya " ARG SHLINK_VERSION=1.18.1 ENV SHLINK_VERSION ${SHLINK_VERSION} -ENV SWOOLE_VERSION 4.3.3 +ENV SWOOLE_VERSION 4.4.8 ENV COMPOSER_VERSION 1.9.0 WORKDIR /etc/shlink diff --git a/bin/test/run-api-tests.sh b/bin/test/run-api-tests.sh index 32339c19..eabc62d6 100755 --- a/bin/test/run-api-tests.sh +++ b/bin/test/run-api-tests.sh @@ -10,5 +10,5 @@ echo 'Starting server...' vendor/bin/zend-expressive-swoole start -d sleep 2 -vendor/bin/phpunit --order-by=random -c phpunit-api.xml --testdox --colors=always +APP_ENV=test DB_DRIVER=mysql vendor/bin/phpunit --order-by=random -c phpunit-api.xml --testdox --colors=always vendor/bin/zend-expressive-swoole stop diff --git a/composer.json b/composer.json index 8e2b1968..c3e071bc 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "phly/phly-event-dispatcher": "^1.0", "predis/predis": "^1.1", "pugx/shortid-php": "^0.5", - "shlinkio/shlink-common": "^2.1", + "shlinkio/shlink-common": "^2.2", "shlinkio/shlink-event-dispatcher": "^1.0", "shlinkio/shlink-installer": "^2.1", "shlinkio/shlink-ip-geolocation": "^1.1", diff --git a/data/infra/swoole.Dockerfile b/data/infra/swoole.Dockerfile index 87c16064..865ec5ba 100644 --- a/data/infra/swoole.Dockerfile +++ b/data/infra/swoole.Dockerfile @@ -4,6 +4,7 @@ MAINTAINER Alejandro Celaya ENV APCU_VERSION 5.1.16 ENV APCU_BC_VERSION 1.0.4 ENV INOTIFY_VERSION 2.0.0 +ENV SWOOLE_VERSION 4.4.8 RUN apk update @@ -66,7 +67,7 @@ RUN rm /tmp/inotify.tar.gz # Install swoole # First line fixes an error when installing pecl extensions. Found in https://github.com/docker-library/php/issues/233 RUN apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS && \ - pecl install swoole && \ + pecl install swoole-${SWOOLE_VERSION} && \ docker-php-ext-enable swoole && \ apk del .phpize-deps diff --git a/docker-compose.yml b/docker-compose.yml index 630ab955..811eec69 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,6 +34,7 @@ services: dockerfile: ./data/infra/swoole.Dockerfile ports: - "8080:8080" + - "9001:9001" volumes: - ./:/home/shlink links: diff --git a/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.Entity.ShortUrl.php b/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.Entity.ShortUrl.php index 18fc6a0d..76e5ae7b 100644 --- a/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.Entity.ShortUrl.php +++ b/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.Entity.ShortUrl.php @@ -60,7 +60,6 @@ $builder->createManyToMany('tags', Entity\Tag::class) ->setJoinTable('short_urls_in_tags') ->addInverseJoinColumn('tag_id', 'id', true, false, 'CASCADE') ->addJoinColumn('short_url_id', 'id', true, false, 'CASCADE') - ->cascadePersist() ->build(); $builder->createManyToOne('domain', Entity\Domain::class) diff --git a/module/Core/src/Util/TagManagerTrait.php b/module/Core/src/Util/TagManagerTrait.php index 7d439229..4fbfd288 100644 --- a/module/Core/src/Util/TagManagerTrait.php +++ b/module/Core/src/Util/TagManagerTrait.php @@ -8,6 +8,7 @@ use Doctrine\Common\Collections; use Doctrine\ORM\EntityManagerInterface; use Shlinkio\Shlink\Core\Entity\Tag; +use function Functional\map; use function str_replace; use function strtolower; use function trim; @@ -21,18 +22,13 @@ trait TagManagerTrait */ private function tagNamesToEntities(EntityManagerInterface $em, array $tags): Collections\Collection { - $entities = []; - foreach ($tags as $tagName) { + $entities = map($tags, function (string $tagName) use ($em): Tag { $tagName = $this->normalizeTagName($tagName); $tag = $em->getRepository(Tag::class)->findOneBy(['name' => $tagName]) ?? new Tag($tagName); + $em->persist($tag); -// if (! $tag) { -// $tag = ; -// $em->persist($tag); -// } - - $entities[] = $tag; - } + return $tag; + }); return new Collections\ArrayCollection($entities); } diff --git a/module/Rest/test-api/Action/CreateShortUrlActionTest.php b/module/Rest/test-api/Action/CreateShortUrlActionTest.php index c3f7a4e4..9e691f7f 100644 --- a/module/Rest/test-api/Action/CreateShortUrlActionTest.php +++ b/module/Rest/test-api/Action/CreateShortUrlActionTest.php @@ -50,10 +50,10 @@ class CreateShortUrlActionTest extends ApiTestCase /** @test */ public function createsNewShortUrlWithTags(): void { - [$statusCode, $payload] = $this->createShortUrl(['tags' => ['foo', 'bar', 'baz']]); + [$statusCode, ['tags' => $tags]] = $this->createShortUrl(['tags' => ['foo', 'bar', 'baz']]); $this->assertEquals(self::STATUS_OK, $statusCode); - $this->assertEquals(['foo', 'bar', 'baz'], $payload['tags']); + $this->assertEquals(['foo', 'bar', 'baz'], $tags); } /**