Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tests/unit/PseudoTypes/ArrayKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\String_;
use PHPUnit\Framework\TestCase;

final class ArrayKeyTest extends TestCase
{
public function testArrayKeyCanBeConstructedAndStringifiedCorrectly(): void
public function testCreate(): void
{
$type = new ArrayKey();

$this->assertEquals(new Compound([new String_(), new Integer()]), $type->underlyingType());
}

public function testToString(): void
{
$this->assertSame('array-key', (string) (new ArrayKey()));
}
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/PseudoTypes/ArrayShapeItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use PHPUnit\Framework\TestCase;

class ArrayShapeItemTest extends TestCase
{
public function testCreate(): void
{
$key = 'abc';
$value = new IntegerValue(100);
$item = new ArrayShapeItem($key, $value, true);

$this->assertSame($key, $item->getKey());
$this->assertSame($value, $item->getValue());
$this->assertTrue($item->isOptional());
}
}
5 changes: 4 additions & 1 deletion tests/unit/PseudoTypes/ArrayShapeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Mixed_;
use PHPUnit\Framework\TestCase;

class ArrayShapeTest extends TestCase
{
public function testExposeItems(): void
public function testCreate(): void
{
$item1 = new ArrayShapeItem('foo', new True_(), false);
$item2 = new ArrayShapeItem('bar', new False_(), true);

$arrayShape = new ArrayShape($item1, $item2);

$this->assertSame([$item1, $item2], $arrayShape->getItems());
$this->assertEquals(new Array_(new Mixed_(), new ArrayKey()), $arrayShape->underlyingType());
}

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/PseudoTypes/CallableStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\String_;
use PHPUnit\Framework\TestCase;

class CallableStringTest extends TestCase
{
public function testCreate(): void
{
$type = new CallableString();

$this->assertEquals(new String_(), $type->underlyingType());
}

public function testToString(): void
{
$this->assertSame('callable-string', (string) (new CallableString()));
}
}
16 changes: 13 additions & 3 deletions tests/unit/PseudoTypes/ClassStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,32 @@
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Object_;
use phpDocumentor\Reflection\Types\String_;
use PHPUnit\Framework\TestCase;

class ClassStringTest extends TestCase
{
public function testCreate(): void
{
$genericType = new Object_(new Fqsen('\Foo\Bar'));
$type = new ClassString($genericType);

$this->assertSame($genericType, $type->getGenericType());
$this->assertEquals(new String_(), $type->underlyingType());
}

/**
* @dataProvider provideClassStrings
* @dataProvider provideToStringData
*/
public function testClassStringStringifyCorrectly(ClassString $type, string $expectedString): void
public function testToString(ClassString $type, string $expectedString): void
{
$this->assertSame($expectedString, (string) $type);
}

/**
* @return array<string, array{ClassString, string}>
*/
public function provideClassStrings(): array
public function provideToStringData(): array
{
return [
'generic class string' => [new ClassString(), 'class-string'],
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/PseudoTypes/ConditionalForParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\Static_;
use PHPUnit\Framework\TestCase;

Expand All @@ -24,6 +25,7 @@ public function testCreate(): void
$this->assertSame($targetType, $type->getTargetType());
$this->assertSame($if, $type->getIf());
$this->assertSame($else, $type->getElse());
$this->assertEquals(new Mixed_(), $type->underlyingType());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/PseudoTypes/ConditionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\Object_;
use phpDocumentor\Reflection\Types\Static_;
use PHPUnit\Framework\TestCase;
Expand All @@ -26,6 +27,7 @@ public function testCreate(): void
$this->assertSame($targetType, $type->getTargetType());
$this->assertSame($if, $type->getIf());
$this->assertSame($else, $type->getElse());
$this->assertEquals(new Mixed_(), $type->underlyingType());
}

/**
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/PseudoTypes/ConstExpressionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\Object_;
use PHPUnit\Framework\TestCase;

class ConstExpressionTest extends TestCase
{
public function testCreate(): void
{
$owner = new Object_(new Fqsen('\Foo\Bar'));
$expression = '*';
$type = new ConstExpression($owner, $expression);

$this->assertSame($owner, $type->getOwner());
$this->assertSame($expression, $type->getExpression());
$this->assertEquals(new Mixed_(), $type->underlyingType());
}
}
63 changes: 63 additions & 0 deletions tests/unit/PseudoTypes/EnumStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Object_;
use phpDocumentor\Reflection\Types\String_;
use PHPUnit\Framework\TestCase;

class EnumStringTest extends TestCase
{
public function testCreate(): void
{
$genericType = new Object_(new Fqsen('\Foo\Bar'));
$type = new EnumString($genericType);

$this->assertSame($genericType, $type->getGenericType());
$this->assertEquals(new String_(), $type->underlyingType());
}

/**
* @dataProvider provideToStringData
*/
public function testToString(EnumString $type, string $expectedString): void
{
$this->assertSame($expectedString, (string) $type);
}

/**
* @return array<string, array{EnumString, string}>
*/
public function provideToStringData(): array
{
return [
'basic' => [new EnumString(), 'enum-string'],
'with generics' => [
new EnumString(new Object_(new Fqsen('\Foo\Bar'))),
'enum-string<\Foo\Bar>',
],
'more than one enum' => [
new EnumString(
new Compound([
new Object_(new Fqsen('\Foo\Bar')),
new Object_(new Fqsen('\Foo\Barrr')),
])
),
'enum-string<\Foo\Bar|\Foo\Barrr>',
],
];
}
}
34 changes: 34 additions & 0 deletions tests/unit/PseudoTypes/FloatValueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Float_;
use PHPUnit\Framework\TestCase;

class FloatValueTest extends TestCase
{
public function testCreate(): void
{
$value = 12.12;
$type = new FloatValue($value);

$this->assertSame($value, $type->getValue());
$this->assertEquals(new Float_(), $type->underlyingType());
}

public function testToString(): void
{
$this->assertSame('12.12', (string) (new FloatValue(12.12)));
}
}
32 changes: 32 additions & 0 deletions tests/unit/PseudoTypes/HtmlEscapedStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\String_;
use PHPUnit\Framework\TestCase;

class HtmlEscapedStringTest extends TestCase
{
public function testCreate(): void
{
$type = new HtmlEscapedString();

$this->assertEquals(new String_(), $type->underlyingType());
}

public function testToString(): void
{
$this->assertSame('html-escaped-string', (string) (new HtmlEscapedString()));
}
}
2 changes: 2 additions & 0 deletions tests/unit/PseudoTypes/IntMaskOfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Integer;
use PHPUnit\Framework\TestCase;

class IntMaskOfTest extends TestCase
Expand All @@ -15,6 +16,7 @@ public function testCreate(): void
$type = new IntMaskOf($childType);

$this->assertSame($childType, $type->getType());
$this->assertEquals(new Integer(), $type->underlyingType());
}

public function testToString(): void
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/PseudoTypes/IntMaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Integer;
use PHPUnit\Framework\TestCase;

class IntMaskTest extends TestCase
Expand All @@ -14,6 +15,7 @@ public function testCreate(): void
$type = new IntMask(...$childTypes);

$this->assertSame($childTypes, $type->getTypes());
$this->assertEquals(new Integer(), $type->underlyingType());
}

public function testToString(): void
Expand Down
Loading