Skip to content

Commit 46a75ab

Browse files
committed
tests updated to use the correct config
1 parent 5e0f4a8 commit 46a75ab

19 files changed

+149
-80
lines changed

tests/ClientManagerTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Webklex\PHPIMAP\Client;
1717
use Webklex\PHPIMAP\ClientManager;
18+
use Webklex\PHPIMAP\Config;
1819
use Webklex\PHPIMAP\Exceptions\MaskNotFoundException;
1920
use Webklex\PHPIMAP\IMAP;
2021

@@ -38,10 +39,12 @@ public function setUp(): void {
3839
* @return void
3940
*/
4041
public function testConfigAccessorAccount(): void {
41-
self::assertSame("default", ClientManager::get("default"));
42-
self::assertSame("d-M-Y", ClientManager::get("date_format"));
43-
self::assertSame(IMAP::FT_PEEK, ClientManager::get("options.fetch"));
44-
self::assertSame([], ClientManager::get("options.open"));
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"));
4548
}
4649

4750
/**
@@ -59,12 +62,12 @@ public function testMakeClient(): void {
5962
* @throws MaskNotFoundException
6063
*/
6164
public function testAccountAccessor(): void {
62-
self::assertSame("default", $this->cm->getDefaultAccount());
65+
self::assertSame("default", $this->cm->getConfig()->getDefaultAccount());
6366
self::assertNotEmpty($this->cm->account("default"));
6467

65-
$this->cm->setDefaultAccount("foo");
66-
self::assertSame("foo", $this->cm->getDefaultAccount());
67-
$this->cm->setDefaultAccount("default");
68+
$this->cm->getConfig()->setDefaultAccount("foo");
69+
self::assertSame("foo", $this->cm->getConfig()->getDefaultAccount());
70+
$this->cm->getConfig()->setDefaultAccount("default");
6871
}
6972

7073
/**
@@ -82,10 +85,10 @@ public function testSetConfig(): void {
8285
];
8386
$cm = new ClientManager($config);
8487

85-
self::assertSame("foo", $cm->getDefaultAccount());
88+
self::assertSame("foo", $cm->getConfig()->getDefaultAccount());
8689
self::assertInstanceOf(Client::class, $cm->account("foo"));
87-
self::assertSame(IMAP::ST_MSGN, $cm->get("options.fetch"));
88-
self::assertSame(false, is_array($cm->get("options.open")));
90+
self::assertSame(IMAP::ST_MSGN, $cm->getConfig()->get("options.fetch"));
91+
self::assertSame(false, is_array($cm->getConfig()->get("options.open")));
8992

9093
}
9194
}

tests/ClientTest.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\MockObject\MockObject;
1616
use PHPUnit\Framework\TestCase;
1717
use Webklex\PHPIMAP\Client;
18+
use Webklex\PHPIMAP\Config;
1819
use Webklex\PHPIMAP\Connection\Protocols\ImapProtocol;
1920
use Webklex\PHPIMAP\Connection\Protocols\Response;
2021
use Webklex\PHPIMAP\Exceptions\AuthFailedException;
@@ -42,18 +43,22 @@ class ClientTest extends TestCase {
4243
* @throws MaskNotFoundException
4344
*/
4445
public function setUp(): void {
45-
$this->client = new Client([
46-
'protocol' => 'imap',
47-
'encryption' => 'ssl',
48-
'username' => '[email protected]',
49-
'password' => 'bar',
50-
'proxy' => [
51-
'socket' => null,
52-
'request_fulluri' => false,
53-
'username' => null,
54-
'password' => null,
55-
],
56-
]);
46+
$config = Config::make([
47+
"accounts" => [
48+
"default" => [
49+
'protocol' => 'imap',
50+
'encryption' => 'ssl',
51+
'username' => '[email protected]',
52+
'password' => 'bar',
53+
'proxy' => [
54+
'socket' => null,
55+
'request_fulluri' => false,
56+
'username' => null,
57+
'password' => null,
58+
],
59+
]]
60+
]);
61+
$this->client = new Client($config);
5762
}
5863

5964
/**
@@ -274,18 +279,19 @@ public function testClientId(): void {
274279
}
275280

276281
public function testClientConfig(): void {
277-
$config = $this->client->getConfig();
282+
$config = $this->client->getConfig()->get("accounts.".$this->client->getConfig()->getDefaultAccount());
278283
self::assertSame("[email protected]", $config["username"]);
279284
self::assertSame("bar", $config["password"]);
280285
self::assertSame("localhost", $config["host"]);
281286
self::assertSame(true, $config["validate_cert"]);
282287
self::assertSame(993, $config["port"]);
283288

284-
$this->client->setConfig([
285-
"host" => "domain.tld",
286-
'password' => 'bar',
287-
]);
288-
$config = $this->client->getConfig();
289+
$this->client->getConfig()->set("accounts.".$this->client->getConfig()->getDefaultAccount(), [
290+
"host" => "domain.tld",
291+
'password' => 'bar',
292+
]);
293+
$config = $this->client->getConfig()->get("accounts.".$this->client->getConfig()->getDefaultAccount());
294+
289295
self::assertSame("bar", $config["password"]);
290296
self::assertSame("domain.tld", $config["host"]);
291297
self::assertSame(true, $config["validate_cert"]);

tests/HeaderTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,25 @@
1616
use PHPUnit\Framework\TestCase;
1717
use Webklex\PHPIMAP\Address;
1818
use Webklex\PHPIMAP\Attribute;
19+
use Webklex\PHPIMAP\Config;
1920
use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException;
2021
use Webklex\PHPIMAP\Header;
2122
use Webklex\PHPIMAP\IMAP;
2223

2324
class HeaderTest extends TestCase {
2425

26+
/** @var Config $config */
27+
protected Config $config;
28+
29+
/**
30+
* Setup the test environment.
31+
*
32+
* @return void
33+
*/
34+
public function setUp(): void {
35+
$this->config = Config::make();
36+
}
37+
2538
/**
2639
* Test parsing email headers
2740
*
@@ -35,7 +48,7 @@ public function testHeaderParsing(): void {
3548

3649
$raw_header = substr($email, 0, strpos($email, "\r\n\r\n"));
3750

38-
$header = new Header($raw_header);
51+
$header = new Header($raw_header, $this->config);
3952
$subject = $header->get("subject");
4053
$returnPath = $header->get("Return-Path");
4154
/** @var Carbon $date */
@@ -80,9 +93,9 @@ public function testRfc822ParseHeaders() {
8093
->onlyMethods([])
8194
->getMock();
8295

83-
$config = new \ReflectionProperty($mock, 'config');
96+
$config = new \ReflectionProperty($mock, 'options');
8497
$config->setAccessible(true);
85-
$config->setValue($mock, ['rfc822' => true]);
98+
$config->setValue($mock, $this->config->get("options"));
8699

87100
$mockHeader = "Content-Type: text/csv; charset=WINDOWS-1252; name*0=\"TH_Is_a_F ile name example 20221013.c\"; name*1=sv\r\nContent-Transfer-Encoding: quoted-printable\r\nContent-Disposition: attachment; filename*0=\"TH_Is_a_F ile name example 20221013.c\"; filename*1=\"sv\"\r\n";
88101

tests/ImapProtocolTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@
1313
namespace Tests;
1414

1515
use PHPUnit\Framework\TestCase;
16+
use Webklex\PHPIMAP\Config;
1617
use Webklex\PHPIMAP\Connection\Protocols\ImapProtocol;
1718
use Webklex\PHPIMAP\Exceptions\ConnectionFailedException;
1819

1920
class ImapProtocolTest extends TestCase {
2021

22+
/** @var Config $config */
23+
protected Config $config;
24+
25+
/**
26+
* Setup the test environment.
27+
*
28+
* @return void
29+
*/
30+
public function setUp(): void {
31+
$this->config = Config::make();
32+
}
33+
2134

2235
/**
2336
* ImapProtocol test
@@ -26,7 +39,7 @@ class ImapProtocolTest extends TestCase {
2639
*/
2740
public function testImapProtocol(): void {
2841

29-
$protocol = new ImapProtocol(false);
42+
$protocol = new ImapProtocol($this->config, false);
3043
self::assertSame(false, $protocol->getCertValidation());
3144
self::assertSame("", $protocol->getEncryption());
3245

tests/MessageTest.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Webklex\PHPIMAP\Attachment;
1919
use Webklex\PHPIMAP\Attribute;
2020
use Webklex\PHPIMAP\Client;
21+
use Webklex\PHPIMAP\Config;
2122
use Webklex\PHPIMAP\Connection\Protocols\Response;
2223
use Webklex\PHPIMAP\Exceptions\EventNotFoundException;
2324
use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException;
@@ -51,21 +52,24 @@ class MessageTest extends TestCase {
5152
* Setup the test environment.
5253
*
5354
* @return void
54-
* @throws MaskNotFoundException
5555
*/
5656
public function setUp(): void {
57-
$this->client = new Client([
58-
'protocol' => 'imap',
59-
'encryption' => 'ssl',
60-
'username' => '[email protected]',
61-
'password' => 'bar',
62-
'proxy' => [
63-
'socket' => null,
64-
'request_fulluri' => false,
65-
'username' => null,
66-
'password' => null,
67-
],
68-
]);
57+
$config = Config::make([
58+
"accounts" => [
59+
"default" => [
60+
'protocol' => 'imap',
61+
'encryption' => 'ssl',
62+
'username' => '[email protected]',
63+
'password' => 'bar',
64+
'proxy' => [
65+
'socket' => null,
66+
'request_fulluri' => false,
67+
'username' => null,
68+
'password' => null,
69+
],
70+
]]
71+
]);
72+
$this->client = new Client($config);
6973
}
7074

7175
/**

tests/PartTest.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Carbon\Carbon;
1616
use PHPUnit\Framework\TestCase;
17+
use Webklex\PHPIMAP\Config;
1718
use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException;
1819
use Webklex\PHPIMAP\Exceptions\MessageContentFetchingException;
1920
use Webklex\PHPIMAP\Header;
@@ -23,6 +24,18 @@
2324

2425
class PartTest extends TestCase {
2526

27+
/** @var Config $config */
28+
protected Config $config;
29+
30+
/**
31+
* Setup the test environment.
32+
*
33+
* @return void
34+
*/
35+
public function setUp(): void {
36+
$this->config = Config::make();
37+
}
38+
2639
/**
2740
* Test parsing a text Part
2841
* @throws InvalidMessageDateException
@@ -31,8 +44,8 @@ public function testTextPart(): void {
3144
$raw_headers = "Content-Type: text/plain;\r\n charset=UTF-8\r\nContent-Transfer-Encoding: 7bit\r\n";
3245
$raw_body = "\r\nAny updates?";
3346

34-
$headers = new Header($raw_headers);
35-
$part = new Part($raw_body, $headers, 0);
47+
$headers = new Header($raw_headers, $this->config);
48+
$part = new Part($raw_body, $this->config, $headers, 0);
3649

3750
self::assertSame("UTF-8", $part->charset);
3851
self::assertSame("text/plain", $part->content_type);
@@ -53,8 +66,8 @@ public function testHTMLPart(): void {
5366
$raw_headers = "Content-Type: text/html;\r\n charset=UTF-8\r\nContent-Transfer-Encoding: 7bit\r\n";
5467
$raw_body = "\r\n<p></p>\r\n<p dir=\"auto\">Any updates?</p>";
5568

56-
$headers = new Header($raw_headers);
57-
$part = new Part($raw_body, $headers, 0);
69+
$headers = new Header($raw_headers, $this->config);
70+
$part = new Part($raw_body, $this->config, $headers, 0);
5871

5972
self::assertSame("UTF-8", $part->charset);
6073
self::assertSame("text/html", $part->content_type);
@@ -75,8 +88,8 @@ public function testBase64Part(): void {
7588
$raw_headers = "Content-Type: application/octet-stream; name=6mfFxiU5Yhv9WYJx.txt\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=6mfFxiU5Yhv9WYJx.txt\r\n";
7689
$raw_body = "em5rNTUxTVAzVFAzV1BwOUtsMWduTEVycldFZ2tKRkF0dmFLcWtUZ3JrM2RLSThkWDM4WVQ4QmFW\r\neFJjT0VSTg==";
7790

78-
$headers = new Header($raw_headers);
79-
$part = new Part($raw_body, $headers, 0);
91+
$headers = new Header($raw_headers, $this->config);
92+
$part = new Part($raw_body, $this->config, $headers, 0);
8093

8194
self::assertSame("", $part->charset);
8295
self::assertSame("application/octet-stream", $part->content_type);

tests/StructureTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,26 @@
1313
namespace Tests;
1414

1515
use PHPUnit\Framework\TestCase;
16+
use Webklex\PHPIMAP\Config;
1617
use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException;
1718
use Webklex\PHPIMAP\Exceptions\MessageContentFetchingException;
1819
use Webklex\PHPIMAP\Header;
1920
use Webklex\PHPIMAP\Structure;
2021

2122
class StructureTest extends TestCase {
2223

24+
/** @var Config $config */
25+
protected Config $config;
26+
27+
/**
28+
* Setup the test environment.
29+
*
30+
* @return void
31+
*/
32+
public function setUp(): void {
33+
$this->config = Config::make();
34+
}
35+
2336
/**
2437
* Test parsing email headers
2538
*
@@ -35,7 +48,7 @@ public function testStructureParsing(): void {
3548
$raw_header = substr($email, 0, strpos($email, "\r\n\r\n"));
3649
$raw_body = substr($email, strlen($raw_header)+8);
3750

38-
$header = new Header($raw_header);
51+
$header = new Header($raw_header, $this->config);
3952
$structure = new Structure($raw_body, $header);
4053

4154
self::assertSame(2, count($structure->parts));

tests/fixtures/DateTemplateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testFixture() : void {
8181
"fallback_date" => "2021-01-01 00:00:00",
8282
],
8383
]);
84-
$message = $this->getFixture("date-template.eml");
84+
$message = $this->getFixture("date-template.eml", self::$manager->getConfig());
8585

8686
self::assertEquals("test", $message->subject);
8787
self::assertEquals("1.0", $message->mime_version);

tests/fixtures/FixtureTestCase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use PHPUnit\Framework\TestCase;
1616
use Webklex\PHPIMAP\ClientManager;
17+
use Webklex\PHPIMAP\Config;
1718
use Webklex\PHPIMAP\Exceptions\AuthFailedException;
1819
use Webklex\PHPIMAP\Exceptions\ConnectionFailedException;
1920
use Webklex\PHPIMAP\Exceptions\ImapBadRequestException;
@@ -83,9 +84,9 @@ final public function __construct(?string $name = null, array $data = [], $dataN
8384
* @throws ResponseException
8485
* @throws RuntimeException
8586
*/
86-
final public function getFixture(string $template) : Message {
87+
final public function getFixture(string $template, Config $config = null) : Message {
8788
$filename = implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "messages", $template]);
88-
$message = Message::fromFile($filename);
89+
$message = Message::fromFile($filename, $config);
8990
self::assertInstanceOf(Message::class, $message);
9091

9192
return $message;

tests/issues/Issue355Test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
namespace Tests\issues;
1414

1515
use PHPUnit\Framework\TestCase;
16+
use Webklex\PHPIMAP\Config;
1617
use Webklex\PHPIMAP\Header;
1718

1819
class Issue355Test extends TestCase {
1920

2021
public function testIssue() {
2122
$raw_header = "Subject: =?UTF-8?Q?Re=3A_Uppdaterat_=C3=A4rende_=28447899=29=2C_kostnader_f=C3=B6r_hj=C3=A4?= =?UTF-8?Q?lp_med_stadge=C3=A4ndring_enligt_ny_lagstiftning?=\r\n";
2223

23-
$header = new Header($raw_header);
24+
$header = new Header($raw_header, Config::make());
2425
$subject = $header->get("subject");
2526

2627
$this->assertEquals("Re: Uppdaterat ärende (447899), kostnader för hjälp med stadgeändring enligt ny lagstiftning", $subject->toString());

0 commit comments

Comments
 (0)