‪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 PHPUnit\Framework\Attributes\Test;
21 use Psr\Http\Message\RequestFactoryInterface;
22 use Psr\Http\Message\RequestInterface;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 final class ‪RequestFactoryTest extends UnitTestCase
31 {
32  #[Test]
33  public function ‪implementsPsr17FactoryInterface(): void
34  {
35  $factory = new ‪RequestFactory(new ‪GuzzleClientFactory());
36  self::assertInstanceOf(RequestFactoryInterface::class, $factory);
37  }
38 
39  #[Test]
40  public function ‪requestHasMethodSet(): void
41  {
42  $factory = new ‪RequestFactory(new ‪GuzzleClientFactory());
43  $request = $factory->createRequest('POST', '/');
44  self::assertSame('POST', $request->getMethod());
45  }
46 
47  #[Test]
49  {
50  $factory = new ‪RequestFactory(new ‪GuzzleClientFactory());
51  $request = $factory->createRequest('GET', '/');
52  $body = $request->getBody();
53 
54  self::assertInstanceOf(RequestInterface::class, $request);
55 
56  self::assertSame('', $body->__toString());
57  self::assertSame(0, $body->getSize());
58  self::assertTrue($body->isSeekable());
59 
60  $body->write('Foo');
61  self::assertSame(3, $body->getSize());
62  self::assertSame('Foo', $body->__toString());
63  }
64 
65  #[Test]
66  public function ‪raisesExceptionForInvalidMethod(): void
67  {
68  $this->expectException(\InvalidArgumentException::class);
69  $this->expectExceptionCode(1436717275);
70  $factory = new ‪RequestFactory(new ‪GuzzleClientFactory());
71  $factory->createRequest('BOGUS-BODY', '/');
72  }
73 }
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\requestHasMethodSet
‪requestHasMethodSet()
Definition: RequestFactoryTest.php:40
‪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:66
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\implementsPsr17FactoryInterface
‪implementsPsr17FactoryInterface()
Definition: RequestFactoryTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest
Definition: RequestFactoryTest.php:31
‪TYPO3\CMS\Core\Http\RequestFactory
Definition: RequestFactory.php:30
‪TYPO3\CMS\Core\Tests\Unit\Http\RequestFactoryTest\requestFactoryHasAWritableEmptyBody
‪requestFactoryHasAWritableEmptyBody()
Definition: RequestFactoryTest.php:48