From 0e535123ae88e3626b0ab43f22c57d6595bdf547 Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandro@alejandrocelaya.com>
Date: Sun, 11 Aug 2019 21:22:27 +0200
Subject: [PATCH] Used TestUtils module from external library

---
 composer.json                                 |  5 +-
 module/TestUtils/LICENSE                      | 21 ------
 module/TestUtils/README.md                    | 10 ---
 module/TestUtils/src/ApiTest/ApiTestCase.php  | 67 -------------------
 .../TestUtils/src/DbTest/DatabaseTestCase.php | 36 ----------
 module/TestUtils/src/Helper/TestHelper.php    | 40 -----------
 phpunit.xml.dist                              |  1 -
 7 files changed, 2 insertions(+), 178 deletions(-)
 delete mode 100644 module/TestUtils/LICENSE
 delete mode 100644 module/TestUtils/README.md
 delete mode 100644 module/TestUtils/src/ApiTest/ApiTestCase.php
 delete mode 100644 module/TestUtils/src/DbTest/DatabaseTestCase.php
 delete mode 100644 module/TestUtils/src/Helper/TestHelper.php

diff --git a/composer.json b/composer.json
index 2f7b201b..f35b2afb 100644
--- a/composer.json
+++ b/composer.json
@@ -54,7 +54,6 @@
     },
     "require-dev": {
         "devster/ubench": "^2.0",
-        "doctrine/data-fixtures": "^1.3",
         "eaglewu/swoole-ide-helper": "dev-master",
         "filp/whoops": "^2.4",
         "infection/infection": "^0.12.2",
@@ -63,6 +62,7 @@
         "phpunit/phpunit": "^8.3",
         "roave/security-advisories": "dev-master",
         "shlinkio/php-coding-standard": "~1.2.2",
+        "shlinkio/shlink-test-utils": "^1.0",
         "symfony/dotenv": "^4.3",
         "symfony/var-dumper": "^4.3",
         "zendframework/zend-component-installer": "^2.1",
@@ -95,8 +95,7 @@
             "ShlinkioTest\\Shlink\\Common\\": "module/Common/test",
             "ShlinkioTest\\Shlink\\EventDispatcher\\": "module/EventDispatcher/test",
             "ShlinkioTest\\Shlink\\IpGeolocation\\": "module/IpGeolocation/test",
-            "ShlinkioTest\\Shlink\\PreviewGenerator\\": "module/PreviewGenerator/test",
-            "Shlinkio\\Shlink\\TestUtils\\": "module/TestUtils/src"
+            "ShlinkioTest\\Shlink\\PreviewGenerator\\": "module/PreviewGenerator/test"
         }
     },
     "scripts": {
diff --git a/module/TestUtils/LICENSE b/module/TestUtils/LICENSE
deleted file mode 100644
index 31778387..00000000
--- a/module/TestUtils/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2019 Alejandro Celaya
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/module/TestUtils/README.md b/module/TestUtils/README.md
deleted file mode 100644
index d2520ec1..00000000
--- a/module/TestUtils/README.md
+++ /dev/null
@@ -1,10 +0,0 @@
-# Shlink test utils
-
-Helpers and utilities to run different types of tests in Shlink.
-
-Provided base test classes:
-
-* `ApiTestCase` for API e2e tests.
-* `DbTestCase` for database integration tests.
-
-Both classes extends [phpunit]'s `TestCase` class.
diff --git a/module/TestUtils/src/ApiTest/ApiTestCase.php b/module/TestUtils/src/ApiTest/ApiTestCase.php
deleted file mode 100644
index 7cc70396..00000000
--- a/module/TestUtils/src/ApiTest/ApiTestCase.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-declare(strict_types=1);
-
-namespace Shlinkio\Shlink\TestUtils\ApiTest;
-
-use Fig\Http\Message\RequestMethodInterface;
-use Fig\Http\Message\StatusCodeInterface;
-use GuzzleHttp\ClientInterface;
-use GuzzleHttp\RequestOptions;
-use PHPUnit\Framework\TestCase;
-use Psr\Http\Message\ResponseInterface;
-
-use function Shlinkio\Shlink\Common\json_decode;
-use function sprintf;
-
-abstract class ApiTestCase extends TestCase implements StatusCodeInterface, RequestMethodInterface
-{
-    private const REST_PATH_PREFIX = '/rest/v1';
-
-    /** @var ClientInterface */
-    private static $client;
-    /** @var callable|null */
-    private static $seedFixtures;
-
-    public static function setApiClient(ClientInterface $client): void
-    {
-        self::$client = $client;
-    }
-
-    public static function setSeedFixturesCallback(callable $seedFixtures): void
-    {
-        self::$seedFixtures = $seedFixtures;
-    }
-
-    public function setUp(): void
-    {
-        if (self::$seedFixtures !== null) {
-            (self::$seedFixtures)();
-        }
-    }
-
-    protected function callApi(string $method, string $uri, array $options = []): ResponseInterface
-    {
-        return self::$client->request($method, sprintf('%s%s', self::REST_PATH_PREFIX, $uri), $options);
-    }
-
-    protected function callApiWithKey(string $method, string $uri, array $options = []): ResponseInterface
-    {
-        $headers = $options[RequestOptions::HEADERS] ?? [];
-        $headers['X-Api-Key'] = 'valid_api_key';
-        $options[RequestOptions::HEADERS] = $headers;
-
-        return $this->callApi($method, $uri, $options);
-    }
-
-    protected function getJsonResponsePayload(ResponseInterface $resp): array
-    {
-        return json_decode((string) $resp->getBody());
-    }
-
-    protected function callShortUrl(string $shortCode): ResponseInterface
-    {
-        return self::$client->request(self::METHOD_GET, sprintf('/%s', $shortCode), [
-            RequestOptions::ALLOW_REDIRECTS => false,
-        ]);
-    }
-}
diff --git a/module/TestUtils/src/DbTest/DatabaseTestCase.php b/module/TestUtils/src/DbTest/DatabaseTestCase.php
deleted file mode 100644
index 987dfa1f..00000000
--- a/module/TestUtils/src/DbTest/DatabaseTestCase.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-declare(strict_types=1);
-
-namespace Shlinkio\Shlink\TestUtils\DbTest;
-
-use Doctrine\ORM\EntityManagerInterface;
-use PHPUnit\Framework\TestCase;
-
-abstract class DatabaseTestCase extends TestCase
-{
-    protected const ENTITIES_TO_EMPTY = [];
-
-    /** @var EntityManagerInterface */
-    private static $em;
-
-    public static function setEntityManager(EntityManagerInterface $em): void
-    {
-        self::$em = $em;
-    }
-
-    protected function getEntityManager(): EntityManagerInterface
-    {
-        return self::$em;
-    }
-
-    public function tearDown(): void
-    {
-        foreach (static::ENTITIES_TO_EMPTY as $entityClass) {
-            $qb = $this->getEntityManager()->createQueryBuilder();
-            $qb->delete($entityClass, 'x');
-            $qb->getQuery()->execute();
-        }
-
-        $this->getEntityManager()->clear();
-    }
-}
diff --git a/module/TestUtils/src/Helper/TestHelper.php b/module/TestUtils/src/Helper/TestHelper.php
deleted file mode 100644
index c8b67d6c..00000000
--- a/module/TestUtils/src/Helper/TestHelper.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-declare(strict_types=1);
-
-namespace Shlinkio\Shlink\TestUtils\Helper;
-
-use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
-use Doctrine\Common\DataFixtures\Loader;
-use Doctrine\Common\DataFixtures\Purger\ORMPurger;
-use Doctrine\ORM\EntityManagerInterface;
-use Symfony\Component\Process\Process;
-
-class TestHelper
-{
-    public function createTestDb(): void
-    {
-        $process = new Process(['vendor/bin/doctrine', 'orm:schema-tool:drop', '--force', '--no-interaction', '-q']);
-        $process->inheritEnvironmentVariables()
-                ->mustRun();
-
-        $process = new Process(['vendor/bin/doctrine', 'orm:schema-tool:create', '--no-interaction', '-q']);
-        $process->inheritEnvironmentVariables()
-                ->mustRun();
-    }
-
-    public function seedFixtures(EntityManagerInterface $em, array $config): void
-    {
-        $paths = $config['paths'] ?? [];
-        if (empty($paths)) {
-            return;
-        }
-
-        $loader = new Loader();
-        foreach ($paths as $path) {
-            $loader->loadFromDirectory($path);
-        }
-
-        $executor = new ORMExecutor($em, new ORMPurger());
-        $executor->execute($loader->getFixtures());
-    }
-}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 1f0636f5..03e97254 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -35,7 +35,6 @@
 
             <exclude>
                 <directory suffix=".php">./module/Core/src/Repository</directory>
-                <directory suffix=".php">./module/TestUtils</directory>
             </exclude>
         </whitelist>
     </filter>