diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 4d668ae6..6feef10d 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -111,7 +111,7 @@ jobs: - name: "Run tests with coverage" if: ${{ matrix.php-version == '8.0' }} timeout-minutes: 3 - run: "vendor/bin/phpunit --coverage-clover=coverage.xml" + run: "vendor/bin/phpunit --no-coverage --coverage-clover=coverage.xml" - name: "Send code coverage report to Codecov.io" if: ${{ matrix.php-version == '8.0' }} diff --git a/.gitignore b/.gitignore index 03ffa1a2..0d825c39 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ vendor/ composer.lock phpunit.xml wait-for-it +coverage/ diff --git a/Makefile b/Makefile index c7c9e060..679f6fab 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,29 @@ +PHP_DOCKER_VERSION := thecodingmachine/php:8.0-v4-cli +PHP_BIN := docker run -it --rm \ + --network=ddeboer_imap_network \ + --env IMAP_SERVER_NAME=ddeboer_imap_server \ + --env IMAP_SERVER_PORT=993 \ + --env IMAP_USERNAME=test@test.test \ + --env IMAP_PASSWORD=p4ssword \ + --env PHP_EXTENSION_IMAP=1 \ + --env PHP_EXTENSION_PCOV=1 \ + -v "$(PWD)":"$(PWD)" -w "$(PWD)" \ + $(PHP_DOCKER_VERSION) + all: csfix static-analysis test @echo "Done." vendor: composer.json - composer update + $(PHP_BIN) composer update touch vendor .PHONY: csfix csfix: vendor - vendor/bin/php-cs-fixer fix --verbose + $(PHP_BIN) vendor/bin/php-cs-fixer fix --verbose .PHONY: static-analysis static-analysis: vendor - $(or ${PHP_BIN},php) vendor/bin/phpstan analyse + $(PHP_BIN) vendor/bin/phpstan analyse wait-for-it: wget -O wait-for-it "https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh" @@ -19,7 +31,20 @@ wait-for-it: .PHONY: start-imap-server start-imap-server: wait-for-it - docker run --name=ddeboer_imap_server --detach --rm --publish 10993:993 --env MAILNAME=test.test --env MAIL_ADDRESS=test@test.test --env MAIL_PASS=p4ssword antespi/docker-imap-devel:latest + docker pull $(PHP_DOCKER_VERSION) + docker pull antespi/docker-imap-devel:latest + docker network create ddeboer_imap_network + docker run \ + --name=ddeboer_imap_server \ + --network=ddeboer_imap_network \ + --detach \ + --rm \ + --expose 993 \ + --publish 10993:993 \ + --env MAILNAME=test.test \ + --env MAIL_ADDRESS=test@test.test \ + --env MAIL_PASS=p4ssword \ + antespi/docker-imap-devel:latest ./wait-for-it localhost:10993 .PHONY: stop-imap-server @@ -28,4 +53,7 @@ stop-imap-server: .PHONY: test test: vendor - IMAP_SERVER_NAME=localhost IMAP_SERVER_PORT=10993 IMAP_USERNAME=test@test.test IMAP_PASSWORD=p4ssword $(or ${PHP_BIN},php) -d zend.assertions=1 vendor/bin/phpunit ${arg} + $(PHP_BIN) php \ + -d zend.assertions=1 \ + vendor/bin/phpunit \ + $(PHPUNIT_FLAGS) diff --git a/README.md b/README.md index c57ab01f..554a9c17 100644 --- a/README.md +++ b/README.md @@ -284,24 +284,12 @@ Mockability is granted by interfaces present for each API. Dig into [MockabilityTest](tests/MockabilityTest.php) for an example of a mocked workflow. -## Running the Tests +## Contributing: run the build locally -This library is functionally tested on [Travis CI](https://travis-ci.org/ddeboer/imap) -against a local Dovecot server. +Docker is needed to run the build on your computer. -If you have your own IMAP (test) account, you can run the tests locally by -providing your IMAP credentials: +First command you need to run is `make start-imap-server`, which starts an IMAP server locally. -```bash -$ composer install -$ IMAP_SERVER_NAME="my.imap.server.com" IMAP_SERVER_PORT="60993" IMAP_USERNAME="johndoe" IMAP_PASSWORD="p4ssword" vendor/bin/phpunit -``` - -You can also copy `phpunit.xml.dist` file to a custom `phpunit.xml` and put -these environment variables in it. +Then the local build can be triggered with a bare `make`. -**WARNING** Tests create new mailboxes without removing them. - -``` -$ docker-compose run tests -``` +When you finish the development, stop the local IMAP server with `make stop-imap-server`. diff --git a/composer.json b/composer.json index 0bcf72af..2d7c5f81 100644 --- a/composer.json +++ b/composer.json @@ -28,13 +28,12 @@ "ext-mbstring": "*" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^v3.4.0", - "laminas/laminas-mail": "^2.15.1", - "malukenho/mcbumpface": "^1.1.5", - "phpstan/phpstan": "^1.3.3", - "phpstan/phpstan-phpunit": "^1.0.0", - "phpstan/phpstan-strict-rules": "^1.1.0", - "phpunit/phpunit": "^9.5.11" + "friendsofphp/php-cs-fixer": "^v3.9.5", + "laminas/laminas-mail": "^2.16.0", + "phpstan/phpstan": "^1.8.2", + "phpstan/phpstan-phpunit": "^1.1.1", + "phpstan/phpstan-strict-rules": "^1.3.0", + "phpunit/phpunit": "^9.5.21" }, "autoload": { "psr-4": { @@ -45,10 +44,5 @@ "psr-4": { "Ddeboer\\Imap\\Tests\\": "tests/" } - }, - "config": { - "allow-plugins": { - "malukenho/mcbumpface": true - } } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 32204978..507afd0a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,10 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Call to function is_resource\\(\\) with resource will always evaluate to true\\.$#" - count: 1 - path: src/ImapResource.php - - message: "#^Class IMAP\\\\Connection not found\\.$#" count: 1 @@ -30,11 +25,6 @@ parameters: 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 \\#2 \\$array of function implode expects array\\, array\\ given\\.$#" count: 1 @@ -51,8 +41,13 @@ parameters: 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 + message: "#^Cannot call method getDecodedContent\\(\\) on mixed\\.$#" + count: 2 + path: src/Message/AbstractMessage.php + + - + message: "#^Cannot call method getSubtype\\(\\) on mixed\\.$#" + count: 2 path: src/Message/AbstractMessage.php - @@ -70,31 +65,16 @@ parameters: 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 @@ -177,12 +157,7 @@ parameters: - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsInt\\(\\) with int will always evaluate to true\\.$#" - count: 1 - path: tests/ConnectionTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsInt\\(\\) with int\\<0, max\\> will always evaluate to true\\.$#" - count: 1 + count: 2 path: tests/ConnectionTest.php - diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 24ee738a..b250544d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,6 @@ ./src + diff --git a/src/Connection.php b/src/Connection.php index 9f5ef90f..d562ab6a 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -61,7 +61,7 @@ public function getQuota(string $root = 'INBOX'): array $errorNumber = 0; \set_error_handler(static function ($nr, $message) use (&$errorMessage, &$errorNumber): bool { $errorMessage = $message; - $errorNumber = $nr; + $errorNumber = $nr; return true; }); diff --git a/src/Message.php b/src/Message.php index 1a9d16e7..bc2c10cb 100644 --- a/src/Message.php +++ b/src/Message.php @@ -49,7 +49,7 @@ protected function lazyLoadStructure(): void $errorNumber = 0; \set_error_handler(static function ($nr, $message) use (&$errorMessage, &$errorNumber): bool { $errorMessage = $message; - $errorNumber = $nr; + $errorNumber = $nr; return true; }); diff --git a/src/Message/AbstractPart.php b/src/Message/AbstractPart.php index 0647133c..b87c4bfd 100644 --- a/src/Message/AbstractPart.php +++ b/src/Message/AbstractPart.php @@ -400,7 +400,7 @@ private static function isAttachment(\stdClass $part): bool } if ( - 'inline' === \strtolower($part->disposition) + 'inline' === \strtolower($part->disposition) && self::SUBTYPE_PLAIN !== \strtoupper($part->subtype) && self::SUBTYPE_HTML !== \strtoupper($part->subtype) ) { diff --git a/src/Message/Transcoder.php b/src/Message/Transcoder.php index bd439e06..91b297eb 100644 --- a/src/Message/Transcoder.php +++ b/src/Message/Transcoder.php @@ -304,7 +304,7 @@ public static function decode(string $text, string $fromCharset): string $errorNumber = 0; \set_error_handler(static function ($nr, $message) use (&$errorMessage, &$errorNumber): bool { $errorMessage = $message; - $errorNumber = $nr; + $errorNumber = $nr; return true; }); diff --git a/src/Server.php b/src/Server.php index 41a953d9..8a5a1b8f 100644 --- a/src/Server.php +++ b/src/Server.php @@ -67,7 +67,7 @@ public function authenticate(string $username, string $password): ConnectionInte $errorNumber = 0; \set_error_handler(static function ($nr, $message) use (&$errorMessage, &$errorNumber): bool { $errorMessage = $message; - $errorNumber = $nr; + $errorNumber = $nr; return true; }); diff --git a/tests/MailboxTest.php b/tests/MailboxTest.php index f8284aa4..63bf03a3 100644 --- a/tests/MailboxTest.php +++ b/tests/MailboxTest.php @@ -322,7 +322,7 @@ public function testSort(): void $this->createTestMessage($anotherMailbox, 'C'); $concatSubjects = static function (MessageIteratorInterface $it): string { - $subject = ''; + $subject = ''; foreach ($it as $message) { $subject .= $message->getSubject(); }