Hoa central
Registry.php
Go to the documentation of this file.
1 <?php
2 
38 
39 use Hoa\Registry as LUT;
40 use Hoa\Test;
41 
51 {
52  public function case_no_instance()
53  {
54  $this
55  ->exception(function () {
56  new LUT();
57  })
58  ->isInstanceOf('Hoa\Registry\Exception');
59  }
60 
61  public function case_classic()
62  {
63  $this
64  ->given(
65  $string = $this->realdom->string('a', 'z', 5),
66  $key = $this->sample($string),
67  $value = $this->sample($string),
68  LUT::set($key, $value)
69  )
70  ->when($result = LUT::get($key))
71  ->then
72  ->string($result)
73  ->isEqualTo($value);
74  }
75 
76  public function case_value_is_an_object()
77  {
78  $this
79  ->given(
80  $string = $this->realdom->string('a', 'z', 5),
81  $object = $this->realdom->class('StdClass'),
82  $key = $this->sample($string),
83  $value = $this->sample($object),
84  LUT::set($key, $value)
85  )
86  ->when($result = LUT::get($key))
87  ->then
88  ->object($result)
89  ->isInstanceOf('StdClass')
90  ->isIdenticalTo($value);
91  }
92 
93  public function case_isRegistered()
94  {
95  $this
96  ->given(
97  $string = $this->realdom->string('a', 'z', 5),
98  $key = $this->sample($string),
99  $value = $this->sample($string)
100  )
101  ->when($result = LUT::isRegistered($key))
102  ->then
103  ->boolean($result)
104  ->isFalse()
105 
106  ->when(
107  LUT::set($key, $value),
108  $result = LUT::isRegistered($key)
109  )
110  ->then
111  ->boolean($result)
112  ->isTrue()
113 
114  ->when(
115  LUT::remove($key),
116  $result = LUT::isRegistered($key)
117  )
118  ->then
119  ->boolean($result)
120  ->isFalse();
121  }
122 
123  public function case_protocol()
124  {
125  $this
126  ->given(
127  $string = $this->realdom->string('a', 'z', 5),
128  $key = $this->sample($string),
129  $value = $this->sample($string),
130  LUT::set($key, $value)
131  )
132  ->when($result = resolve('hoa://Library/Registry#' . $key))
133  ->then
134  ->string($result)
135  ->isEqualTo($value);
136  }
137 
139  {
140  $this
141  ->given(
142  $string = $this->realdom->string('a', 'z', 5),
143  $object = $this->realdom->class('StdClass'),
144  $key = $this->sample($string),
145  $value = $this->sample($object),
146  LUT::set($key, $value)
147  )
148  ->when(
149  $result1 = resolve('hoa://Library/Registry#' . $key),
150  $result2 = LUT::get($key)
151  )
152  ->then
153  ->object($result1)
154  ->isInstanceOf('StdClass')
155  ->isIdenticalTo($value)
156  ->isIdenticalTo($result2)
157 
158  ->given($dummy = $this->sample($string))
159  ->when(
160  $result1->foo = $dummy,
161  $result3 = resolve('hoa://Library/Registry#' . $key)
162  )
163  ->then
164  ->object($result1)
165  ->isIdenticalTo($result2)
166  ->isIdenticalTo($result3)
167 
168  ->string($result1->foo)
169  ->isEqualTo($dummy);
170  }
171 }