mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-28 09:51:40 -06:00
Merge pull request #457 from acelaya/feature/test-utils-module
Created TestUtils module
This commit is contained in:
commit
1fd677df5a
@ -91,12 +91,10 @@
|
|||||||
"module/Core/test",
|
"module/Core/test",
|
||||||
"module/Core/test-db"
|
"module/Core/test-db"
|
||||||
],
|
],
|
||||||
"ShlinkioTest\\Shlink\\Common\\": [
|
"ShlinkioTest\\Shlink\\Common\\": "module/Common/test",
|
||||||
"module/Common/test",
|
|
||||||
"module/Common/test-db"
|
|
||||||
],
|
|
||||||
"ShlinkioTest\\Shlink\\EventDispatcher\\": "module/EventDispatcher/test",
|
"ShlinkioTest\\Shlink\\EventDispatcher\\": "module/EventDispatcher/test",
|
||||||
"ShlinkioTest\\Shlink\\IpGeolocation\\": "module/IpGeolocation/test"
|
"ShlinkioTest\\Shlink\\IpGeolocation\\": "module/IpGeolocation/test",
|
||||||
|
"Shlinkio\\Shlink\\TestUtils\\": "module/TestUtils/src"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Common;
|
namespace Shlinkio\Shlink\TestUtils;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
@ -16,7 +16,7 @@ if (! file_exists('.env')) {
|
|||||||
|
|
||||||
/** @var ContainerInterface $container */
|
/** @var ContainerInterface $container */
|
||||||
$container = require __DIR__ . '/../container.php';
|
$container = require __DIR__ . '/../container.php';
|
||||||
$testHelper = $container->get(TestHelper::class);
|
$testHelper = $container->get(Helper\TestHelper::class);
|
||||||
$config = $container->get('config');
|
$config = $container->get('config');
|
||||||
$em = $container->get(EntityManager::class);
|
$em = $container->get(EntityManager::class);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Common;
|
namespace Shlinkio\Shlink\TestUtils;
|
||||||
|
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
@ -15,5 +15,5 @@ if (! file_exists('.env')) {
|
|||||||
|
|
||||||
/** @var ContainerInterface $container */
|
/** @var ContainerInterface $container */
|
||||||
$container = require __DIR__ . '/../container.php';
|
$container = require __DIR__ . '/../container.php';
|
||||||
$container->get(TestHelper::class)->createTestDb();
|
$container->get(Helper\TestHelper::class)->createTestDb();
|
||||||
DbTest\DatabaseTestCase::setEntityManager($container->get('em'));
|
DbTest\DatabaseTestCase::setEntityManager($container->get('em'));
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioTest\Shlink;
|
namespace Shlinkio\Shlink;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use PDO;
|
use PDO;
|
||||||
@ -84,7 +84,7 @@ return [
|
|||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
'factories' => [
|
'factories' => [
|
||||||
Common\TestHelper::class => InvokableFactory::class,
|
TestUtils\Helper\TestHelper::class => InvokableFactory::class,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use Shlinkio\Shlink\Core\Entity\Visit;
|
|||||||
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
|
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
|
||||||
use Shlinkio\Shlink\Core\Model\Visitor;
|
use Shlinkio\Shlink\Core\Model\Visitor;
|
||||||
use Shlinkio\Shlink\Core\Repository\ShortUrlRepository;
|
use Shlinkio\Shlink\Core\Repository\ShortUrlRepository;
|
||||||
use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase;
|
use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase;
|
||||||
|
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ namespace ShlinkioTest\Shlink\Core\Repository;
|
|||||||
|
|
||||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||||
use Shlinkio\Shlink\Core\Repository\TagRepository;
|
use Shlinkio\Shlink\Core\Repository\TagRepository;
|
||||||
use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase;
|
use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase;
|
||||||
|
|
||||||
class TagRepositoryTest extends DatabaseTestCase
|
class TagRepositoryTest extends DatabaseTestCase
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@ use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
|||||||
use Shlinkio\Shlink\Core\Model\Visitor;
|
use Shlinkio\Shlink\Core\Model\Visitor;
|
||||||
use Shlinkio\Shlink\Core\Repository\VisitRepository;
|
use Shlinkio\Shlink\Core\Repository\VisitRepository;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
||||||
use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase;
|
use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase;
|
||||||
|
|
||||||
use function Functional\map;
|
use function Functional\map;
|
||||||
use function range;
|
use function range;
|
||||||
|
@ -5,7 +5,7 @@ namespace ShlinkioApiTest\Shlink\Rest\Action;
|
|||||||
|
|
||||||
use Cake\Chronos\Chronos;
|
use Cake\Chronos\Chronos;
|
||||||
use GuzzleHttp\RequestOptions;
|
use GuzzleHttp\RequestOptions;
|
||||||
use ShlinkioTest\Shlink\Common\ApiTest\ApiTestCase;
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||||
|
|
||||||
use function Functional\map;
|
use function Functional\map;
|
||||||
use function range;
|
use function range;
|
||||||
|
@ -3,7 +3,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||||
|
|
||||||
use ShlinkioTest\Shlink\Common\ApiTest\ApiTestCase;
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||||
|
|
||||||
class ListShortUrlsTest extends ApiTestCase
|
class ListShortUrlsTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@ namespace ShlinkioApiTest\Shlink\Rest\Middleware;
|
|||||||
use Shlinkio\Shlink\Rest\Authentication\Plugin\ApiKeyHeaderPlugin;
|
use Shlinkio\Shlink\Rest\Authentication\Plugin\ApiKeyHeaderPlugin;
|
||||||
use Shlinkio\Shlink\Rest\Authentication\RequestToHttpAuthPlugin;
|
use Shlinkio\Shlink\Rest\Authentication\RequestToHttpAuthPlugin;
|
||||||
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||||
use ShlinkioTest\Shlink\Common\ApiTest\ApiTestCase;
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||||
|
|
||||||
use function implode;
|
use function implode;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
namespace ShlinkioApiTest\Shlink\Rest\Middleware;
|
||||||
|
|
||||||
use ShlinkioTest\Shlink\Common\ApiTest\ApiTestCase;
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||||
|
|
||||||
use function explode;
|
use function explode;
|
||||||
|
|
||||||
class OptionsRequestTest extends ApiTestCase
|
class ImplicitOptionsTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
/** @test */
|
/** @test */
|
||||||
public function optionsRequestsReturnEmptyResponse(): void
|
public function optionsRequestsReturnEmptyResponse(): void
|
21
module/TestUtils/LICENSE
Normal file
21
module/TestUtils/LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
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.
|
10
module/TestUtils/README.md
Normal file
10
module/TestUtils/README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# 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.
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Common\ApiTest;
|
namespace Shlinkio\Shlink\TestUtils\ApiTest;
|
||||||
|
|
||||||
use Fig\Http\Message\RequestMethodInterface;
|
use Fig\Http\Message\RequestMethodInterface;
|
||||||
use Fig\Http\Message\StatusCodeInterface;
|
use Fig\Http\Message\StatusCodeInterface;
|
||||||
@ -19,7 +19,7 @@ abstract class ApiTestCase extends TestCase implements StatusCodeInterface, Requ
|
|||||||
|
|
||||||
/** @var ClientInterface */
|
/** @var ClientInterface */
|
||||||
private static $client;
|
private static $client;
|
||||||
/** @var callable */
|
/** @var callable|null */
|
||||||
private static $seedFixtures;
|
private static $seedFixtures;
|
||||||
|
|
||||||
public static function setApiClient(ClientInterface $client): void
|
public static function setApiClient(ClientInterface $client): void
|
||||||
@ -34,7 +34,7 @@ abstract class ApiTestCase extends TestCase implements StatusCodeInterface, Requ
|
|||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
if (self::$seedFixtures) {
|
if (self::$seedFixtures !== null) {
|
||||||
(self::$seedFixtures)();
|
(self::$seedFixtures)();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Common\DbTest;
|
namespace Shlinkio\Shlink\TestUtils\DbTest;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Common;
|
namespace Shlinkio\Shlink\TestUtils\Helper;
|
||||||
|
|
||||||
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
|
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
|
||||||
use Doctrine\Common\DataFixtures\Loader;
|
use Doctrine\Common\DataFixtures\Loader;
|
Loading…
Reference in New Issue
Block a user