Server IP : 85.214.239.14 / Your IP : 3.133.149.244 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /var/www/wordpress/phpMyAdmin/vendor/dasprid/enum/test/ |
Upload File : |
<?php declare(strict_types = 1); namespace DASPRiD\EnumTest; use DASPRiD\Enum\AbstractEnum; use DASPRiD\Enum\Exception\CloneNotSupportedException; use DASPRiD\Enum\Exception\IllegalArgumentException; use DASPRiD\Enum\Exception\MismatchException; use DASPRiD\Enum\Exception\SerializeNotSupportedException; use DASPRiD\Enum\Exception\UnserializeNotSupportedException; use PHPUnit\Framework\TestCase; use ReflectionClass; final class AbstractEnumTest extends TestCase { public function setUp() { $reflectionClass = new ReflectionClass(AbstractEnum::class); $constantsProperty = $reflectionClass->getProperty('constants'); $constantsProperty->setAccessible(true); $constantsProperty->setValue([]); $valuesProperty = $reflectionClass->getProperty('values'); $valuesProperty->setAccessible(true); $valuesProperty->setValue([]); $allValuesLoadedProperty = $reflectionClass->getProperty('allValuesLoaded'); $allValuesLoadedProperty->setAccessible(true); $allValuesLoadedProperty->setValue([]); } public function testToString() : void { $weekday = WeekDay::FRIDAY(); self::assertSame('FRIDAY', (string) $weekday); } public function testName() : void { $this->assertSame('WEDNESDAY', WeekDay::WEDNESDAY()->name()); } public function testOrdinal() : void { $this->assertSame(2, WeekDay::WEDNESDAY()->ordinal()); } public function testSameInstanceIsReturned() : void { self::assertSame(WeekDay::FRIDAY(), WeekDay::FRIDAY()); } public static function testValueOf() : void { self::assertSame(WeekDay::FRIDAY(), WeekDay::valueOf('FRIDAY')); } public function testValueOfInvalidConstant() : void { $this->expectException(IllegalArgumentException::class); WeekDay::valueOf('CATURDAY'); } public function testExceptionOnCloneAttempt() : void { $this->expectException(CloneNotSupportedException::class); clone WeekDay::FRIDAY(); } public function testExceptionOnSerializeAttempt() : void { $this->expectException(SerializeNotSupportedException::class); serialize(WeekDay::FRIDAY()); } public function testExceptionOnUnserializeAttempt() : void { $this->expectException(UnserializeNotSupportedException::class); unserialize('O:24:"DASPRiD\\EnumTest\\WeekDay":0:{}'); } public function testReturnValueOfValuesIsSortedByOrdinal() : void { // Initialize some week days out of order WeekDay::SATURDAY(); WeekDay::TUESDAY(); $ordinals = array_values(array_map(function (WeekDay $weekDay) : int { return $weekDay->ordinal(); }, WeekDay::values())); self::assertSame([0, 1, 2, 3, 4, 5, 6], $ordinals); $cachedOrdinals = array_values(array_map(function (WeekDay $weekDay) : int { return $weekDay->ordinal(); }, WeekDay::values())); $this->assertSame($ordinals, $cachedOrdinals); } public function testCompareTo() : void { $this->assertSame(-4, WeekDay::WEDNESDAY()->compareTo(WeekDay::SUNDAY())); $this->assertSame(4, WeekDay::SUNDAY()->compareTo(WeekDay::WEDNESDAY())); $this->assertSame(0, WeekDay::WEDNESDAY()->compareTo(WeekDay::WEDNESDAY())); } public function testCompareToWrongEnum() : void { $this->expectException(MismatchException::class); WeekDay::MONDAY()->compareTo(Planet::EARTH()); } public function testParameterizedEnum() : void { $planet = Planet::EARTH(); $this->assertSame(5.976e+24, $planet->mass()); $this->assertSame(6.37814e6, $planet->radius()); } }