Skip to content

Commit 2be625e

Browse files
authored
Merge pull request #325 from williamdes/1.4.x
Backports for 1.4.x
2 parents d3cea65 + 6e46b88 commit 2be625e

File tree

12 files changed

+83
-36
lines changed

12 files changed

+83
-36
lines changed

.github/workflows/tests.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,25 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
php: [7.2, 7.3, 7.4, 8.0]
13+
php: [7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4]
1414
experimental: [false]
15+
dependency-versions: ['locked']
16+
coverage: [false]
1517
include:
18+
- php: 7.2
19+
experimental: false
20+
dependency-versions: lowest
21+
coverage: false
1622
- php: 8.0
1723
analysis: true
18-
- php: 8.1
24+
coverage: false
25+
- php: nightly
1926
experimental: true
27+
coverage: false
2028

2129
steps:
2230
- name: Checkout
23-
uses: actions/checkout@v2
31+
uses: actions/checkout@v4
2432

2533
- name: Set up PHP ${{ matrix.php }}
2634
uses: shivammathur/setup-php@v2
@@ -30,6 +38,8 @@ jobs:
3038

3139
- name: Install dependencies with Composer
3240
uses: ramsey/composer-install@v1
41+
with:
42+
dependency-versions: ${{ matrix.dependency-versions }}
3343

3444
- name: Coding standards
3545
if: matrix.analysis
@@ -40,10 +50,10 @@ jobs:
4050
run: vendor/bin/phpstan analyse src
4151

4252
- name: Tests
43-
run: vendor/bin/phpunit --coverage-clover clover.xml
53+
run: vendor/bin/phpunit --no-coverage
4454

4555
- name: Upload coverage results to Coveralls
46-
if: matrix.analysis
56+
if: matrix.coverage
4757
env:
4858
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4959
run: |

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
"require-dev": {
3939
"ext-json": "*",
4040
"adriansuter/php-autoload-override": "^1.2",
41-
"http-interop/http-factory-tests": "^0.9.0",
42-
"php-http/psr7-integration-tests": "dev-master",
41+
"http-interop/http-factory-tests": "^1.0 || ^2.0",
42+
"php-http/psr7-integration-tests": "^1.3",
4343
"phpstan/phpstan": "^0.12",
44-
"phpunit/phpunit": "^8.5 || ^9.5",
44+
"phpunit/phpunit": "^8.5 || ^9.5 || ^10",
4545
"squizlabs/php_codesniffer": "^3.6",
4646
"weirdan/prophecy-shim": "^1.0 || ^2.0.2"
4747
},

