shlink/config/test/bootstrap_api_tests.php

34 lines
1.1 KiB
PHP
Raw Normal View History

2019-01-26 12:19:20 +03:00
<?php
2019-10-05 18:26:10 +03:00
2019-01-26 12:19:20 +03:00
declare(strict_types=1);
2019-08-11 17:30:46 +03:00
namespace Shlinkio\Shlink\TestUtils;
2019-01-26 12:19:20 +03:00
2019-01-27 14:14:18 +03:00
use Doctrine\ORM\EntityManager;
2019-01-26 12:19:20 +03:00
use Psr\Container\ContainerInterface;
2020-09-26 11:43:50 +03:00
use function register_shutdown_function;
use function sprintf;
use const ShlinkioTest\Shlink\SWOOLE_TESTING_HOST;
use const ShlinkioTest\Shlink\SWOOLE_TESTING_PORT;
2019-01-26 12:19:20 +03:00
/** @var ContainerInterface $container */
$container = require __DIR__ . '/../container.php';
2019-08-11 17:30:46 +03:00
$testHelper = $container->get(Helper\TestHelper::class);
2019-01-27 14:14:18 +03:00
$config = $container->get('config');
$em = $container->get(EntityManager::class);
2020-09-26 11:43:50 +03:00
$httpClient = $container->get('shlink_test_api_client');
2021-12-10 19:45:50 +03:00
// Dump code coverage when process shuts down
2020-09-26 11:43:50 +03:00
register_shutdown_function(function () use ($httpClient): void {
$httpClient->request(
'GET',
sprintf('http://%s:%s/api-tests/stop-coverage', SWOOLE_TESTING_HOST, SWOOLE_TESTING_PORT),
);
});
2019-01-27 14:14:18 +03:00
2021-10-23 16:44:56 +03:00
$testHelper->createTestDb(['bin/cli', 'db:create'], ['bin/cli', 'db:migrate']);
2020-09-26 11:43:50 +03:00
ApiTest\ApiTestCase::setApiClient($httpClient);
ApiTest\ApiTestCase::setSeedFixturesCallback(fn () => $testHelper->seedFixtures($em, $config['data_fixtures'] ?? []));