-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* @link https://github.com/studiometa/twig-toolkit | ||
* @copyright Studio Meta | ||
* @license https://github.com/studiometa/twig-toolkit/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Studiometa\TwigToolkit\Helpers; | ||
|
||
use Twig\Environment; | ||
use Spatie\Url\Url as UrlCore; | ||
|
||
/** | ||
* Url manipulation helper. | ||
* | ||
* @author Studio Meta <[email protected]> | ||
* @since 1.3.1 | ||
*/ | ||
class Url extends UrlCore | ||
{ | ||
/** | ||
* @return self | ||
*/ | ||
public static function fromString(?string $url) | ||
{ | ||
return parent::fromString($url ?? ''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
use function Spatie\Snapshots\assertMatchesSnapshot; | ||
use Studiometa\TwigToolkit\Helpers\Url; | ||
|
||
test('The `Url` class should work with null given as $url', function () { | ||
expect(function () { | ||
Url::fromString(null); | ||
})->not->toThrow('type string, null given'); | ||
|
||
expect((string)Url::fromString(null))->toBe(''); | ||
expect((string)Url::fromString(null)->withHost('fqdn.tld'))->toBe('//fqdn.tld'); | ||
}); |