‪TYPO3CMS  ‪main
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;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 final class ‪RequestFactoryTest extends UnitTestCase
30 {
34  public function ‪implementsPsr17FactoryInterface(): void
35  {
36  $factory = new ‪RequestFactory(new ‪GuzzleClientFactory());
37  self::assertInstanceOf(RequestFactoryInterface::class, $factory);
38  }
39 
43  public function ‪requestHasMethodSet(): void
44  {
45  $factory = new ‪RequestFactory(new ‪GuzzleClientFactory());
46  $request = $factory->createRequest('POST', '/');
47  self::assertSame('POST', $request->getMethod());
48  }
49 
54  {
55  $factory = new ‪RequestFactory(new ‪GuzzleClientFactory());
56  $request = $factory->createRequest('GET', '/');
57  $body = $request->getBody();
58 
59  self::assertInstanceOf(RequestInterface::class, $request);
60 
61  self::assertSame('', $body->__toString());
62  self::assertSame(0, $body->getSize());
63  self::assertTrue($body->isSeekable());
64 
65  $body->write('Foo');
66  self::assertSame(3, $body->getSize());
67  self::assertSame('Foo', $body->__toString());
68  }
69 
73  public function ‪raisesExceptionForInvalidMethod(): void
74  {
75  $this->expectException(\InvalidArgumentException::class);
76  $this->expectExceptionCode(1436717275);
77  $factory = new ‪RequestFactory(new ‪GuzzleClientFactory());
78  $factory->createRequest('BOGUS-BODY', '/');
79  }
80 }
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\requestHasMethodSet
‪requestHasMethodSet()
Definition: RequestFactoryTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Http
Definition: ApplicationTypeTest.php:18
‪TYPO3\CMS\Core\Http\Client\GuzzleClientFactory
Definition: GuzzleClientFactory.php:28
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\raisesExceptionForInvalidMethod
‪raisesExceptionForInvalidMethod()
Definition: RequestFactoryTest.php:73
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\implementsPsr17FactoryInterface
‪implementsPsr17FactoryInterface()
Definition: RequestFactoryTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest
Definition: RequestFactoryTest.php:30
‪TYPO3\CMS\Core\Http\RequestFactory
Definition: RequestFactory.php:30
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\requestFactoryHasAWritableEmptyBody
‪requestFactoryHasAWritableEmptyBody()
Definition: RequestFactoryTest.php:53