src/Factory/StreamFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function createStream(string $content = ''): StreamInterface
5151
public function createStreamFromFile(
5252
string $filename,
5353
string $mode = 'r',
54-
StreamInterface $cache = null
54+
?StreamInterface $cache = null
5555
): StreamInterface {
5656
set_error_handler(
5757
static function (int $errno, string $errstr) use ($filename, $mode): void {
@@ -82,7 +82,7 @@ static function (int $errno, string $errstr) use ($filename, $mode): void {
8282
/**
8383
* {@inheritdoc}
8484
*/
85-
public function createStreamFromResource($resource, StreamInterface $cache = null): StreamInterface
85+
public function createStreamFromResource($resource, ?StreamInterface $cache = null): StreamInterface
8686
{
8787
if (!is_resource($resource)) {
8888
throw new InvalidArgumentException(

src/Stream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ class Stream implements StreamInterface
9090

9191
/**
9292
* @param resource $stream A PHP resource handle.
93-
* @param StreamInterface $cache A stream to cache $stream (useful for non-seekable streams)
93+
* @param StreamInterface|null $cache A stream to cache $stream (useful for non-seekable streams)
9494
*
9595
* @throws InvalidArgumentException If argument is not a resource.
9696
*/
97-
public function __construct($stream, StreamInterface $cache = null)
97+
public function __construct($stream, ?StreamInterface $cache = null)
9898
{
9999
$this->attach($stream);
100100

src/Uri.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ protected function filterUserInfo(?string $info = null): string
217217
}
218218

219219
$match = preg_replace_callback(
220-
'/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=]+|%(?![A-Fa-f0-9]{2}))/u',
220+
'/(?:[^%a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=]+|%(?![A-Fa-f0-9]{2}))/',
221221
function ($match) {
222222
return rawurlencode($match[0]);
223223
},
@@ -328,7 +328,14 @@ protected function filterPort($port): ?int
328328
*/
329329
public function getPath(): string
330330
{
331-
return $this->path;
331+
$path = $this->path;
332+
333+
// If the path starts with a / then remove all leading slashes except one.
334+
if (strpos($path, '/') === 0) {
335+
$path = '/' . ltrim($path, '/');
336+
}
337+
338+
return $path;
332339
}
333340

334341
/**
@@ -480,11 +487,13 @@ public function __toString(): string
480487
{
481488
$scheme = $this->getScheme();
482489
$authority = $this->getAuthority();
483-
$path = $this->getPath();
490+
$path = $this->path;
484491
$query = $this->getQuery();
485492
$fragment = $this->getFragment();
486493

487-
$path = '/' . ltrim($path, '/');
494+
if (! str_starts_with($path, '/')) {
495+
$path = '/' . $path;
496+
}
488497

489498
return ($scheme !== '' ? $scheme . ':' : '')
490499
. ($authority !== '' ? '//' . $authority : '')

tests/Integration/StreamTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ class StreamTest extends StreamIntegrationTest
2424
{
2525
use BaseTestFactories;
2626

27+
/**
28+
* @var array with functionName => reason
29+
*/
30+
protected $skippedTests = [
31+
'testGetContentsError' => 'PHP 7.3 and 7.4 fail this test: stream_get_contents()'
32+
. ': supplied resource is not a valid stream resource'
33+
];
34+
2735
/**
2836
* @param string|resource|StreamInterface $data
2937
*

tests/Integration/UploadedFileTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ class UploadedFileTest extends UploadedFileIntegrationTest
2121
{
2222
use BaseTestFactories;
2323

24+
/**
25+
* @var array with functionName => reason
26+
*/
27+
protected $skippedTests = [
28+
'testGetSize' => 'PHP 7.2 fail this test: Failed asserting that \'\' matches PCRE pattern "|^[0-9]+$|"'
29+
];
30+
2431
/**
2532
* @return UploadedFileInterface
2633
*/

tests/ResponseTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,8 @@ public function testResonPhraseContainsLineFeed()
144144

145145
public function testWithStatusValidReasonPhraseObject()
146146
{
147-
$mock = $this->getMockBuilder('ResponseTestReasonPhrase')->setMethods(['__toString'])->getMock();
148-
$mock->expects($this->once())
149-
->method('__toString')
150-
->will($this->returnValue('Slim OK'));
151-
152147
$response = new Response();
153-
$response = $response->withStatus(200, $mock);
148+
$response = $response->withStatus(200, new StringableTestObject('Slim OK'));
154149
$this->assertEquals('Slim OK', $response->getReasonPhrase());
155150
}
156151

tests/StringableTestObject.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* Slim Framework (https://slimframework.com)
5+
*
6+
* @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace Slim\Tests\Psr7;
12+
13+
final class StringableTestObject implements \Stringable
14+
{
15+
/** @var string */
16+
private $value;
17+
18+
public function __construct(string $value)
19+
{
20+
$this->value = $value;
21+
}
22+
23+
public function __toString(): string
24+
{
25+
return $this->value;
26+
}
27+
}

tests/UploadedFileTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ public function testCreateUploadedFileWithInvalidUri()
452452
new UploadedFile($stream);
453453
}
454454

455-
public function providerCreateFromGlobals()
455+
public static function providerCreateFromGlobals()
456456
{
457457
return [
458458
// no nest: <input name="avatar" type="file">

0 commit comments

Comments
 (0)