‪TYPO3CMS  10.4
RequestFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\RequestFactoryInterface;
21 use Psr\Http\Message\RequestInterface;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪RequestFactoryTest extends UnitTestCase
29 {
34  {
35  $factory = new ‪RequestFactory();
36  self::assertInstanceOf(RequestFactoryInterface::class, $factory);
37  }
38 
42  public function ‪testRequestHasMethodSet()
43  {
44  $factory = new ‪RequestFactory();
45  $request = $factory->createRequest('POST', '/');
46  self::assertSame('POST', $request->getMethod());
47  }
48 
53  {
54  $factory = new ‪RequestFactory();
55  $request = $factory->createRequest('GET', '/');
56  $body = $request->getBody();
57 
58  self::assertInstanceOf(RequestInterface::class, $request);
59 
60  self::assertSame('', $body->__toString());
61  self::assertSame(0, $body->getSize());
62  self::assertTrue($body->isSeekable());
63 
64  $body->write('Foo');
65  self::assertSame(3, $body->getSize());
66  self::assertSame('Foo', $body->__toString());
67  }
68 
73  {
74  return [
75  'true' => [true],
76  'false' => [false],
77  'int' => [1],
78  'float' => [1.1],
79  'array' => [['http://example.com']],
80  'stdClass' => [(object)['href' => 'http://example.com']],
81  ];
82  }
83 
89  {
90  $this->expectException(\InvalidArgumentException::class);
91  $this->expectExceptionCode(1436717272);
92  $factory = new ‪RequestFactory();
93  $factory->createRequest('GET', $uri);
94  }
95 
100  {
101  $this->expectException(\InvalidArgumentException::class);
102  $this->expectExceptionCode(1436717275);
103  $factory = new ‪RequestFactory();
104  $factory->createRequest('BOGUS-BODY', '/');
105  }
106 }
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\invalidRequestUriDataProvider
‪array invalidRequestUriDataProvider()
Definition: RequestFactoryTest.php:72
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\testRequestHasMethodSet
‪testRequestHasMethodSet()
Definition: RequestFactoryTest.php:42
‪TYPO3\CMS\Core\Tests\Unit\Http
Definition: ApplicationTypeTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\testRequestFactoryHasAWritableEmptyBody
‪testRequestFactoryHasAWritableEmptyBody()
Definition: RequestFactoryTest.php:52
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\raisesExceptionForInvalidMethod
‪raisesExceptionForInvalidMethod()
Definition: RequestFactoryTest.php:99
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\implementsPsr17FactoryInterface
‪implementsPsr17FactoryInterface()
Definition: RequestFactoryTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\constructorRaisesExceptionForInvalidUri
‪constructorRaisesExceptionForInvalidUri($uri)
Definition: RequestFactoryTest.php:88
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest
Definition: RequestFactoryTest.php:29
‪TYPO3\CMS\Core\Http\RequestFactory
Definition: RequestFactory.php:31