| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
namespace Tests; |
| 14 |
|
| 15 |
use PHPUnit\Framework\TestCase; |
| 16 |
use Webklex\PHPIMAP\Client; |
| 17 |
use Webklex\PHPIMAP\ClientManager; |
| 18 |
use Webklex\PHPIMAP\Config; |
| 19 |
use Webklex\PHPIMAP\Exceptions\MaskNotFoundException; |
| 20 |
use Webklex\PHPIMAP\IMAP; |
| 21 |
|
| 22 |
class ClientManagerTest extends TestCase { |
| 23 |
|
| 24 |
|
| 25 |
protected ClientManager $cm; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function setUp(): void { |
| 33 |
$this->cm = new ClientManager(); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public function testConfigAccessorAccount(): void { |
| 42 |
$config = $this->cm->getConfig(); |
| 43 |
self::assertInstanceOf(Config::class, $config); |
| 44 |
self::assertSame("default", $config->get("default")); |
| 45 |
self::assertSame("d-M-Y", $config->get("date_format")); |
| 46 |
self::assertSame(IMAP::FT_PEEK, $config->get("options.fetch")); |
| 47 |
self::assertSame([], $config->get("options.open")); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function testMakeClient(): void { |
| 56 |
self::assertInstanceOf(Client::class, $this->cm->make([])); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public function testAccountAccessor(): void { |
| 65 |
self::assertSame("default", $this->cm->getConfig()->getDefaultAccount()); |
| 66 |
self::assertNotEmpty($this->cm->account("default")); |
| 67 |
|
| 68 |
$this->cm->getConfig()->setDefaultAccount("foo"); |
| 69 |
self::assertSame("foo", $this->cm->getConfig()->getDefaultAccount()); |
| 70 |
$this->cm->getConfig()->setDefaultAccount("default"); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public function testSetConfig(): void { |
| 79 |
$config = [ |
| 80 |
"default" => "foo", |
| 81 |
"options" => [ |
| 82 |
"fetch" => IMAP::ST_MSGN, |
| 83 |
"open" => "foo" |
| 84 |
] |
| 85 |
]; |
| 86 |
$cm = new ClientManager($config); |
| 87 |
|
| 88 |
self::assertSame("foo", $cm->getConfig()->getDefaultAccount()); |
| 89 |
self::assertInstanceOf(Client::class, $cm->account("foo")); |
| 90 |
self::assertSame(IMAP::ST_MSGN, $cm->getConfig()->get("options.fetch")); |
| 91 |
self::assertSame(false, is_array($cm->getConfig()->get("options.open"))); |
| 92 |
|
| 93 |
} |
| 94 |
} |