HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/posscale/public_html/printmanager/vendor/webklex/php-imap/tests/ClientManagerTest.php
<?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")));

    }
}