-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathHttpFactoryTest.php
54 lines (44 loc) · 1.63 KB
/
HttpFactoryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* League.Uri (https://uri.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace League\Uri;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriFactoryInterface;
final class HttpFactoryTest extends TestCase
{
protected function createUriFactory(): UriFactoryInterface
{
return new HttpFactory();
}
public function testCreateUri(): void
{
$uri = $this->createUriFactory()->createUri('https://nyholm.tech/foo');
self::assertInstanceOf(Http::class, $uri);
self::assertEquals('https://nyholm.tech/foo', $uri->__toString());
}
#[Test]
#[DataProvider('invalidUriWithWhitespaceProvider')]
public function it_fails_parsing_uri_string_with_whitespace(string $uri): void
{
$this->expectException(InvalidArgumentException::class);
$this->createUriFactory()->createUri($uri);
}
public static function invalidUriWithWhitespaceProvider(): iterable
{
yield 'uri containing only whitespaces' => ['uri' => ' '];
yield 'uri starting with whitespaces' => ['uri' => ' https://a/b?c'];
yield 'uri ending with whitespaces' => ['uri' => 'https://a/b?c '];
yield 'uri surrounded with whitespaces' => ['uri' => ' https://a/b?c '];
yield 'uri containing whitespaces' => ['uri' => 'https://a/b ?c'];
}
}