ConnectionFactoryTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Test\DB;
  7. use OC\DB\ConnectionFactory;
  8. use OC\SystemConfig;
  9. use Test\TestCase;
  10. class ConnectionFactoryTest extends TestCase {
  11. public function splitHostFromPortAndSocketData() {
  12. return [
  13. ['127.0.0.1', ['host' => '127.0.0.1']],
  14. ['db.example.org', ['host' => 'db.example.org']],
  15. ['unix', ['host' => 'unix']],
  16. ['[::1]', ['host' => '[::1]']],
  17. ['127.0.0.1:3306', ['host' => '127.0.0.1', 'port' => 3306]],
  18. ['db.example.org:3306', ['host' => 'db.example.org', 'port' => 3306]],
  19. ['unix:3306', ['host' => 'unix', 'port' => 3306]],
  20. ['[::1]:3306', ['host' => '[::1]', 'port' => 3306]],
  21. ['unix:/socket', ['host' => 'unix', 'unix_socket' => '/socket']],
  22. ];
  23. }
  24. /**
  25. * @dataProvider splitHostFromPortAndSocketData
  26. * @param string $host
  27. * @param array $expected
  28. */
  29. public function testSplitHostFromPortAndSocket($host, array $expected) {
  30. /** @var SystemConfig $config */
  31. $config = $this->createMock(SystemConfig::class);
  32. $factory = new ConnectionFactory($config);
  33. $this->assertEquals($expected, self::invokePrivate($factory, 'splitHostFromPortAndSocket', [$host]));
  34. }
  35. }