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