diff --git a/pkg/enqueue/Consumption/Exception/InvalidArgumentException.php b/pkg/enqueue/Consumption/Exception/InvalidArgumentException.php index 35ab5df2b..da6015d27 100644 --- a/pkg/enqueue/Consumption/Exception/InvalidArgumentException.php +++ b/pkg/enqueue/Consumption/Exception/InvalidArgumentException.php @@ -12,7 +12,7 @@ class InvalidArgumentException extends \InvalidArgumentException implements Exce */ public static function assertInstanceOf($argument, $class) { - if (!$argument instanceof $class) { + if (false == $argument instanceof $class) { throw new static(sprintf( 'The argument must be an instance of %s but got %s.', $class, diff --git a/pkg/enqueue/Tests/Functions/DsnToConnectionFactoryFunctionTest.php b/pkg/enqueue/Tests/Functions/DsnToConnectionFactoryFunctionTest.php index 6ae301b26..ecc106641 100644 --- a/pkg/enqueue/Tests/Functions/DsnToConnectionFactoryFunctionTest.php +++ b/pkg/enqueue/Tests/Functions/DsnToConnectionFactoryFunctionTest.php @@ -54,7 +54,7 @@ public static function provideDSNs() yield ['file://', FsConnectionFactory::class]; - yield ['file://foo/bar/baz', FsConnectionFactory::class]; + yield ['file:///foo/bar/baz', FsConnectionFactory::class]; yield ['null://', NullConnectionFactory::class]; } diff --git a/pkg/enqueue/Tests/Functions/DsnToContextFunctionTest.php b/pkg/enqueue/Tests/Functions/DsnToContextFunctionTest.php index 74e646e0f..d088bae93 100644 --- a/pkg/enqueue/Tests/Functions/DsnToContextFunctionTest.php +++ b/pkg/enqueue/Tests/Functions/DsnToContextFunctionTest.php @@ -54,7 +54,7 @@ public static function provideDSNs() yield ['file://', FsContext::class]; - yield ['file:/'.sys_get_temp_dir(), FsContext::class]; + yield ['file://'.sys_get_temp_dir(), FsContext::class]; yield ['null://', NullContext::class]; } diff --git a/pkg/fs/FsConnectionFactory.php b/pkg/fs/FsConnectionFactory.php index 2883da7ae..66efc3796 100644 --- a/pkg/fs/FsConnectionFactory.php +++ b/pkg/fs/FsConnectionFactory.php @@ -62,16 +62,17 @@ private function parseDsn($dsn) return ['path' => $dsn]; } - $scheme = parse_url(https://github.com/$dsn,%20PHP_URL_SCHEME); + if (false === strpos($dsn, 'file://')) { + throw new \LogicException(sprintf('The given DSN "%s" is not supported. Must start with "file://".', $dsn)); + } + + $dsn = substr($dsn, 7); + $path = parse_url(https://github.com/$dsn,%20PHP_URL_PATH); - $host = parse_url(https://github.com/$dsn,%20PHP_URL_HOST); $query = parse_url(https://github.com/$dsn,%20PHP_URL_QUERY); - if (false === $scheme) { - throw new \LogicException(sprintf('Failed to parse DSN "%s"', $dsn)); - } - if ('file' !== $scheme) { - throw new \LogicException('The given DSN scheme "%s" is not supported. Could be "file" only.'); + if ('/' != $path[0]) { + throw new \LogicException(sprintf('Failed to parse DSN path "%s". The path must start with "/"', $path)); } if ($query) { @@ -87,7 +88,7 @@ private function parseDsn($dsn) $config['chmod'] = intval($config['chmod'], 8); } - $config['path'] = sprintf('/%s%s', $host, $path); + $config['path'] = $path; return $config; } diff --git a/pkg/fs/Tests/FsConnectionFactoryConfigTest.php b/pkg/fs/Tests/FsConnectionFactoryConfigTest.php index 51619fe3a..71c52c2d0 100644 --- a/pkg/fs/Tests/FsConnectionFactoryConfigTest.php +++ b/pkg/fs/Tests/FsConnectionFactoryConfigTest.php @@ -24,7 +24,7 @@ public function testThrowNeitherArrayStringNorNullGivenAsConfig() public function testThrowIfSchemeIsNotAmqp() { $this->expectException(\LogicException::class); - $this->expectExceptionMessage('The given DSN scheme "%s" is not supported. Could be "file" only.'); + $this->expectExceptionMessage('The given DSN "http://example.com/" is not supported. Must start with "file://'); new FsConnectionFactory('http://example.com/'); } @@ -32,7 +32,7 @@ public function testThrowIfSchemeIsNotAmqp() public function testThrowIfDsnCouldNotBeParsed() { $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Failed to parse DSN "file://:@/"'); + $this->expectExceptionMessage('Failed to parse DSN path ":@/". The path must start with "/"'); new FsConnectionFactory('file://:@/'); } @@ -89,27 +89,27 @@ public static function provideConfigs() ]; yield [ - __DIR__, + '/foo/bar/baz', [ - 'path' => __DIR__, + 'path' => '/foo/bar/baz', 'pre_fetch_count' => 1, 'chmod' => 0600, ], ]; yield [ - 'file:/'.__DIR__, + 'file:///foo/bar/baz', [ - 'path' => __DIR__, + 'path' => '/foo/bar/baz', 'pre_fetch_count' => 1, 'chmod' => 0600, ], ]; yield [ - 'file:/'.__DIR__.'?pre_fetch_count=100&chmod=0666', + 'file:///foo/bar/baz?pre_fetch_count=100&chmod=0666', [ - 'path' => __DIR__, + 'path' => '/foo/bar/baz', 'pre_fetch_count' => 100, 'chmod' => 0666, ],