ConnectionFactoryTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 OCP\ICacheFactory;
  10. use Test\TestCase;
  11. class ConnectionFactoryTest extends TestCase {
  12. public function splitHostFromPortAndSocketData() {
  13. return [
  14. ['127.0.0.1', ['host' => '127.0.0.1']],
  15. ['db.example.org', ['host' => 'db.example.org']],
  16. ['unix', ['host' => 'unix']],
  17. ['[::1]', ['host' => '[::1]']],
  18. ['127.0.0.1:3306', ['host' => '127.0.0.1', 'port' => 3306]],
  19. ['db.example.org:3306', ['host' => 'db.example.org', 'port' => 3306]],
  20. ['unix:3306', ['host' => 'unix', 'port' => 3306]],
  21. ['[::1]:3306', ['host' => '[::1]', 'port' => 3306]],
  22. ['unix:/socket', ['host' => 'unix', 'unix_socket' => '/socket']],
  23. ];
  24. }
  25. /**
  26. * @dataProvider splitHostFromPortAndSocketData
  27. * @param string $host
  28. * @param array $expected
  29. */
  30. public function testSplitHostFromPortAndSocket($host, array $expected) {
  31. /** @var SystemConfig $config */
  32. $config = $this->createMock(SystemConfig::class);
  33. $cacheFactory = $this->createMock(ICacheFactory::class);
  34. $factory = new ConnectionFactory($config, $cacheFactory);
  35. $this->assertEquals($expected, self::invokePrivate($factory, 'splitHostFromPortAndSocket', [$host]));
  36. }
  37. }