Skip to content

[transport] Fs transport dsn must contain one extra "/" #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue/Tests/Functions/DsnToContextFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
17 changes: 9 additions & 8 deletions pkg/fs/FsConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/fs/Tests/FsConnectionFactoryConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ 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');
}

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://:@/');
}
Expand Down Expand Up @@ -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,
],
Expand Down