‪TYPO3CMS  ‪main
MapTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
24 final class ‪MapTest extends UnitTestCase
25 {
26  #[Test]
27  public function ‪mapIsArrayAccessible(): void
28  {
29  $aKey = new \stdClass();
30  $aValue = new \stdClass();
31  $bKey = new \stdClass();
32  $bValue = new \stdClass();
33 
34  $map = new ‪Map();
35  $map[$aKey] = $aValue;
36  $map[$bKey] = $bValue;
37 
38  self::assertInstanceOf(Map::class, $map);
39  self::assertCount(2, $map);
40  self::assertSame($aValue, $map[$aKey]);
41  self::assertSame($bValue, $map[$bKey]);
42  }
43 
44  #[Test]
45  public function ‪mapKeyCanBeUnset(): void
46  {
47  $aKey = new \stdClass();
48  $aValue = new \stdClass();
49  $bKey = new \stdClass();
50  $bValue = new \stdClass();
51 
52  $map = new ‪Map();
53  $map[$aKey] = $aValue;
54  $map[$bKey] = $bValue;
55 
56  unset($map[$bKey]);
57 
58  self::assertCount(1, $map);
59  self::assertFalse(isset($map[$bKey]));
60  }
61 
62  #[Test]
63  public function ‪mapCanBeIterated(): void
64  {
65  $aKey = new \stdClass();
66  $aValue = new \stdClass();
67  $bKey = new \stdClass();
68  $bValue = new \stdClass();
69 
70  $map = new ‪Map();
71  $map[$aKey] = $aValue;
72  $map[$bKey] = $bValue;
73 
74  $entries = [];
75  foreach ($map as $key => $value) {
76  $entries[] = [$key, $value];
77  }
78 
79  $expectation = [
80  [$aKey, $aValue],
81  [$bKey, $bValue],
82  ];
83  self::assertSame($expectation, $entries);
84  }
85 
86  #[Test]
87  public function ‪mapIsCreatedFromEntries(): void
88  {
89  $aKey = new \stdClass();
90  $aValue = new \stdClass();
91  $bKey = new \stdClass();
92  $bValue = new \stdClass();
93 
94  $map = ‪Map::fromEntries(
95  [$aKey, $aValue],
96  [$bKey, $bValue],
97  );
98 
99  self::assertCount(2, $map);
100  self::assertSame($aValue, $map[$aKey]);
101  self::assertSame($bValue, $map[$bKey]);
102  }
103 }
‪TYPO3\CMS\Core\Type\Map\fromEntries
‪static fromEntries(array ... $entries)
Definition: Map.php:54
‪TYPO3\CMS\Core\Tests\Unit\Type\MapTest\mapIsCreatedFromEntries
‪mapIsCreatedFromEntries()
Definition: MapTest.php:87
‪TYPO3\CMS\Core\Tests\Unit\Type
Definition: BitSetTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Type\MapTest\mapIsArrayAccessible
‪mapIsArrayAccessible()
Definition: MapTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Type\MapTest\mapKeyCanBeUnset
‪mapKeyCanBeUnset()
Definition: MapTest.php:45
‪TYPO3\CMS\Core\Type\Map
Definition: Map.php:47
‪TYPO3\CMS\Core\Tests\Unit\Type\MapTest\mapCanBeIterated
‪mapCanBeIterated()
Definition: MapTest.php:63
‪TYPO3\CMS\Core\Tests\Unit\Type\MapTest
Definition: MapTest.php:25