Skip to content

Commit

Permalink
Add PHP 8.1 support, drop PHP 7.4 (#527)
Browse files Browse the repository at this point in the history
* Prepare for PHP 8.1

* PHP 8.1 compatibility

* Fix 8.0-8.1 composer-require-checker mismatch on IMAP\Connection type

* Run CC on lowest version
  • Loading branch information
Slamdunk authored Nov 29, 2021
1 parent 5f1d8ed commit 2d6c3f7
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 24 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -62,8 +62,8 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"

env:
IMAP_SERVER_NAME: dovecot.travis.dev
Expand Down Expand Up @@ -104,17 +104,17 @@ jobs:
run: "composer update --no-interaction --no-progress"

- name: "Run tests without coverage"
if: ${{ matrix.php-version != '7.4' }}
if: ${{ matrix.php-version != '8.0' }}
timeout-minutes: 3
run: "vendor/bin/phpunit --no-coverage --no-logging"

- name: "Run tests with coverage"
if: ${{ matrix.php-version == '7.4' }}
if: ${{ matrix.php-version == '8.0' }}
timeout-minutes: 3
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"

- name: "Send code coverage report to Codecov.io"
if: ${{ matrix.php-version == '7.4' }}
if: ${{ matrix.php-version == '8.0' }}
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -129,7 +129,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"

steps:
- name: "Checkout"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ all: csfix static-analysis test
@echo "Done."

vendor: composer.json
composer update --ignore-platform-reqs
composer update
touch vendor

.PHONY: csfix
Expand Down
3 changes: 2 additions & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"symbol-whitelist" : [
"null", "true", "false",
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object"
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"IMAP\\Connection"
]
}
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
}
],
"require": {
"php": "^7.4 || ^8.0.1",
"php": "^8.0.1",
"ext-iconv": "*",
"ext-imap": "*",
"ext-mbstring": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^v3.1.0",
"laminas/laminas-mail": "^2.15.0",
"friendsofphp/php-cs-fixer": "^v3.3.2",
"laminas/laminas-mail": "^2.15.1",
"malukenho/mcbumpface": "^1.1.5",
"phpstan/phpstan": "^0.12.99",
"phpstan/phpstan-phpunit": "^0.12.22",
"phpstan/phpstan-strict-rules": "^0.12.11",
"phpunit/phpunit": "^9.5.9"
"phpstan/phpstan": "^1.2.0",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpstan/phpstan-strict-rules": "^1.1.0",
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"psr-4": {
Expand Down
130 changes: 125 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,96 @@ parameters:
count: 1
path: src/ImapResource.php

-
message: "#^Class IMAP\\\\Connection not found\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^If condition is always false\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^Instanceof between resource and IMAP\\\\Connection will always evaluate to false\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^Parameter \\$resource of method Ddeboer\\\\Imap\\\\ImapResource\\:\\:__construct\\(\\) has invalid type IMAP\\\\Connection\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^Property Ddeboer\\\\Imap\\\\ImapResource\\:\\:\\$resource \\(resource\\) does not accept IMAP\\\\Connection\\|resource\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^Strict comparison using \\=\\=\\= between false and true will always evaluate to false\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^Parameter \\#3 \\$reverse of function imap_sort expects int, bool\\|int given\\.$#"
message: "#^Parameter \\#2 \\$array of function implode expects array\\<string\\>, array\\<int, Ddeboer\\\\Imap\\\\MessageInterface\\|int\\|string\\> given\\.$#"
count: 1
path: src/Mailbox.php

-
message: "#^Parameter \\#2 \\$msg_no of function imap_delete expects int, string given\\.$#"
message: "#^Parameter \\#3 \\$reverse of function imap_sort expects bool, bool\\|int given\\.$#"
count: 1
path: src/Message.php
path: src/Mailbox.php

-
message: "#^Parameter \\#2 \\$msg_no of function imap_undelete expects int, string given\\.$#"
message: "#^Call to function is_numeric\\(\\) with int will always evaluate to true\\.$#"
count: 1
path: src/Message.php

-
message: "#^Method Ddeboer\\\\Imap\\\\Message\\\\AbstractMessage\\:\\:getAttachments\\(\\) return type has no value type specified in iterable type Ddeboer\\\\Imap\\\\Message\\\\AttachmentInterface\\.$#"
count: 1
path: src/Message/AbstractMessage.php

-
message: "#^Call to function base64_decode\\(\\) requires parameter \\#2 to be true\\.$#"
count: 1
path: src/Message/AbstractPart.php

-
message: "#^Method Ddeboer\\\\Imap\\\\Message\\\\AbstractPart\\:\\:getChildren\\(\\) return type with generic interface RecursiveIterator does not specify its types\\: TKey, TValue$#"
count: 1
path: src/Message/AbstractPart.php

-
message: "#^Method Ddeboer\\\\Imap\\\\Message\\\\AbstractPart\\:\\:getChildren\\(\\) should return RecursiveIterator\\|null but returns mixed\\.$#"
count: 1
path: src/Message/AbstractPart.php

-
message: "#^Method Ddeboer\\\\Imap\\\\Message\\\\AbstractPart\\:\\:getParts\\(\\) return type has no value type specified in iterable type Ddeboer\\\\Imap\\\\Message\\\\PartInterface\\.$#"
count: 1
path: src/Message/AbstractPart.php

-
message: "#^Strict comparison using \\=\\=\\= between false and string will always evaluate to false\\.$#"
count: 1
path: src/Message/AbstractPart.php

-
message: "#^Method Ddeboer\\\\Imap\\\\Message\\\\BasicMessageInterface\\:\\:getAttachments\\(\\) return type has no value type specified in iterable type Ddeboer\\\\Imap\\\\Message\\\\AttachmentInterface\\.$#"
count: 1
path: src/Message/BasicMessageInterface.php

-
message: "#^Interface Ddeboer\\\\Imap\\\\Message\\\\PartInterface extends generic interface RecursiveIterator but does not specify its types\\: TKey, TValue$#"
count: 1
path: src/Message/PartInterface.php

-
message: "#^Method Ddeboer\\\\Imap\\\\Message\\\\PartInterface\\:\\:getParts\\(\\) return type has no value type specified in iterable type Ddeboer\\\\Imap\\\\Message\\\\PartInterface\\.$#"
count: 1
path: src/Message/PartInterface.php

-
message: "#^Call to function is_int\\(\\) with Ddeboer\\\\Imap\\\\MessageInterface will always evaluate to false\\.$#"
count: 1
Expand All @@ -45,21 +105,76 @@ parameters:
count: 1
path: src/MessageIterator.php

-
message: "#^Class ArrayIterator specifies template type TKey of interface Iterator as int but it's already specified as mixed\\.$#"
count: 1
path: src/MessageIterator.php

-
message: "#^Class ArrayIterator specifies template type TKey of interface Traversable as int but it's already specified as mixed\\.$#"
count: 1
path: src/MessageIterator.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
path: src/MessageIterator.php

-
message: "#^Interface Iterator specifies template type TKey of interface Traversable as int but it's already specified as mixed\\.$#"
count: 2
path: src/MessageIterator.php

-
message: "#^Interface SeekableIterator specifies template type TKey of interface Iterator as int but it's already specified as mixed\\.$#"
count: 1
path: src/MessageIterator.php

-
message: "#^Interface SeekableIterator specifies template type TKey of interface Traversable as int but it's already specified as mixed\\.$#"
count: 1
path: src/MessageIterator.php

-
message: "#^Parameter \\#1 \\$array of method ArrayIterator\\<int,Ddeboer\\\\Imap\\\\MessageInterface\\>\\:\\:__construct\\(\\) expects array\\<int, Ddeboer\\\\Imap\\\\MessageInterface\\>, array\\<int\\> given\\.$#"
count: 1
path: src/MessageIterator.php

-
message: "#^Property Ddeboer\\\\Imap\\\\MessageIterator\\:\\:\\$resource is never read, only written\\.$#"
count: 1
path: src/MessageIterator.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: src/MessageIterator.php

-
message: "#^Class ArrayIterator specifies template type TKey of interface Iterator as int but it's already specified as mixed\\.$#"
count: 1
path: src/Test/RawMessageIterator.php

-
message: "#^Class ArrayIterator specifies template type TKey of interface Traversable as int but it's already specified as mixed\\.$#"
count: 1
path: src/Test/RawMessageIterator.php

-
message: "#^Interface Iterator specifies template type TKey of interface Traversable as int but it's already specified as mixed\\.$#"
count: 2
path: src/Test/RawMessageIterator.php

-
message: "#^Interface SeekableIterator specifies template type TKey of interface Iterator as int but it's already specified as mixed\\.$#"
count: 1
path: src/Test/RawMessageIterator.php

-
message: "#^Interface SeekableIterator specifies template type TKey of interface Traversable as int but it's already specified as mixed\\.$#"
count: 1
path: src/Test/RawMessageIterator.php

-
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsInt\\(\\) with int will always evaluate to true\\.$#"
count: 1
Expand All @@ -71,7 +186,7 @@ parameters:
path: tests/ConnectionTest.php

-
message: "#^Parameter \\#1 \\$resource of class Ddeboer\\\\Imap\\\\ImapResource constructor expects resource, string given\\.$#"
message: "#^Parameter \\#1 \\$resource of class Ddeboer\\\\Imap\\\\ImapResource constructor expects IMAP\\\\Connection\\|resource, string given\\.$#"
count: 1
path: tests/ConnectionTest.php

Expand All @@ -95,3 +210,8 @@ parameters:
count: 2
path: tests/MessageTest.php

-
message: "#^Cannot access property \\$parts on mixed\\.$#"
count: 2
path: tests/MessageTest.php

2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
includes:
- phar://phpstan.phar/conf/config.levelmax.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- phpstan-baseline.neon

parameters:
level: max
tmpDir: tmp/
paths:
- src/
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
convertDeprecationsToExceptions="true"
colors="true"
verbose="true"
>
Expand Down
8 changes: 6 additions & 2 deletions src/ImapResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Ddeboer\Imap\Exception\InvalidResourceException;
use Ddeboer\Imap\Exception\ReopenMailboxException;
use IMAP\Connection;

/**
* An imap resource stream.
Expand All @@ -22,7 +23,7 @@ final class ImapResource implements ImapResourceInterface
/**
* Constructor.
*
* @param resource $resource
* @param Connection|resource $resource
*/
public function __construct($resource, MailboxInterface $mailbox = null)
{
Expand All @@ -32,7 +33,10 @@ public function __construct($resource, MailboxInterface $mailbox = null)

public function getStream()
{
if (false === \is_resource($this->resource) || 'imap' !== \get_resource_type($this->resource)) {
if (
!$this->resource instanceof Connection
&& (false === \is_resource($this->resource) || 'imap' !== \get_resource_type($this->resource))
) {
throw new InvalidResourceException('Supplied resource is not a valid imap resource');
}

Expand Down
15 changes: 15 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function testCannotInstantiateArbitraryConnections(): void
$resource->getStream();
}

/**
* @requires PHP < 8.1
*/
public function testCloseConnection(): void
{
$connection = $this->createConnection();
Expand All @@ -57,6 +60,18 @@ public function testPing(): void
static::assertTrue($connection->ping());

$connection->close();
}

/**
* @requires PHP < 8.1
*/
public function testPingUnavailableAfterClose(): void
{
$connection = $this->createConnection();

static::assertTrue($connection->ping());

$connection->close();

$this->expectException(InvalidResourceException::class);

Expand Down
3 changes: 3 additions & 0 deletions tests/MailboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public function testCount(): void
static::assertSame(3, $this->mailbox->count());
}

/**
* @requires PHP < 8.1
*/
public function testDelete(): void
{
$connection = $this->getConnection();
Expand Down

0 comments on commit 2d6c3f7

Please sign in to comment.