Skip to content

Commit

Permalink
Merge branch 'php-8.1'
Browse files Browse the repository at this point in the history
Closes #33
  • Loading branch information
akrabat committed Nov 11, 2021
2 parents 90c38ef + b935f5d commit 50ba091
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ jobs:

strategy:
matrix:
dependencies:
- "lowest"
- "highest"
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
operating-system:
- "ubuntu-latest"

Expand All @@ -43,15 +41,10 @@ jobs:
path: |
~/.composer/cache
vendor
key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"

- name: "Install lowest dependencies"
if: ${{ matrix.dependencies == 'lowest' }}
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest"
key: "php-${{ matrix.php-version }}"
restore-keys: "php-${{ matrix.php-version }}"

- name: "Install highest dependencies"
if: ${{ matrix.dependencies == 'highest' }}
run: "composer update --no-interaction --no-progress --no-suggest"

- name: "Tests"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
vendor
composer.lock
.phpunit.result.cache
12 changes: 6 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.7/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
Expand All @@ -20,9 +20,9 @@
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
</include>
</coverage>
</phpunit>
6 changes: 5 additions & 1 deletion src/IpAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
*/
protected function determineClientIpAddress($request)
{
$ipAddress = null;
$ipAddress = '';

$serverParams = $request->getServerParams();
if (isset($serverParams['REMOTE_ADDR'])) {
Expand Down Expand Up @@ -234,6 +234,10 @@ protected function determineClientIpAddress($request)
}
}

if (empty($ipAddress)) {
$ipAddress = null;
}

return $ipAddress;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/IpAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ public function testIpIsNullIfMissing()
$this->assertNull($ipAddress);
}

public function testIpIsNullIfMissingAndProxiesAreConfigured()
{
error_reporting(-1);
$middleware = new IPAddress(true, ['*'], 'IP');
$env = [];
$ipAddress = $this->simpleRequest($middleware, $env, 'IP');

$this->assertSame(null, $ipAddress);
}


public function testXForwardedForIp()
{
$middleware = new IPAddress(true, []);
Expand Down

0 comments on commit 50ba091

Please sign in to comment.