Debian Codegraph @

lib/3rdParty/composer/webklex/php-imap/tests/fixtures/FixtureTestCase.php

raw symbols SCIP
1 <?php
2 /*
3 * File: FixtureTestCase.php
4 * Category: -
5 * Author: M.Goldenbaum
6 * Created: 09.03.23 02:24
7 * Updated: -
8 *
9 * Description:
10 * -
11 */
12
13 namespace Tests\fixtures;
14
15 use PHPUnit\Framework\TestCase;
16 use Webklex\PHPIMAP\ClientManager;
17 use Webklex\PHPIMAP\Config;
18 use Webklex\PHPIMAP\Exceptions\AuthFailedException;
19 use Webklex\PHPIMAP\Exceptions\ConnectionFailedException;
20 use Webklex\PHPIMAP\Exceptions\ImapBadRequestException;
21 use Webklex\PHPIMAP\Exceptions\ImapServerErrorException;
22 use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException;
23 use Webklex\PHPIMAP\Exceptions\MaskNotFoundException;
24 use Webklex\PHPIMAP\Exceptions\MessageContentFetchingException;
25 use Webklex\PHPIMAP\Exceptions\ResponseException;
26 use Webklex\PHPIMAP\Exceptions\RuntimeException;
27 use Webklex\PHPIMAP\Message;
28 use \ReflectionException;
29
30 /**
31 * Class FixtureTestCase
32 *
33 * @package Tests\fixtures
34 */
35 abstract class FixtureTestCase extends TestCase {
36
37 /**
38 * Client manager
39 * @var ClientManager $manager
40 */
41 protected static ClientManager $manager;
42
43 /**
44 * FixtureTestCase constructor.
45 * @param string|null $name
46 * @param array $data
47 * @param $dataName
48 */
49 final public function __construct(?string $name = null, array $data = [], $dataName = '') {
50 parent::__construct($name, $data, $dataName);
51
52 self::$manager = new ClientManager([
53 'options' => [
54 "debug" => $_ENV["LIVE_MAILBOX_DEBUG"] ?? false,
55 ],
56 'accounts' => [
57 'default' => [
58 'host' => getenv("LIVE_MAILBOX_HOST"),
59 'port' => getenv("LIVE_MAILBOX_PORT"),
60 'encryption' => getenv("LIVE_MAILBOX_ENCRYPTION"),
61 'validate_cert' => getenv("LIVE_MAILBOX_VALIDATE_CERT"),
62 'username' => getenv("LIVE_MAILBOX_USERNAME"),
63 'password' => getenv("LIVE_MAILBOX_PASSWORD"),
64 'protocol' => 'imap', //might also use imap, [pop3 or nntp (untested)]
65 ],
66 ],
67 ]);
68 return self::$manager;
69 }
70
71 /**
72 * Get a fixture message
73 * @param string $template
74 *
75 * @return Message
76 * @throws ReflectionException
77 * @throws AuthFailedException
78 * @throws ConnectionFailedException
79 * @throws ImapBadRequestException
80 * @throws ImapServerErrorException
81 * @throws InvalidMessageDateException
82 * @throws MaskNotFoundException
83 * @throws MessageContentFetchingException
84 * @throws ResponseException
85 * @throws RuntimeException
86 */
87 final public function getFixture(string $template, ?Config $config = null) : Message {
88 $filename = implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "messages", $template]);
89 $message = Message::fromFile($filename, $config);
90 self::assertInstanceOf(Message::class, $message);
91
92 return $message;
93 }
94 }