123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- declare(strict_types=1);
- namespace ShlinkioTest\Shlink\Core\Config;
- use PHPUnit\Framework\TestCase;
- use Shlinkio\Shlink\Core\Config\SimplifiedConfigParser;
- use function array_merge;
- class SimplifiedConfigParserTest extends TestCase
- {
- private SimplifiedConfigParser $postProcessor;
- public function setUp(): void
- {
- $this->postProcessor = new SimplifiedConfigParser();
- }
- /** @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',
- 'validate_url' => true,
- 'delete_short_url_threshold' => 50,
- 'invalid_short_url_redirect_to' => 'foobar.com',
- 'redis_servers' => [
- 'tcp://1.1.1.1:1111',
- 'tcp://1.2.2.2:2222',
- ],
- 'db_config' => [
- 'dbname' => 'shlink',
- 'user' => 'foo',
- 'password' => 'bar',
- 'port' => '1234',
- ],
- 'base_path' => '/foo/bar',
- 'task_worker_num' => 50,
- 'visits_webhooks' => [
- 'http://my-api.com/api/v2.3/notify',
- 'https://third-party.io/foo',
- ],
- ];
- $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',
- ],
- 'validate_url' => true,
- 'visits_webhooks' => [
- 'http://my-api.com/api/v2.3/notify',
- 'https://third-party.io/foo',
- ],
- ],
- 'delete_short_urls' => [
- 'visits_threshold' => 50,
- 'check_visits_threshold' => true,
- ],
- 'dependencies' => [
- 'aliases' => [
- 'lock_store' => 'redis_lock_store',
- ],
- ],
- 'redis' => [
- 'servers' => [
- 'tcp://1.1.1.1:1111',
- 'tcp://1.2.2.2:2222',
- ],
- ],
- 'router' => [
- 'base_path' => '/foo/bar',
- ],
- 'not_found_redirects' => [
- 'invalid_short_url' => 'foobar.com',
- ],
- 'mezzio-swoole' => [
- 'swoole-http-server' => [
- 'options' => [
- 'task_worker_num' => 50,
- ],
- ],
- ],
- ];
- $result = ($this->postProcessor)(array_merge($config, $simplified));
- $this->assertEquals(array_merge($expected, $simplified), $result);
- }
- }
|