Skip to content

feat: Support path in STACKKIT_CLOUD_TASKS_HANDLER #127

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
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
15 changes: 5 additions & 10 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,13 @@ public static function getHandler($handler): string
));
}

// Versions 1.x and 2.x required the full path (e.g. my-app.com/handle-task). In 3.x and beyond
// it is no longer necessary to also include the path and simply setting the handler
// URL is enough. If someone upgrades and forgets we will warn them here.
if (!empty($parse['path'])) {
throw new Exception(
'Unable to push task to Cloud Tasks because the task handler URL (' . $handler . ') is not ' .
'compatible. To fix this, please remove \'' . $parse['path'] . '\' from the URL, ' .
'or copy from here: STACKKIT_CLOUD_TASKS_HANDLER=' . $parse['scheme'] . '://' . $parse['host']
);
$trimmedHandlerUrl = rtrim($handler, '/');

if (!str_ends_with($trimmedHandlerUrl, '/handle-task')) {
return "$trimmedHandlerUrl/handle-task";
}

return $handler . '/handle-task';
return $trimmedHandlerUrl;
} catch (UrlException $e) {
throw new Exception(
'Unable to push task to Cloud Tasks because the task handler URL (' . $handler . ') is ' .
Expand Down
27 changes: 27 additions & 0 deletions tests/ConfigHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Tests;

use Stackkit\LaravelGoogleCloudTasksQueue\Config;

class ConfigHandlerTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider handlerDataProvider
*/
public function test_it_allows_a_handler_url_to_contain_path(string $handler, string $expectedHandler): void
{
self::assertSame($expectedHandler, Config::getHandler($handler));
}

public function handlerDataProvider(): array
{
return [
['https://example.com', 'https://example.com/handle-task'],
['https://example.com/my/path', 'https://example.com/my/path/handle-task'],
['https://example.com/trailing/slashes//', 'https://example.com/trailing/slashes/handle-task'],
['https://example.com/handle-task', 'https://example.com/handle-task'],
['https://example.com/handle-task/', 'https://example.com/handle-task'],
];
}
}