Skip to content

Commit

Permalink
README.md: update instruction to build repo locally (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Aug 3, 2022
1 parent 8b772d0 commit c09e9c6
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 75 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 --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' }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ vendor/
composer.lock
phpunit.xml
wait-for-it
coverage/
38 changes: 33 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
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"
chmod +x 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
Expand All @@ -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)
22 changes: 5 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
18 changes: 6 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -45,10 +44,5 @@
"psr-4": {
"Ddeboer\\Imap\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"malukenho/mcbumpface": true
}
}
}
41 changes: 8 additions & 33 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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\\<string\\>, array\\<int, Ddeboer\\\\Imap\\\\MessageInterface\\|int\\|string\\> given\\.$#"
count: 1
Expand All @@ -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

-
Expand All @@ -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
Expand Down Expand Up @@ -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

-
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<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 @@ -15,6 +14,7 @@
<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 c09e9c6

Please sign in to comment.