329e01ca996b22359d3444e7a78959e7142393b9
[core.git] / tests / framework / config / FrameworkConfigurationTest.php
1 <?php
2
3 // Same namespace as target class
4 namespace CoreFramework\Configuration;
5
6 // Inport framework stuff
7 use CoreFramework\Console\Tools\ConsoleTools;
8 use CoreFramework\Loader\ClassLoader;
9 use CoreFramework\Generic\NullPointerException;
10 use CoreFramework\Generic\UnsupportedOperationException;
11
12 // Import PHPUnit stuff
13 use PHPUnit\Framework\Error\Notice;
14 use PHPUnit\Framework\TestCase;
15
16 // Import SPL stuff
17 use \InvalidArgumentException;
18
19 /*
20  * Copyright (C) 2017 Roland Haeder<roland@mxchange.org>
21  *
22  * This program is free software: you can redistribute it and/or modify
23  * it under the terms of the GNU General Public License as published by
24  * the Free Software Foundation, either version 3 of the License, or
25  * (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30  * GNU General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License
33  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
34  */
35
36 class FrameworkConfigurationTest extends TestCase {
37
38         /**
39          * The configuration instance being tested
40          */
41         private static $configInstance = NULL;
42
43         /**
44          * Own IP address
45          */
46         private static $ipAddress = FALSE;
47
48         /**
49          * Setup test case
50          */
51         public function setUp() {
52                 // Trace message
53                 //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
54
55                 // Call parent method
56                 parent::setUp();
57
58                 // Trace message
59                 //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
60
61         }
62
63         /**
64          * Setup test case
65          */
66         public static function setUpBeforeClass() {
67                 // Trace message
68                 //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
69
70                 // Call parent method
71                 parent::setUpBeforeClass();
72
73                 // Init instance
74                 self::$configInstance = FrameworkConfiguration::getSelfInstance();
75
76                 /*
77                  * Disable strict naming-convention check in own class loader, because
78                  * PHP_Invoker doesn't have namespaces.
79                  */
80                 ClassLoader::enableStrictNamingConventionCheck(FALSE);
81
82                 // Quiet DNS resolver as this is not wanted here
83                 self::$configInstance->setConfigEntry('quiet_dns_resolver', TRUE);
84
85                 // Lookup own IP address
86                 self::$ipAddress = ConsoleTools::acquireSelfIpAddress();
87
88                 // Trace message
89                 //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
90         }
91
92         /**
93          * Tests if __toString() returns proper name
94          */
95         public function testConfigToStringClassName () {
96                 // Get it
97                 $className = self::$configInstance->__toString();
98
99                 // Should be equal
100                 $this->assertEquals('CoreFramework\Configuration\FrameworkConfiguration', $className);
101         }
102
103         /**
104          * Tests getting a singleton instance
105          */
106         public function testGettingSelfConfigInstance () {
107                 // Get instance
108                 $dummyInstance = FrameworkConfiguration::getSelfInstance();
109
110                 // Should be equal to own instance
111                 $this->assertEquals(self::$configInstance, $dummyInstance);
112         }
113
114         /**
115          * Tests equals() method
116          */
117         public function testEqualsConfigInstance () {
118                 // Get instance
119                 $dummyInstance = FrameworkConfiguration::getSelfInstance();
120
121                 // Should return TRUE
122                 $this->assertTrue(self::$configInstance->equals($dummyInstance));
123         }
124
125         /**
126          * Tests hashCode() method
127          */
128         public function testHashCodeConfigInstance () {
129                 // Get instance
130                 $dummyInstance = FrameworkConfiguration::getSelfInstance();
131
132                 // Get hash code from both
133                 $hashCodeExpected = self::$configInstance->hashCode();
134                 $hashCodeActual = $dummyInstance->hashCode();
135
136                 // Should be equal
137                 $this->assertEquals($hashCodeExpected, $hashCodeActual);
138         }
139
140         /**
141          * Tests if getting configuration entry returns an array
142          */
143         public function testGettingConfigurationArray () {
144                 // Get it
145                 $config = self::$configInstance->getConfigurationArray();
146
147                 // Should be an array
148                 $this->assertTrue(is_array($config));
149         }
150
151         /**
152          * Tests if getting configuration entry returns a filled array
153          */
154         public function testGettingfilledConfigurationArray () {
155                 // Get it
156                 $config = self::$configInstance->getConfigurationArray();
157
158                 // Should be an array
159                 $this->assertTrue(count($config) > 0);
160         }
161
162         /**
163          * Tests if getting whole configuration entry is the same for another
164          * singleton instance
165          */
166         public function testSameConfigurationArrayGetter () {
167                 // Get instance
168                 $dummyInstance = FrameworkConfiguration::getSelfInstance();
169
170                 // Get it from both instances
171                 $config1 = self::$configInstance->getConfigurationArray();
172                 $config2 = $dummyInstance->getConfigurationArray();
173
174                 // Should be the same
175                 $this->assertEquals($config1, $config2);
176         }
177
178         /**
179          * Tests if a proper exception is thrown when check for a NULL key
180          */
181         public function testCheckingNullConfigKey () {
182                 // Will throw this exception
183                 $this->expectException(NullPointerException::class);
184
185                 // Test it
186                 $dummy = self::$configInstance->isConfigurationEntrySet(NULL);
187         }
188
189         /**
190          * Tests if a proper exception is thrown when checking a boolean key
191          */
192         public function testCheckingBooleanConfigKey () {
193                 // Will throw this exception
194                 $this->expectException(InvalidArgumentException::class);
195
196                 // Test it
197                 $dummy = self::$configInstance->isConfigurationEntrySet(FALSE);
198         }
199
200         /**
201          * Tests if a proper exception is thrown when checking an empty key
202          */
203         public function testCheckingEmptyConfigKey () {
204                 // Will throw this exception
205                 $this->expectException(InvalidArgumentException::class);
206
207                 // Test it
208                 $dummy = self::$configInstance->isConfigurationEntrySet('');
209         }
210
211         /**
212          * Tests if a proper exception is thrown when checking an array key
213          */
214         public function testCheckingArrayConfigKey () {
215                 // Will throw this exception
216                 $this->expectException(InvalidArgumentException::class);
217
218                 // Test it
219                 $dummy = self::$configInstance->isConfigurationEntrySet(array());
220         }
221
222         /**
223          * Tests if a proper exception is thrown when checking a decimal key
224          */
225         public function testCheckingDecimalConfigKey () {
226                 // Will throw this exception
227                 $this->expectException(InvalidArgumentException::class);
228
229                 // Test it
230                 $dummy = self::$configInstance->isConfigurationEntrySet(12345);
231         }
232
233         /**
234          * Tests if a proper exception is thrown when checking a float key
235          */
236         public function testCheckingFloatConfigKey () {
237                 // Will throw this exception
238                 $this->expectException(InvalidArgumentException::class);
239
240                 // Test it
241                 $dummy = self::$configInstance->isConfigurationEntrySet(123.45);
242         }
243
244         /**
245          * Tests if a proper exception is thrown when checking an object key
246          */
247         public function testCheckingObjectConfigKey () {
248                 // Will throw this exception
249                 $this->expectException(InvalidArgumentException::class);
250
251                 // Test it
252                 $dummy = self::$configInstance->isConfigurationEntrySet($this);
253         }
254
255         /**
256          * Tests if a proper exception is thrown when checking a resource key
257          */
258         public function testCheckingResourceConfigKey () {
259                 // Will throw this exception
260                 $this->expectException(InvalidArgumentException::class);
261
262                 // Init some resource
263                 $resource = fopen(__FILE__, 'r');
264
265                 // Test it
266                 $dummy = self::$configInstance->isConfigurationEntrySet($resource);
267         }
268
269         /**
270          * Tests if checking an existing (well-known) key can be found and returns
271          * TRUE.
272          */
273         public function testCheckingExistingConfigKey () {
274                 // Should return TRUE
275                 $this->assertTrue(self::$configInstance->isConfigurationEntrySet('application_base_path'));
276         }
277
278         /**
279          * Tests if checking a non-existing key will return FALSE.
280          */
281         public function testCheckingNonExistingConfigKey () {
282                 // Should return FALSE
283                 $this->assertFalse(self::$configInstance->isConfigurationEntrySet('__non_existing_key__'));
284         }
285
286         /**
287          * Tests if a proper exception is thrown when getting a NULL key
288          */
289         public function testGettingNullConfigKey () {
290                 // Will throw this exception
291                 $this->expectException(NullPointerException::class);
292
293                 // Test it
294                 $dummy = self::$configInstance->getConfigEntry(NULL);
295         }
296
297         /**
298          * Tests if a proper exception is thrown when getting a boolean key
299          */
300         public function testGettingBooleanConfigKey () {
301                 // Will throw this exception
302                 $this->expectException(InvalidArgumentException::class);
303
304                 // Test it
305                 $dummy = self::$configInstance->getConfigEntry(FALSE);
306         }
307
308         /**
309          * Tests if a proper exception is thrown when getting an empty key
310          */
311         public function testGettingEmptyConfigKey () {
312                 // Will throw this exception
313                 $this->expectException(InvalidArgumentException::class);
314
315                 // Test it
316                 $dummy = self::$configInstance->getConfigEntry('');
317         }
318
319         /**
320          * Tests if a proper exception is thrown when getting a decimal key
321          */
322         public function testGettingDecimalConfigKey () {
323                 // Will throw this exception
324                 $this->expectException(InvalidArgumentException::class);
325
326                 // Test it
327                 $dummy = self::$configInstance->getConfigEntry(12345);
328         }
329
330         /**
331          * Tests if a proper exception is thrown when getting a float key
332          */
333         public function testGettingFloatConfigKey () {
334                 // Will throw this exception
335                 $this->expectException(InvalidArgumentException::class);
336
337                 // Test it
338                 $dummy = self::$configInstance->getConfigEntry(123.45);
339         }
340
341         /**
342          * Tests if a proper exception is thrown when getting an array key
343          */
344         public function testGettingArrayConfigKey () {
345                 // Will throw this exception
346                 $this->expectException(InvalidArgumentException::class);
347
348                 // Test it
349                 $dummy = self::$configInstance->getConfigEntry(array());
350         }
351
352         /**
353          * Tests if a proper exception is thrown when getting an object key
354          */
355         public function testGettingObjectConfigKey () {
356                 // Will throw this exception
357                 $this->expectException(InvalidArgumentException::class);
358
359                 // Test it
360                 $dummy = self::$configInstance->getConfigEntry($this);
361         }
362
363         /**
364          * Tests if a proper exception is thrown when getting a resource key
365          */
366         public function testGettingResourceConfigKey () {
367                 // Will throw this exception
368                 $this->expectException(InvalidArgumentException::class);
369
370                 // Init some resource
371                 $resource = fopen(__FILE__, 'r');
372
373                 // Test it
374                 $dummy = self::$configInstance->getConfigEntry($resource);
375         }
376
377         /**
378          * Tests if getting a non-existing key will cause a proper exception been
379          * thrown.
380          */
381         public function testGettingNonExistingConfigKey () {
382                 // Should cause this exception
383                 $this->expectException(NoConfigEntryException::class);
384
385                 // Get non-existing key
386                 $dummy = self::$configInstance->getConfigEntry('__non_existing_key__');
387         }
388
389         /**
390          * Tests if a generic key 'application_base_path' can be found.
391          */
392         public function testGettingConfigKeyApplicationBasePathExists () {
393                 // Get it from config instance
394                 $value = self::$configInstance->getConfigEntry('application_base_path');
395
396                 // Is it a readable path?
397                 $this->assertDirectoryIsReadable($value);
398         }
399
400         /**
401          * Tests setting a NULL key (value doesn't matter)
402          */
403         public function testSettingNullConfigKey () {
404                 // Will throw this exception
405                 $this->expectException(NullPointerException::class);
406
407                 // Test it
408                 self::$configInstance->setConfigEntry(NULL, 'foo');
409         }
410
411         /**
412          * Tests setting a boolean key (value doesn't matter)
413          */
414         public function testSettingBooleanConfigKey () {
415                 // Will throw this exception
416                 $this->expectException(InvalidArgumentException::class);
417
418                 // Test it
419                 self::$configInstance->setConfigEntry(FALSE, 'foo');
420         }
421
422         /**
423          * Tests setting an empty key (value doesn't matter)
424          */
425         public function testSettingEmptyConfigKey () {
426                 // Will throw this exception
427                 $this->expectException(InvalidArgumentException::class);
428
429                 // Test it
430                 self::$configInstance->setConfigEntry('', 'foo');
431         }
432
433         /**
434          * Tests setting a decimal key (value doesn't matter)
435          */
436         public function testSettingDecimalConfigKey () {
437                 // Will throw this exception
438                 $this->expectException(InvalidArgumentException::class);
439
440                 // Test it
441                 self::$configInstance->setConfigEntry(12345, 'foo');
442         }
443
444         /**
445          * Tests setting a float key (value doesn't matter)
446          */
447         public function testSettingFloatConfigKey () {
448                 // Will throw this exception
449                 $this->expectException(InvalidArgumentException::class);
450
451                 // Test it
452                 self::$configInstance->setConfigEntry(123.45, 'foo');
453         }
454
455         /**
456          * Tests setting an array key (value doesn't matter)
457          */
458         public function testSettingArrayConfigKey () {
459                 // Will throw this exception
460                 $this->expectException(InvalidArgumentException::class);
461
462                 // Test it
463                 self::$configInstance->setConfigEntry(array(), 'foo');
464         }
465
466         /**
467          * Tests setting an object key (value doesn't matter)
468          */
469         public function testSettingObjectConfigKey () {
470                 // Will throw this exception
471                 $this->expectException(InvalidArgumentException::class);
472
473                 // Test it
474                 self::$configInstance->setConfigEntry($this, 'foo');
475         }
476
477         /**
478          * Tests setting a resource key (value doesn't matter)
479          */
480         public function testSettingResourceConfigKey () {
481                 // Will throw this exception
482                 $this->expectException(InvalidArgumentException::class);
483
484                 // Init some resource
485                 $resource = fopen(__FILE__, 'r');
486
487                 // Test it
488                 self::$configInstance->setConfigEntry($resource, 'foo');
489         }
490
491         /**
492          * Tests setting a valid key but array for value
493          */
494         public function testSettingArrayValueConfigKey () {
495                 // Will throw this exception
496                 $this->expectException(InvalidArgumentException::class);
497
498                 // Test it
499                 self::$configInstance->setConfigEntry('foo', array());
500         }
501
502         /**
503          * Tests setting a valid key but object for value
504          */
505         public function testSettingObjectValueConfigKey () {
506                 // Will throw this exception
507                 $this->expectException(InvalidArgumentException::class);
508
509                 // Test it
510                 self::$configInstance->setConfigEntry('foo', $this);
511         }
512
513         /**
514          * Tests setting a valid key but resource for value
515          */
516         public function testSettingResourceValueConfigKey () {
517                 // Will throw this exception
518                 $this->expectException(InvalidArgumentException::class);
519
520                 // Init some resource
521                 $resource = fopen(__FILE__, 'r');
522
523                 // Test it
524                 self::$configInstance->setConfigEntry('foo', $resource);
525         }
526
527         /**
528          * Tests unsetting NULL key
529          */
530         public function testUnsettingNullConfigKey () {
531                 // Will throw this exception
532                 $this->expectException(NullPointerException::class);
533
534                 // Test it
535                 self::$configInstance->unsetConfigEntry(NULL);
536         }
537
538         /**
539          * Tests unsetting boolean key
540          */
541         public function testUnsettingBooleanConfigKey () {
542                 // Will throw this exception
543                 $this->expectException(InvalidArgumentException::class);
544
545                 // Test it
546                 self::$configInstance->unsetConfigEntry(FALSE);
547         }
548
549         /**
550          * Tests unsetting decimal key
551          */
552         public function testUnsettingDecimalConfigKey () {
553                 // Will throw this exception
554                 $this->expectException(InvalidArgumentException::class);
555
556                 // Test it
557                 self::$configInstance->unsetConfigEntry(12345);
558         }
559
560         /**
561          * Tests unsetting float key
562          */
563         public function testUnsettingFloatConfigKey () {
564                 // Will throw this exception
565                 $this->expectException(InvalidArgumentException::class);
566
567                 // Test it
568                 self::$configInstance->unsetConfigEntry(123.45);
569         }
570
571         /**
572          * Tests unsetting array key
573          */
574         public function testUnsettingArrayConfigKey () {
575                 // Will throw this exception
576                 $this->expectException(InvalidArgumentException::class);
577
578                 // Test it
579                 self::$configInstance->unsetConfigEntry(array());
580         }
581
582         /**
583          * Tests unsetting object key
584          */
585         public function testUnsettingObjectConfigKey () {
586                 // Will throw this exception
587                 $this->expectException(InvalidArgumentException::class);
588
589                 // Test it
590                 self::$configInstance->unsetConfigEntry($this);
591         }
592
593         /**
594          * Tests unsetting resource key
595          */
596         public function testUnsettingResourceConfigKey () {
597                 // Will throw this exception
598                 $this->expectException(InvalidArgumentException::class);
599
600                 // Init some resource
601                 $resource = fopen(__FILE__, 'r');
602
603                 // Test it
604                 self::$configInstance->unsetConfigEntry($resource);
605         }
606
607         /**
608          * Tests unsetting an empty key
609          */
610         public function testUnettingEmptyConfigKey () {
611                 // Will throw this exception
612                 $this->expectException(InvalidArgumentException::class);
613
614                 // Test it
615                 self::$configInstance->unsetConfigEntry('');
616         }
617
618         /**
619          * Tests unsetting a non-existing key
620          */
621         public function testUnettingNonExistingConfigKey () {
622                 // Will throw this exception
623                 $this->expectException(NoConfigEntryException::class);
624
625                 // Test it
626                 self::$configInstance->unsetConfigEntry('__non_existing_key__');
627         }
628
629         /**
630          * Tests setting and getting a key will return same value of same type
631          * (NULL). This unit test does also unset the then existing key.
632          */
633         public function testSettingGettiingNullConfigKey () {
634                 // Set test value
635                 self::$configInstance->setConfigEntry('__test_key', NULL);
636
637                 // Get it
638                 $value = self::$configInstance->getConfigEntry('__test_key');
639
640                 // Must be equal
641                 $this->assertEquals(NULL, $value);
642
643                 // Unset it
644                 self::$configInstance->unsetConfigEntry('__test_key');
645         }
646
647         /**
648          * Tests setting and getting a key will return same value of same type.
649          * This unit test does also unset the then existing key.
650          */
651         public function testSettingGettiingConfigKey () {
652                 // Set test value
653                 self::$configInstance->setConfigEntry('__test_key', 'foo');
654
655                 // Get it
656                 $value = self::$configInstance->getConfigEntry('__test_key');
657
658                 // Must be equal
659                 $this->assertEquals('foo', $value);
660
661                 // Unset it
662                 self::$configInstance->unsetConfigEntry('__test_key');
663         }
664
665         /**
666          * Tests setting a NULL default timezone
667          */
668         public function testSettingNullDefaultTimezone () {
669                 // Will throw this exception
670                 $this->expectException(NullPointerException::class);
671
672                 // Test it
673                 self::$configInstance->setDefaultTimezone(NULL);
674         }
675
676         /**
677          * Tests setting a boolean default timezone
678          */
679         public function testSettingBooleanDefaultTimezone () {
680                 // Will throw this exception
681                 $this->expectException(InvalidArgumentException::class);
682
683                 // Test it
684                 self::$configInstance->setDefaultTimezone(FALSE);
685         }
686
687         /**
688          * Tests setting a decimal default timezone
689          */
690         public function testSettingDecimalDefaultTimezone () {
691                 // Will throw this exception
692                 $this->expectException(InvalidArgumentException::class);
693
694                 // Test it
695                 self::$configInstance->setDefaultTimezone(12345);
696         }
697
698         /**
699          * Tests setting a float default timezone
700          */
701         public function testSettingFloatDefaultTimezone () {
702                 // Will throw this exception
703                 $this->expectException(InvalidArgumentException::class);
704
705                 // Test it
706                 self::$configInstance->setDefaultTimezone(123.45);
707         }
708
709         /**
710          * Tests setting an array default timezone
711          */
712         public function testSettingArrayDefaultTimezone () {
713                 // Will throw this exception
714                 $this->expectException(InvalidArgumentException::class);
715
716                 // Test it
717                 self::$configInstance->setDefaultTimezone(array());
718         }
719
720         /**
721          * Tests setting an object default timezone
722          */
723         public function testSettingObjectDefaultTimezone () {
724                 // Will throw this exception
725                 $this->expectException(InvalidArgumentException::class);
726
727                 // Test it
728                 self::$configInstance->setDefaultTimezone($this);
729         }
730
731         /**
732          * Tests setting a resource default timezone
733          */
734         public function testSettingResourceDefaultTimezone () {
735                 // Will throw this exception
736                 $this->expectException(InvalidArgumentException::class);
737
738                 // Init some resource
739                 $resource = fopen(__FILE__, 'r');
740
741                 // Test it
742                 self::$configInstance->setDefaultTimezone($resource);
743         }
744
745         /**
746          * Tests setting an empty default timezone
747          */
748         public function testSettingEmptyDefaultTimezone () {
749                 // Will throw this exception
750                 $this->expectException(InvalidArgumentException::class);
751
752                 // Test it
753                 self::$configInstance->setDefaultTimezone('');
754         }
755
756         /**
757          * Tests setting invalid timezone
758          */
759         public function testSettingInvalidDefaultTimezone () {
760                 // Expect Notice
761                 $this->expectException(Notice::class);
762
763                 // Try to set it
764                 self::$configInstance->setDefaultTimezone('!invalid!');
765         }
766
767         /**
768          * Tests setting valid timezone
769          */
770         public function testSettingValidDefaultTimezone () {
771                 // Will be true
772                 $this->assertTrue(self::$configInstance->setDefaultTimezone('Europe/Berlin'));
773         }
774
775         /**
776          * Tests if detectServerAddress is returning what it should for tests.
777          * This will always be 127.0.0.1.
778          */
779         public function testConfigDetectServerAddress () {
780                 // Call it
781                 $serverAddress = self::$configInstance->detectServerAddress();
782
783                 // Should be the same
784                 $this->assertEquals(self::$ipAddress, $serverAddress);
785         }
786
787         /**
788          * Re-tests if detectServerAddress is returning what it should for tests.
789          * This will always be 127.0.0.1. This call should not invoke
790          * ConsoleTools's method as the configuration entry is already cached.
791          */
792         public function testConfigDetectServerAddressCached () {
793                 // Call it
794                 $serverAddress = self::$configInstance->detectServerAddress();
795
796                 // Should be the same
797                 $this->assertEquals(self::$ipAddress, $serverAddress);
798         }
799
800         /**
801          * Tests setting a NULL server address
802          */
803         public function testConfigSettingNullServerAddress () {
804                 // Expect this exception
805                 $this->expectException(NullPointerException::class);
806
807                 // Test it
808                 self::$configInstance->setServerAddress(NULL);
809         }
810
811         /**
812          * Tests setting a boolean server address
813          */
814         public function testConfigSettingBooleanServerAddress () {
815                 // Expect this exception
816                 $this->expectException(InvalidArgumentException::class);
817
818                 // Test it
819                 self::$configInstance->setServerAddress(FALSE);
820         }
821
822         /**
823          * Tests setting a decimal server address
824          */
825         public function testConfigSettingDecimalServerAddress () {
826                 // Expect this exception
827                 $this->expectException(InvalidArgumentException::class);
828
829                 // Test it
830                 self::$configInstance->setServerAddress(12345);
831         }
832
833         /**
834          * Tests setting a float server address
835          */
836         public function testConfigSettingFloatServerAddress () {
837                 // Expect this exception
838                 $this->expectException(InvalidArgumentException::class);
839
840                 // Test it
841                 self::$configInstance->setServerAddress(123.45);
842         }
843
844         /**
845          * Tests setting an array server address
846          */
847         public function testConfigSettingArrayServerAddress () {
848                 // Expect this exception
849                 $this->expectException(InvalidArgumentException::class);
850
851                 // Test it
852                 self::$configInstance->setServerAddress(array());
853         }
854
855         /**
856          * Tests setting an object server address
857          */
858         public function testConfigSettingObjectServerAddress () {
859                 // Expect this exception
860                 $this->expectException(InvalidArgumentException::class);
861
862                 // Test it
863                 self::$configInstance->setServerAddress($this);
864         }
865
866         /**
867          * Tests setting a resource server address
868          */
869         public function testConfigSettingResourceServerAddress () {
870                 // Expect this exception
871                 $this->expectException(InvalidArgumentException::class);
872
873                 // Init some resource
874                 $resource = fopen(__FILE__, 'r');
875
876                 // Test it
877                 self::$configInstance->setServerAddress($resource);
878         }
879
880         /**
881          * Tests setting an empty server address
882          */
883         public function testConfigSettingEmptyServerAddress () {
884                 // Expect this exception
885                 $this->expectException(InvalidArgumentException::class);
886
887                 // Test it
888                 self::$configInstance->setServerAddress('');
889         }
890
891         /**
892          * Tests setting a valid server address and getting it back
893          */
894         public function testConfigGettingValidServerAddress () {
895                 // Test it
896                 self::$configInstance->setServerAddress('127.0.0.1');
897
898                 // Get it back
899                 $serverAddress = self::$configInstance->getServerAddress();
900
901                 // Should be equal
902                 $this->assertEquals('127.0.0.1', $serverAddress);
903
904                 // Set old back
905                 self::$configInstance->setServerAddress(self::$ipAddress);
906         }
907
908         /**
909          * Tests if the method getField() is still unsupported in this class. Please
910          * note, that this and isFieldSet() may get removed in the future. So also
911          * these test methods will be gone.
912          */
913         public function testConfigGetFieldUnsupported () {
914                 // Expect this exception
915                 $this->expectException(UnsupportedOperationException::class);
916
917                 // Test it
918                 $dummy = self::$configInstance->getField('foo');
919         }
920
921         /**
922          * Tests if the method isFieldSet() is still unsupported in this class. Please
923          * note, that this and getField() may get removed in the future. So also
924          * these test methods will be gone.
925          */
926         public function testConfigIsFieldSetUnsupported () {
927                 // Expect this exception
928                 $this->expectException(UnsupportedOperationException::class);
929
930                 // Test it
931                 $dummy = self::$configInstance->isFieldSet('foo');
932         }
933
934 }