Debian Codegraph @

lib/3rdParty/composer/webklex/php-imap/tests/ClientManagerTest.php

raw symbols SCIP
1 <?php
2 /*
3 * File: ClientManagerTest.php
4 * Category: -
5 * Author: M.Goldenbaum
6 * Created: 28.12.22 18:11
7 * Updated: -
8 *
9 * Description:
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 /** @var ClientManager $cm */
25 protected ClientManager $cm;
26
27 /**
28 * Setup the test environment.
29 *
30 * @return void
31 */
32 public function setUp(): void {
33 $this->cm = new ClientManager();
34 }
35
36 /**
37 * Test if the config can be accessed
38 *
39 * @return void
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 * Test creating a client instance
52 *
53 * @throws MaskNotFoundException
54 */
55 public function testMakeClient(): void {
56 self::assertInstanceOf(Client::class, $this->cm->make([]));
57 }
58
59 /**
60 * Test accessing accounts
61 *
62 * @throws MaskNotFoundException
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 * Test setting a config
75 *
76 * @throws MaskNotFoundException
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 }