{
public static function process()
{
- $content_parts = explode(';', $_SERVER['CONTENT_TYPE'] ?? 'application/x-www-form-urlencoded');
+ $content_parts = explode(';', static::getContentType());
$boundary = '';
$encoding = '';
/**
* Returns the current PHP input stream
* Mainly used for test doubling
+ *
* @return false|resource
*/
protected static function getPhpInputStream()
/**
* Returns the content of the current PHP input
* Mainly used for test doubling
+ *
* @return false|string
*/
protected static function getPhpInputContent()
{
return file_get_contents('php://input');
}
+
+ /**
+ * Returns the content type string of the current call
+ * Mainly used for test doubling
+ *
+ * @return false|string
+ */
+ protected static function getContentType()
+ {
+ return $_SERVER['CONTENT_TYPE'] ?? 'application/x-www-form-urlencoded';
+ }
}
protected static $injectedStream = false;
/** @var false|string */
protected static $injectedContent = false;
+ /** @var false|string */
+ protected static $injectedContentType = false;
/**
* injects the PHP input stream for a test
+ *
* @param false|resource $stream
*/
public static function setPhpInputStream($stream)
/**
* injects the PHP input content for a test
+ *
* @param false|string $content
*/
public static function setPhpInputContent($content)
self::$injectedContent = $content;
}
+ /**
+ * injects the PHP input content type for a test
+ *
+ * @param false|string $contentType
+ */
+ public static function setPhpInputContentType($contentType)
+ {
+ self::$injectedContentType = $contentType;
+ }
+
/** {@inheritDoc} */
protected static function getPhpInputStream()
{
{
return static::$injectedContent;
}
+
+ /** {@inheritDoc} */
+ protected static function getContentType()
+ {
+ return static::$injectedContentType;
+ }
}
/**
* Testing HTTPInputData
+ *
* @see HTTPInputData
*/
class HTTPInputDataTest extends MockedTest
* Returns the data stream for the unit test
* Each array element of the first hierarchy represents one test run
* Each array element of the second hierarchy represents the parameters, passed to the test function
+ *
* @return array[]
*/
public function dataStream()
/**
* Tests the HTTPInputData::process() method
- * @see HTTPInputData::process()
- * @param string $contenttype The content typer of the transmitted data
+ *
+ * @param string $contentType The content typer of the transmitted data
* @param string $input The input, we got from the data stream
* @param array $expected The expected output
+ *
* @dataProvider dataStream
+ * @see HTTPInputData::process()
*/
- public function testHttpInput(string $contenttype, string $input, array $expected)
+ public function testHttpInput(string $contentType, string $input, array $expected)
{
- $_SERVER['CONTENT_TYPE'] = $contenttype;
-
+ HTTPInputDataDouble::setPhpInputContentType($contentType);
HTTPInputDataDouble::setPhpInputContent($input);
$stream = fopen('php://memory', 'r+');
fwrite($stream, $input);