PsrHttpFactory example

protected $httpMessageFactory;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->container = new ContainerBuilder();
    $class_resolver = new ClassResolver();
    $class_resolver->setContainer($this->container);
    $this->httpMessageFactory = new PsrHttpFactory(new HttpFactory()new HttpFactory()new HttpFactory()new HttpFactory());
    $this->controllerResolver = new ControllerResolver($this->httpMessageFactory, $class_resolver);
  }

  /** * Tests createController(). * * @dataProvider providerTestCreateController */
  public function testCreateController($controller$class$output) {
    $this->container->set('some_service', new MockController());
    $result = $this->controllerResolver->getControllerFromDefinition($controller);
    
'HTTP_HOST' => 'http_host.fr',
            'CONTENT_TYPE' => 'application/json',
        ];
        $request = new Request([][][][][]$headers, '{"city":"Paris"');
        $psrRequest = self::buildHttpMessageFactory()->createRequest($request);

        $this->assertNull($psrRequest->getParsedBody());
    }

    public static function provideFactories(): \Generator
    {
        yield 'Discovery' => [new PsrHttpFactory()];
        yield 'incomplete dependencies' => [new PsrHttpFactory(responseFactory: new Psr17Factory())];
        yield 'Nyholm' => [self::buildHttpMessageFactory()];
    }

    private static function buildHttpMessageFactory(): PsrHttpFactory
    {
        $factory = new Psr17Factory();

        return new PsrHttpFactory($factory$factory$factory$factory);
    }
}
$psr7Requests = [
            (new Psr7Request('POST', 'http://tnyholm.se/foo/?bar=biz'))
                ->withQueryParams(['bar' => 'biz']),
            new Psr7Request('GET', 'https://hey-octave.com/'),
            new Psr7Request('GET', 'https://hey-octave.com:443/'),
            new Psr7Request('GET', 'https://hey-octave.com:4242/'),
            new Psr7Request('GET', 'http://hey-octave.com:80/'),
        ];

        $nyholmFactory = new Psr17Factory();
        $psr17Factory = new PsrHttpFactory($nyholmFactory$nyholmFactory$nyholmFactory$nyholmFactory);
        $symfonyFactory = new HttpFoundationFactory();

        return array_merge([
            [$sfRequest$psr17Factory$symfonyFactory],
        ]array_map(function D$psr7Request) use ($symfonyFactory$psr17Factory) {
            return [$psr7Request$symfonyFactory$psr17Factory];
        }$psr7Requests));
    }

    /** * @dataProvider responseProvider */
Home | Imprint | This part of the site doesn't use cookies.