2019-04-18 03:37:38 -05:00
|
|
|
<?php
|
2019-10-05 10:26:10 -05:00
|
|
|
|
2019-04-18 03:37:38 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-09-13 13:03:53 -05:00
|
|
|
namespace ShlinkioTest\Shlink\Core\Config;
|
2019-04-18 03:37:38 -05:00
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-09-13 13:03:53 -05:00
|
|
|
use Shlinkio\Shlink\Core\Config\SimplifiedConfigParser;
|
2019-04-18 03:37:38 -05:00
|
|
|
|
|
|
|
use function array_merge;
|
|
|
|
|
2019-08-07 11:45:28 -05:00
|
|
|
class SimplifiedConfigParserTest extends TestCase
|
2019-04-18 03:37:38 -05:00
|
|
|
{
|
2019-12-31 08:38:37 -06:00
|
|
|
private SimplifiedConfigParser $postProcessor;
|
2019-04-18 03:37:38 -05:00
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
2019-08-07 11:45:28 -05:00
|
|
|
$this->postProcessor = new SimplifiedConfigParser();
|
2019-04-18 03:37:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function properlyMapsSimplifiedConfig(): void
|
|
|
|
{
|
|
|
|
$config = [
|
|
|
|
'app_options' => [
|
|
|
|
'disable_track_param' => 'foo',
|
|
|
|
],
|
|
|
|
|
|
|
|
'entity_manager' => [
|
|
|
|
'connection' => [
|
|
|
|
'driver' => 'mysql',
|
|
|
|
'host' => 'shlink_db',
|
|
|
|
'port' => '3306',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$simplified = [
|
|
|
|
'disable_track_param' => 'bar',
|
|
|
|
'short_domain_schema' => 'https',
|
|
|
|
'short_domain_host' => 'doma.in',
|
2019-12-31 09:29:32 -06:00
|
|
|
'validate_url' => true,
|
2019-04-18 03:37:38 -05:00
|
|
|
'delete_short_url_threshold' => 50,
|
2019-12-31 08:38:37 -06:00
|
|
|
'invalid_short_url_redirect_to' => 'foobar.com',
|
2019-08-07 11:45:28 -05:00
|
|
|
'redis_servers' => [
|
|
|
|
'tcp://1.1.1.1:1111',
|
|
|
|
'tcp://1.2.2.2:2222',
|
|
|
|
],
|
2019-04-18 03:37:38 -05:00
|
|
|
'db_config' => [
|
|
|
|
'dbname' => 'shlink',
|
|
|
|
'user' => 'foo',
|
|
|
|
'password' => 'bar',
|
|
|
|
'port' => '1234',
|
|
|
|
],
|
2019-09-13 13:03:53 -05:00
|
|
|
'base_path' => '/foo/bar',
|
2019-11-10 05:04:14 -06:00
|
|
|
'task_worker_num' => 50,
|
2019-12-28 09:42:21 -06:00
|
|
|
'visits_webhooks' => [
|
|
|
|
'http://my-api.com/api/v2.3/notify',
|
|
|
|
'https://third-party.io/foo',
|
|
|
|
],
|
2019-04-18 03:37:38 -05:00
|
|
|
];
|
|
|
|
$expected = [
|
|
|
|
'app_options' => [
|
|
|
|
'disable_track_param' => 'bar',
|
|
|
|
],
|
|
|
|
|
|
|
|
'entity_manager' => [
|
|
|
|
'connection' => [
|
|
|
|
'driver' => 'mysql',
|
|
|
|
'host' => 'shlink_db',
|
|
|
|
'dbname' => 'shlink',
|
|
|
|
'user' => 'foo',
|
|
|
|
'password' => 'bar',
|
|
|
|
'port' => '1234',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
|
|
|
|
'url_shortener' => [
|
|
|
|
'domain' => [
|
|
|
|
'schema' => 'https',
|
|
|
|
'hostname' => 'doma.in',
|
|
|
|
],
|
2019-12-31 09:29:32 -06:00
|
|
|
'validate_url' => true,
|
2019-12-28 09:42:21 -06:00
|
|
|
'visits_webhooks' => [
|
|
|
|
'http://my-api.com/api/v2.3/notify',
|
|
|
|
'https://third-party.io/foo',
|
|
|
|
],
|
2019-04-18 03:37:38 -05:00
|
|
|
],
|
|
|
|
|
|
|
|
'delete_short_urls' => [
|
|
|
|
'visits_threshold' => 50,
|
|
|
|
'check_visits_threshold' => true,
|
|
|
|
],
|
2019-08-07 09:16:53 -05:00
|
|
|
|
|
|
|
'dependencies' => [
|
|
|
|
'aliases' => [
|
|
|
|
'lock_store' => 'redis_lock_store',
|
|
|
|
],
|
|
|
|
],
|
2019-08-07 11:45:28 -05:00
|
|
|
|
|
|
|
'redis' => [
|
|
|
|
'servers' => [
|
|
|
|
'tcp://1.1.1.1:1111',
|
|
|
|
'tcp://1.2.2.2:2222',
|
|
|
|
],
|
|
|
|
],
|
2019-09-13 13:03:53 -05:00
|
|
|
|
|
|
|
'router' => [
|
|
|
|
'base_path' => '/foo/bar',
|
|
|
|
],
|
2019-11-02 05:30:09 -05:00
|
|
|
|
|
|
|
'not_found_redirects' => [
|
|
|
|
'invalid_short_url' => 'foobar.com',
|
|
|
|
],
|
2019-11-10 05:04:14 -06:00
|
|
|
|
|
|
|
'zend-expressive-swoole' => [
|
|
|
|
'swoole-http-server' => [
|
|
|
|
'options' => [
|
|
|
|
'task_worker_num' => 50,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2019-04-18 03:37:38 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
$result = ($this->postProcessor)(array_merge($config, $simplified));
|
|
|
|
|
|
|
|
$this->assertEquals(array_merge($expected, $simplified), $result);
|
|
|
|
}
|
|
|
|
}
|