Merge pull request #457 from acelaya/feature/test-utils-module

Created TestUtils module
This commit is contained in:
Alejandro Celaya 2019-08-11 16:38:27 +02:00 committed by GitHub
commit 1fd677df5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 54 additions and 25 deletions

View File

@ -91,12 +91,10 @@
"module/Core/test",
"module/Core/test-db"
],
"ShlinkioTest\\Shlink\\Common\\": [
"module/Common/test",
"module/Common/test-db"
],
"ShlinkioTest\\Shlink\\Common\\": "module/Common/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": {

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common;
namespace Shlinkio\Shlink\TestUtils;
use Doctrine\ORM\EntityManager;
use Psr\Container\ContainerInterface;
@ -16,7 +16,7 @@ if (! file_exists('.env')) {
/** @var ContainerInterface $container */
$container = require __DIR__ . '/../container.php';
$testHelper = $container->get(TestHelper::class);
$testHelper = $container->get(Helper\TestHelper::class);
$config = $container->get('config');
$em = $container->get(EntityManager::class);

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common;
namespace Shlinkio\Shlink\TestUtils;
use Psr\Container\ContainerInterface;
@ -15,5 +15,5 @@ if (! file_exists('.env')) {
/** @var ContainerInterface $container */
$container = require __DIR__ . '/../container.php';
$container->get(TestHelper::class)->createTestDb();
$container->get(Helper\TestHelper::class)->createTestDb();
DbTest\DatabaseTestCase::setEntityManager($container->get('em'));

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink;
namespace Shlinkio\Shlink;
use GuzzleHttp\Client;
use PDO;
@ -84,7 +84,7 @@ return [
]),
],
'factories' => [
Common\TestHelper::class => InvokableFactory::class,
TestUtils\Helper\TestHelper::class => InvokableFactory::class,
],
],

View File

@ -11,7 +11,7 @@ use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Model\Visitor;
use Shlinkio\Shlink\Core\Repository\ShortUrlRepository;
use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase;
use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase;
use function count;

View File

@ -5,7 +5,7 @@ namespace ShlinkioTest\Shlink\Core\Repository;
use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Repository\TagRepository;
use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase;
use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase;
class TagRepositoryTest extends DatabaseTestCase
{

View File

@ -11,7 +11,7 @@ use Shlinkio\Shlink\Core\Entity\VisitLocation;
use Shlinkio\Shlink\Core\Model\Visitor;
use Shlinkio\Shlink\Core\Repository\VisitRepository;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase;
use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase;
use function Functional\map;
use function range;

View File

@ -5,7 +5,7 @@ namespace ShlinkioApiTest\Shlink\Rest\Action;
use Cake\Chronos\Chronos;
use GuzzleHttp\RequestOptions;
use ShlinkioTest\Shlink\Common\ApiTest\ApiTestCase;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
use function Functional\map;
use function range;

View File

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Rest\Action;
use ShlinkioTest\Shlink\Common\ApiTest\ApiTestCase;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
class ListShortUrlsTest extends ApiTestCase
{

View File

@ -6,7 +6,7 @@ namespace ShlinkioApiTest\Shlink\Rest\Middleware;
use Shlinkio\Shlink\Rest\Authentication\Plugin\ApiKeyHeaderPlugin;
use Shlinkio\Shlink\Rest\Authentication\RequestToHttpAuthPlugin;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use ShlinkioTest\Shlink\Common\ApiTest\ApiTestCase;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
use function implode;
use function sprintf;

View File

@ -1,13 +1,13 @@
<?php
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;
class OptionsRequestTest extends ApiTestCase
class ImplicitOptionsTest extends ApiTestCase
{
/** @test */
public function optionsRequestsReturnEmptyResponse(): void

21
module/TestUtils/LICENSE Normal file
View 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.

View 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.

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common\ApiTest;
namespace Shlinkio\Shlink\TestUtils\ApiTest;
use Fig\Http\Message\RequestMethodInterface;
use Fig\Http\Message\StatusCodeInterface;
@ -19,7 +19,7 @@ abstract class ApiTestCase extends TestCase implements StatusCodeInterface, Requ
/** @var ClientInterface */
private static $client;
/** @var callable */
/** @var callable|null */
private static $seedFixtures;
public static function setApiClient(ClientInterface $client): void
@ -34,7 +34,7 @@ abstract class ApiTestCase extends TestCase implements StatusCodeInterface, Requ
public function setUp(): void
{
if (self::$seedFixtures) {
if (self::$seedFixtures !== null) {
(self::$seedFixtures)();
}
}

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common\DbTest;
namespace Shlinkio\Shlink\TestUtils\DbTest;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common;
namespace Shlinkio\Shlink\TestUtils\Helper;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Loader;