index/tests/TypeTest.php

50 lines
1.5 KiB
PHP
Raw Normal View History

2022-09-13 13:13:11 +00:00
<?php
// TypeTest.php
// Created: 2021-04-27
// Updated: 2022-02-28
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use Index\AString;
use Index\Type;
use Index\XArray;
/**
* @covers Type
*/
final class TypeTest extends TestCase {
public function testDefaults(): void {
$this->assertEquals(Type::default(Type::BOOL), false);
$this->assertEquals(Type::default(Type::INTEGER), 0);
$this->assertEquals(Type::default(Type::FLOAT), 0.0);
$this->assertEquals(Type::default(Type::STRING), '');
$this->assertEquals(Type::default(Type::ARRAY), []);
$this->assertEquals(Type::default(Type::OBJECT), null);
$this->assertEquals(Type::default(Type::RESOURCE), null);
$this->assertEquals(Type::default(Type::CLOSED_RESOURCE), null);
$this->assertEquals(Type::default(Type::NULL), null);
$this->assertEquals(Type::default(Type::UNKNOWN), null);
}
public function testClassTree(): void {
$array1 = Type::classTree(new AString('the'));
$array2 = [
'Index\\IString',
'Stringable',
'Traversable',
'Index\\Serialisation\\IBencodeSerialisable',
'Index\\IEquatable',
'Index\\ICloneable',
'Index\\IComparable',
'JsonSerializable',
'IteratorAggregate',
'Countable',
'ArrayAccess',
'Index\\AString',
];
$this->assertTrue(XArray::sequenceEquals($array1, $array2));
}
}