Skip to content

Commit

Permalink
Revert "README.md: update instruction to build repo locally (ddeboer#541
Browse files Browse the repository at this point in the history
)"

This reverts commit c09e9c6.
  • Loading branch information
vladimir.kaprielov committed Oct 27, 2022
1 parent 16ef27a commit 8fc09ee
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
- name: "Run tests with coverage"
if: ${{ matrix.php-version == '8.0' }}
timeout-minutes: 3
run: "vendor/bin/phpunit --no-coverage --coverage-clover=coverage.xml"
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"

- name: "Send code coverage report to Codecov.io"
if: ${{ matrix.php-version == '8.0' }}
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ vendor/
composer.lock
phpunit.xml
wait-for-it
coverage/
38 changes: 5 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,25 @@
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 [email protected] \
--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
$(PHP_BIN) composer update
composer update
touch vendor

.PHONY: csfix
csfix: vendor
$(PHP_BIN) vendor/bin/php-cs-fixer fix --verbose
vendor/bin/php-cs-fixer fix --verbose

.PHONY: static-analysis
static-analysis: vendor
$(PHP_BIN) vendor/bin/phpstan analyse
$(or ${PHP_BIN},php) 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"
chmod +x wait-for-it

.PHONY: start-imap-server
start-imap-server: wait-for-it
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 [email protected] \
--env MAIL_PASS=p4ssword \
antespi/docker-imap-devel:latest
docker run --name=ddeboer_imap_server --detach --rm --publish 10993:993 --env MAILNAME=test.test --env [email protected] --env MAIL_PASS=p4ssword antespi/docker-imap-devel:latest
./wait-for-it localhost:10993

.PHONY: stop-imap-server
Expand All @@ -53,7 +28,4 @@ stop-imap-server:

.PHONY: test
test: vendor
$(PHP_BIN) php \
-d zend.assertions=1 \
vendor/bin/phpunit \
$(PHPUNIT_FLAGS)
IMAP_SERVER_NAME=localhost IMAP_SERVER_PORT=10993 [email protected] IMAP_PASSWORD=p4ssword $(or ${PHP_BIN},php) -d zend.assertions=1 vendor/bin/phpunit ${arg}
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,24 @@ Mockability is granted by interfaces present for each API.
Dig into [MockabilityTest](tests/MockabilityTest.php) for an example of a
mocked workflow.

## Contributing: run the build locally
## Running the Tests

Docker is needed to run the build on your computer.
This library is functionally tested on [Travis CI](https://travis-ci.org/ddeboer/imap)
against a local Dovecot server.

First command you need to run is `make start-imap-server`, which starts an IMAP server locally.
If you have your own IMAP (test) account, you can run the tests locally by
providing your IMAP credentials:

Then the local build can be triggered with a bare `make`.
```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.

When you finish the development, stop the local IMAP server with `make stop-imap-server`.
**WARNING** Tests create new mailboxes without removing them.

```
$ docker-compose run tests
```
18 changes: 12 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
"ext-mbstring": "*"
},
"require-dev": {
"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"
"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"
},
"autoload": {
"psr-4": {
Expand All @@ -44,5 +45,10 @@
"psr-4": {
"Ddeboer\\Imap\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"malukenho/mcbumpface": true
}
}
}
41 changes: 33 additions & 8 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
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
Expand All @@ -25,6 +30,11 @@ 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\\<string\\>, array\\<int, Ddeboer\\\\Imap\\\\MessageInterface\\|int\\|string\\> given\\.$#"
count: 1
Expand All @@ -41,13 +51,8 @@ parameters:
path: src/Message.php

-
message: "#^Cannot call method getDecodedContent\\(\\) on mixed\\.$#"
count: 2
path: src/Message/AbstractMessage.php

-
message: "#^Cannot call method getSubtype\\(\\) on mixed\\.$#"
count: 2
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

-
Expand All @@ -65,16 +70,31 @@ 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
Expand Down Expand Up @@ -157,7 +177,12 @@ parameters:

-
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsInt\\(\\) with int will always evaluate to true\\.$#"
count: 2
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
path: tests/ConnectionTest.php

-
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<phpunit
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 All @@ -14,7 +15,6 @@
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="coverage" />
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>
Expand Down
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion src/Message/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Message/Transcoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion tests/MailboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 8fc09ee

Please sign in to comment.