SimplifiedConfigParserTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. declare(strict_types=1);
  3. namespace ShlinkioTest\Shlink\Core\Config;
  4. use PHPUnit\Framework\TestCase;
  5. use Shlinkio\Shlink\Core\Config\SimplifiedConfigParser;
  6. use function array_merge;
  7. class SimplifiedConfigParserTest extends TestCase
  8. {
  9. private SimplifiedConfigParser $postProcessor;
  10. public function setUp(): void
  11. {
  12. $this->postProcessor = new SimplifiedConfigParser();
  13. }
  14. /** @test */
  15. public function properlyMapsSimplifiedConfig(): void
  16. {
  17. $config = [
  18. 'app_options' => [
  19. 'disable_track_param' => 'foo',
  20. ],
  21. 'entity_manager' => [
  22. 'connection' => [
  23. 'driver' => 'mysql',
  24. 'host' => 'shlink_db',
  25. 'port' => '3306',
  26. ],
  27. ],
  28. ];
  29. $simplified = [
  30. 'disable_track_param' => 'bar',
  31. 'short_domain_schema' => 'https',
  32. 'short_domain_host' => 'doma.in',
  33. 'validate_url' => true,
  34. 'delete_short_url_threshold' => 50,
  35. 'invalid_short_url_redirect_to' => 'foobar.com',
  36. 'redis_servers' => [
  37. 'tcp://1.1.1.1:1111',
  38. 'tcp://1.2.2.2:2222',
  39. ],
  40. 'db_config' => [
  41. 'dbname' => 'shlink',
  42. 'user' => 'foo',
  43. 'password' => 'bar',
  44. 'port' => '1234',
  45. ],
  46. 'base_path' => '/foo/bar',
  47. 'task_worker_num' => 50,
  48. 'visits_webhooks' => [
  49. 'http://my-api.com/api/v2.3/notify',
  50. 'https://third-party.io/foo',
  51. ],
  52. ];
  53. $expected = [
  54. 'app_options' => [
  55. 'disable_track_param' => 'bar',
  56. ],
  57. 'entity_manager' => [
  58. 'connection' => [
  59. 'driver' => 'mysql',
  60. 'host' => 'shlink_db',
  61. 'dbname' => 'shlink',
  62. 'user' => 'foo',
  63. 'password' => 'bar',
  64. 'port' => '1234',
  65. ],
  66. ],
  67. 'url_shortener' => [
  68. 'domain' => [
  69. 'schema' => 'https',
  70. 'hostname' => 'doma.in',
  71. ],
  72. 'validate_url' => true,
  73. 'visits_webhooks' => [
  74. 'http://my-api.com/api/v2.3/notify',
  75. 'https://third-party.io/foo',
  76. ],
  77. ],
  78. 'delete_short_urls' => [
  79. 'visits_threshold' => 50,
  80. 'check_visits_threshold' => true,
  81. ],
  82. 'dependencies' => [
  83. 'aliases' => [
  84. 'lock_store' => 'redis_lock_store',
  85. ],
  86. ],
  87. 'redis' => [
  88. 'servers' => [
  89. 'tcp://1.1.1.1:1111',
  90. 'tcp://1.2.2.2:2222',
  91. ],
  92. ],
  93. 'router' => [
  94. 'base_path' => '/foo/bar',
  95. ],
  96. 'not_found_redirects' => [
  97. 'invalid_short_url' => 'foobar.com',
  98. ],
  99. 'mezzio-swoole' => [
  100. 'swoole-http-server' => [
  101. 'options' => [
  102. 'task_worker_num' => 50,
  103. ],
  104. ],
  105. ],
  106. ];
  107. $result = ($this->postProcessor)(array_merge($config, $simplified));
  108. $this->assertEquals(array_merge($expected, $simplified), $result);
  109. }
  110. }