nebkam / fluent-test

A few helpers to ease functional API testing in Symfony
10 stars 2 forks source link

setHttpHeader issue #13

Open goranJankovic opened 3 weeks ago

goranJankovic commented 3 weeks ago

The getParameter method in Container.php can return a variety of types (array|bool|string|int|float|\UnitEnum|null). However, RequestBuilder->setHttpHeader() only accepts string values, which causes a PHPStan error in our tests when

we retrieve:

self::getContainer()->getParameter('xxx_api_key')

and pass it to:

->setHttpHeader([ApiParams::API_KEY_HEADER,self::getContainer()->getParameter('xxx_api_key')])

because:

/**

  • Gets a parameter.
  • @throws ParameterNotFoundException if the parameter is not defined */ public function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null { return $this->parameterBag->get($name); }

To handle this, we've implemented a solution (on our side):

/**

  • @return array{string, string} */ protected static function getAgentHttpHeaders(): array { $param = self::getContainer()->getParameter(''xxx_api_key);

    return [ ApiParams::API_KEY_HEADER, is_string($param) ? $param : throw new UnexpectedValueException('Agent API key is not a string') ]; }

andrew-demb commented 2 weeks ago

What are you expect from the library for this use case?

goranJankovic commented 2 weeks ago

What are you expect from the library for this use case?

Nothing, the owner of the library told me to open this issue.