Debian Codegraph @

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

raw symbols SCIP
1 <?php
2 /*
3 * File: AttributeTest.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 Carbon\Carbon;
16 use PHPUnit\Framework\TestCase;
17 use Webklex\PHPIMAP\Attribute;
18
19 class AttributeTest extends TestCase {
20
21 /**
22 * String Attribute test
23 *
24 * @return void
25 */
26 public function testStringAttribute(): void {
27 $attribute = new Attribute("foo", "bar");
28
29 self::assertSame("bar", $attribute->toString());
30 self::assertSame("foo", $attribute->getName());
31 self::assertSame("foos", $attribute->setName("foos")->getName());
32 }
33
34 /**
35 * Date Attribute test
36 *
37 * @return void
38 */
39 public function testDateAttribute(): void {
40 $attribute = new Attribute("foo", "2022-12-26 08:07:14 GMT-0800");
41
42 self::assertInstanceOf(Carbon::class, $attribute->toDate());
43 self::assertSame("2022-12-26 08:07:14 GMT-0800", $attribute->toDate()->format("Y-m-d H:i:s T"));
44 }
45
46 /**
47 * Array Attribute test
48 *
49 * @return void
50 */
51 public function testArrayAttribute(): void {
52 $attribute = new Attribute("foo", ["bar"]);
53
54 self::assertSame("bar", $attribute->toString());
55
56 $attribute->add("bars");
57 self::assertSame(true, $attribute->has(1));
58 self::assertSame("bars", $attribute->get(1));
59 self::assertSame(true, $attribute->contains("bars"));
60 self::assertSame("foo, bars", $attribute->set("foo", 0)->toString());
61
62 $attribute->remove(0);
63 self::assertSame("bars", $attribute->toString());
64
65 self::assertSame("bars, foos", $attribute->merge(["foos", "bars"], true)->toString());
66 self::assertSame("bars, foos, foos, donk", $attribute->merge(["foos", "donk"], false)->toString());
67
68 self::assertSame(4, $attribute->count());
69
70 self::assertSame("donk", $attribute->last());
71 self::assertSame("bars", $attribute->first());
72
73 self::assertSame(["bars", "foos", "foos", "donk"], array_values($attribute->all()));
74 }
75 }