ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
EntryLockingStringMapTest.php
Go to the documentation of this file.
1<?php
2
4
7use PHPUnit\Framework\TestCase;
8
9require_once './libs/composer/vendor/autoload.php';
10
21class EntryLockingStringMapTest extends TestCase
22{
23
27 private $subject;
28
32 public function setUp() : void
33 {
34 $this->subject = new EntryLockingStringMap();
35 }
36
41 {
42 $key = "hello";
43 $value = "world";
44 $this->subject->put($key, $value);
45 $result = $this->subject->toArray();
46
47 $this->assertArrayHasKey($key, $result);
48 $this->assertEquals($value, $result[$key]);
49 }
50
55 {
56 $key = "hello";
57 $value = "world";
58
59 $this->subject->put($key, $value);
60
61 $this->expectException(ElementAlreadyExistsException::class);
62 $this->expectExceptionMessage("Element $key can not be overwritten.");
63
64 $this->subject->put($key, $value);
65 }
66
70 public function testGetWhichShouldSucceed()
71 {
72 $key = "hello";
73 $value = "world";
74
75 $this->subject->put($key, $value);
76 $result = $this->subject->get($key);
77
78 $this->assertEquals($value, $result);
79 }
80
85 {
86 $key = "hello";
87
88 $this->expectException(NoSuchElementException::class);
89 $this->expectExceptionMessage("No meta data associated with key \"$key\".");
90 $this->subject->get($key);
91 }
92}
$result
An exception for terminatinating execution or to throw for unit testing.