Skip to content

Commit be771e6

Browse files
committed
[transport] Fs transport dsn must contain one extra "/"
1 parent a29652d commit be771e6

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

pkg/enqueue/Consumption/Exception/InvalidArgumentException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class InvalidArgumentException extends \InvalidArgumentException implements Exce
1212
*/
1313
public static function assertInstanceOf($argument, $class)
1414
{
15-
if (!$argument instanceof $class) {
15+
if (false == $argument instanceof $class) {
1616
throw new static(sprintf(
1717
'The argument must be an instance of %s but got %s.',
1818
$class,

pkg/enqueue/Tests/Functions/DsnToConnectionFactoryFunctionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static function provideDSNs()
5454

5555
yield ['file://', FsConnectionFactory::class];
5656

57-
yield ['file://foo/bar/baz', FsConnectionFactory::class];
57+
yield ['file:///foo/bar/baz', FsConnectionFactory::class];
5858

5959
yield ['null://', NullConnectionFactory::class];
6060
}

pkg/enqueue/Tests/Functions/DsnToContextFunctionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static function provideDSNs()
5454

5555
yield ['file://', FsContext::class];
5656

57-
yield ['file:/'.sys_get_temp_dir(), FsContext::class];
57+
yield ['file://'.sys_get_temp_dir(), FsContext::class];
5858

5959
yield ['null://', NullContext::class];
6060
}

pkg/fs/FsConnectionFactory.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ private function parseDsn($dsn)
6262
return ['path' => $dsn];
6363
}
6464

65-
$scheme = parse_url($dsn, PHP_URL_SCHEME);
65+
if (false === strpos($dsn, 'file://')) {
66+
throw new \LogicException(sprintf('The given DSN "%s" is not supported. Must start with "file://".', $dsn));
67+
}
68+
69+
$dsn = substr($dsn, 7);
70+
6671
$path = parse_url($dsn, PHP_URL_PATH);
67-
$host = parse_url($dsn, PHP_URL_HOST);
6872
$query = parse_url($dsn, PHP_URL_QUERY);
69-
if (false === $scheme) {
70-
throw new \LogicException(sprintf('Failed to parse DSN "%s"', $dsn));
71-
}
7273

73-
if ('file' !== $scheme) {
74-
throw new \LogicException('The given DSN scheme "%s" is not supported. Could be "file" only.');
74+
if ('/' != $path[0]) {
75+
throw new \LogicException(sprintf('Failed to parse DSN path "%s". The path must start with "/"', $path));
7576
}
7677

7778
if ($query) {
@@ -87,7 +88,7 @@ private function parseDsn($dsn)
8788
$config['chmod'] = intval($config['chmod'], 8);
8889
}
8990

90-
$config['path'] = sprintf('/%s%s', $host, $path);
91+
$config['path'] = $path;
9192

9293
return $config;
9394
}

pkg/fs/Tests/FsConnectionFactoryConfigTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ public function testThrowNeitherArrayStringNorNullGivenAsConfig()
2424
public function testThrowIfSchemeIsNotAmqp()
2525
{
2626
$this->expectException(\LogicException::class);
27-
$this->expectExceptionMessage('The given DSN scheme "%s" is not supported. Could be "file" only.');
27+
$this->expectExceptionMessage('The given DSN "http://example.com" is not supported. Must start with "file://');
2828

2929
new FsConnectionFactory('http://example.com');
3030
}
3131

3232
public function testThrowIfDsnCouldNotBeParsed()
3333
{
3434
$this->expectException(\LogicException::class);
35-
$this->expectExceptionMessage('Failed to parse DSN "file://:@/"');
35+
$this->expectExceptionMessage('Failed to parse DSN path ":@/". The path must start with "/"');
3636

3737
new FsConnectionFactory('file://:@/');
3838
}
@@ -89,27 +89,27 @@ public static function provideConfigs()
8989
];
9090

9191
yield [
92-
__DIR__,
92+
'/foo/bar/baz',
9393
[
94-
'path' => __DIR__,
94+
'path' => '/foo/bar/baz',
9595
'pre_fetch_count' => 1,
9696
'chmod' => 0600,
9797
],
9898
];
9999

100100
yield [
101-
'file:/'.__DIR__,
101+
'file:///foo/bar/baz',
102102
[
103-
'path' => __DIR__,
103+
'path' => '/foo/bar/baz',
104104
'pre_fetch_count' => 1,
105105
'chmod' => 0600,
106106
],
107107
];
108108

109109
yield [
110-
'file:/'.__DIR__.'?pre_fetch_count=100&chmod=0666',
110+
'file:///foo/bar/baz?pre_fetch_count=100&chmod=0666',
111111
[
112-
'path' => __DIR__,
112+
'path' => '/foo/bar/baz',
113113
'pre_fetch_count' => 100,
114114
'chmod' => 0666,
115115
],

0 commit comments

Comments
 (0)