-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,331 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
phpunit: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: true | ||
matrix: | ||
php: ['8.0', 8.1, 8.2] | ||
|
||
name: PHP ${{ matrix.php }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: openssl, json, mbstring, iconv, fileinfo, libxml, zip | ||
coverage: none | ||
|
||
- name: Install Composer dependencies | ||
run: composer install --prefer-dist --no-interaction --no-progress | ||
|
||
- name: Execute tests | ||
run: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ vendor | |
composer.lock | ||
.idea | ||
/build/ | ||
test.php | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="PHP-IMAP Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="tap" target="build/report.tap"/> | ||
<log type="junit" target="build/report.junit.xml"/> | ||
<log type="coverage-html" target="build/coverage"/> | ||
<log type="coverage-text" target="build/coverage.txt"/> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
</php> | ||
</phpunit> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
<report> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
<html outputDirectory="build/coverage"/> | ||
<text outputFile="build/coverage.txt"/> | ||
</report> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="PHP-IMAP Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/* | ||
* File: AddressTest.php | ||
* Category: - | ||
* Author: M.Goldenbaum | ||
* Created: 28.12.22 18:11 | ||
* Updated: - | ||
* | ||
* Description: | ||
* - | ||
*/ | ||
|
||
namespace Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Webklex\PHPIMAP\Address; | ||
|
||
class AddressTest extends TestCase { | ||
|
||
/** | ||
* Test data | ||
* | ||
* @var array|string[] $data | ||
*/ | ||
protected array $data = [ | ||
"personal" => "Username", | ||
"mailbox" => "info", | ||
"host" => "domain.tld", | ||
"mail" => "[email protected]", | ||
"full" => "Username <[email protected]>", | ||
]; | ||
|
||
/** | ||
* Address test | ||
* | ||
* @return void | ||
*/ | ||
public function testAddress(): void { | ||
$address = new Address((object)$this->data); | ||
|
||
self::assertSame("Username", $address->personal); | ||
self::assertSame("info", $address->mailbox); | ||
self::assertSame("domain.tld", $address->host); | ||
self::assertSame("[email protected]", $address->mail); | ||
self::assertSame("Username <[email protected]>", $address->full); | ||
} | ||
|
||
/** | ||
* Test Address to string conversion | ||
* | ||
* @return void | ||
*/ | ||
public function testAddressToStringConversion(): void { | ||
$address = new Address((object)$this->data); | ||
|
||
self::assertSame("Username <[email protected]>", (string)$address); | ||
} | ||
|
||
/** | ||
* Test Address serialization | ||
* | ||
* @return void | ||
*/ | ||
public function testAddressSerialization(): void { | ||
$address = new Address((object)$this->data); | ||
|
||
foreach($address as $key => $value) { | ||
self::assertSame($this->data[$key], $value); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/* | ||
* File: AttributeTest.php | ||
* Category: - | ||
* Author: M.Goldenbaum | ||
* Created: 28.12.22 18:11 | ||
* Updated: - | ||
* | ||
* Description: | ||
* - | ||
*/ | ||
|
||
namespace Tests; | ||
|
||
use Carbon\Carbon; | ||
use PHPUnit\Framework\TestCase; | ||
use Webklex\PHPIMAP\Attribute; | ||
|
||
class AttributeTest extends TestCase { | ||
|
||
/** | ||
* String Attribute test | ||
* | ||
* @return void | ||
*/ | ||
public function testStringAttribute(): void { | ||
$attribute = new Attribute("foo", "bar"); | ||
|
||
self::assertSame("bar", $attribute->toString()); | ||
self::assertSame("foo", $attribute->getName()); | ||
self::assertSame("foos", $attribute->setName("foos")->getName()); | ||
} | ||
|
||
/** | ||
* Date Attribute test | ||
* | ||
* @return void | ||
*/ | ||
public function testDateAttribute(): void { | ||
$attribute = new Attribute("foo", "2022-12-26 08:07:14 GMT-0800"); | ||
|
||
self::assertInstanceOf(Carbon::class, $attribute->toDate()); | ||
self::assertSame("2022-12-26 08:07:14 GMT-0800", $attribute->toDate()->format("Y-m-d H:i:s T")); | ||
} | ||
|
||
/** | ||
* Array Attribute test | ||
* | ||
* @return void | ||
*/ | ||
public function testArrayAttribute(): void { | ||
$attribute = new Attribute("foo", ["bar"]); | ||
|
||
self::assertSame("bar", $attribute->toString()); | ||
|
||
$attribute->add("bars"); | ||
self::assertSame(true, $attribute->has(1)); | ||
self::assertSame("bars", $attribute->get(1)); | ||
self::assertSame(true, $attribute->contains("bars")); | ||
self::assertSame("foo, bars", $attribute->set("foo", 0)->toString()); | ||
|
||
$attribute->remove(0); | ||
self::assertSame("bars", $attribute->toString()); | ||
|
||
self::assertSame("bars, foos", $attribute->merge(["foos", "bars"], true)->toString()); | ||
self::assertSame("bars, foos, foos, donk", $attribute->merge(["foos", "donk"], false)->toString()); | ||
|
||
self::assertSame(4, $attribute->count()); | ||
|
||
self::assertSame("donk", $attribute->last()); | ||
self::assertSame("bars", $attribute->first()); | ||
|
||
self::assertSame(["bars", "foos", "foos", "donk"], array_values($attribute->all())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/* | ||
* File: ClientManagerTest.php | ||
* Category: - | ||
* Author: M.Goldenbaum | ||
* Created: 28.12.22 18:11 | ||
* Updated: - | ||
* | ||
* Description: | ||
* - | ||
*/ | ||
|
||
namespace Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Webklex\PHPIMAP\Client; | ||
use Webklex\PHPIMAP\ClientManager; | ||
use Webklex\PHPIMAP\Exceptions\MaskNotFoundException; | ||
use Webklex\PHPIMAP\IMAP; | ||
|
||
class ClientManagerTest extends TestCase { | ||
|
||
/** @var ClientManager $cm */ | ||
protected ClientManager $cm; | ||
|
||
/** | ||
* Setup the test environment. | ||
* | ||
* @return void | ||
*/ | ||
public function setUp(): void { | ||
$this->cm = new ClientManager(); | ||
} | ||
|
||
/** | ||
* Test if the config can be accessed | ||
* | ||
* @return void | ||
*/ | ||
public function testConfigAccessorAccount(): void { | ||
self::assertSame("default", ClientManager::get("default")); | ||
self::assertSame("d-M-Y", ClientManager::get("date_format")); | ||
self::assertSame(IMAP::FT_PEEK, ClientManager::get("options.fetch")); | ||
self::assertSame([], ClientManager::get("options.open")); | ||
} | ||
|
||
/** | ||
* Test creating a client instance | ||
* | ||
* @throws MaskNotFoundException | ||
*/ | ||
public function testMakeClient(): void { | ||
self::assertInstanceOf(Client::class, $this->cm->make([])); | ||
} | ||
|
||
/** | ||
* Test accessing accounts | ||
* | ||
* @throws MaskNotFoundException | ||
*/ | ||
public function testAccountAccessor(): void { | ||
self::assertSame("default", $this->cm->getDefaultAccount()); | ||
self::assertNotEmpty($this->cm->account("default")); | ||
|
||
$this->cm->setDefaultAccount("foo"); | ||
self::assertSame("foo", $this->cm->getDefaultAccount()); | ||
$this->cm->setDefaultAccount("default"); | ||
} | ||
|
||
/** | ||
* Test setting a config | ||
* | ||
* @throws MaskNotFoundException | ||
*/ | ||
public function testSetConfig(): void { | ||
$config = [ | ||
"default" => "foo", | ||
"options" => [ | ||
"fetch" => IMAP::ST_MSGN, | ||
"open" => "foo" | ||
] | ||
]; | ||
$cm = new ClientManager($config); | ||
|
||
self::assertSame("foo", $cm->getDefaultAccount()); | ||
self::assertInstanceOf(Client::class, $cm->account("foo")); | ||
self::assertSame(IMAP::ST_MSGN, $cm->get("options.fetch")); | ||
self::assertSame(false, is_array($cm->get("options.open"))); | ||
|
||
} | ||
} |
Oops, something went wrong.