Browse Source

readd http-factory-tests

Kevin Pfeifer 2 years ago
parent
commit
a50139a97b
3 changed files with 9 additions and 3 deletions
  1. 1 0
      composer.json
  2. 3 3
      phpunit.xml.dist
  3. 5 0
      src/Http/StreamFactory.php

+ 1 - 0
composer.json

@@ -58,6 +58,7 @@
     },
     "require-dev": {
         "cakephp/cakephp-codesniffer": "^5.0",
+        "http-interop/http-factory-tests": "^2.0",
         "mikey179/vfsstream": "^1.6.10",
         "mockery/mockery": "^1.6",
         "paragonie/csp-builder": "^2.3",

+ 3 - 3
phpunit.xml.dist

@@ -18,9 +18,9 @@
             <directory>tests/TestCase/Database/</directory>
             <directory>tests/TestCase/ORM/</directory>
         </testsuite>
-<!--        <testsuite name="http-interop-http-factory">-->
-<!--            <directory>./vendor/http-interop/http-factory-tests/test</directory>-->
-<!--        </testsuite>-->
+        <testsuite name="http-interop-http-factory">
+            <directory>./vendor/http-interop/http-factory-tests/test</directory>
+        </testsuite>
         <testsuite name="globalfunctions">
             <file>tests/TestCase/Collection/FunctionsGlobalTest.php</file>
             <file>tests/TestCase/Core/FunctionsGlobalTest.php</file>

+ 5 - 0
src/Http/StreamFactory.php

@@ -19,6 +19,7 @@ namespace Cake\Http;
 use Laminas\Diactoros\Stream;
 use Psr\Http\Message\StreamFactoryInterface;
 use Psr\Http\Message\StreamInterface;
+use RuntimeException;
 
 /**
  * Factory class for creating stream instances.
@@ -57,6 +58,10 @@ class StreamFactory implements StreamFactoryInterface
      */
     public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
     {
+        if (!is_readable($filename)) {
+            throw new RuntimeException(sprintf('Cannot read file `%s`', $filename));
+        }
+
         return new Stream($filename, $mode);
     }