Skip to content

Commit

Permalink
Add tests for null and false as stand-alone types
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 27, 2022
1 parent 207c74e commit afad3e9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/_fixture/ClassWithMethodThatDeclaresFalseReturnType.php
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/type.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Type\TestFixture;

final class ClassWithMethodThatDeclaresFalseReturnType
{
public function falseReturnType(): false
{
}
}
17 changes: 17 additions & 0 deletions tests/_fixture/ClassWithMethodThatDeclaresNullReturnType.php
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/type.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Type\TestFixture;

final class ClassWithMethodThatDeclaresNullReturnType
{
public function nullReturnType(): null
{
}
}
24 changes: 24 additions & 0 deletions tests/unit/ReflectionMapperTest.php
Expand Up @@ -19,8 +19,10 @@
use SebastianBergmann\Type\TestFixture\ClassWithMethodsThatDeclareReturnTypes;
use SebastianBergmann\Type\TestFixture\ClassWithMethodsThatDeclareUnionReturnTypes;
use SebastianBergmann\Type\TestFixture\ClassWithMethodsThatHaveStaticReturnTypes;
use SebastianBergmann\Type\TestFixture\ClassWithMethodThatDeclaresFalseReturnType;
use SebastianBergmann\Type\TestFixture\ClassWithMethodThatDeclaresIntersectionReturnType;
use SebastianBergmann\Type\TestFixture\ClassWithMethodThatDeclaresNeverReturnType;
use SebastianBergmann\Type\TestFixture\ClassWithMethodThatDeclaresNullReturnType;
use SebastianBergmann\Type\TestFixture\ParentClass;

/**
Expand Down Expand Up @@ -162,6 +164,28 @@ public function testMapsFromNeverReturnType(): void
$this->assertSame('never', $type->name());
}

/**
* @requires PHP >= 8.2
*/
public function testMapsFromFalseReturnType(): void
{
$type = (new ReflectionMapper)->fromReturnType(new ReflectionMethod(ClassWithMethodThatDeclaresFalseReturnType::class, 'falseReturnType'));

$this->assertInstanceOf(FalseType::class, $type);
$this->assertSame('false', $type->name());
}

/**
* @requires PHP >= 8.2
*/
public function testMapsFromNullReturnType(): void
{
$type = (new ReflectionMapper)->fromReturnType(new ReflectionMethod(ClassWithMethodThatDeclaresNullReturnType::class, 'nullReturnType'));

$this->assertInstanceOf(NullType::class, $type);
$this->assertSame('null', $type->name());
}

public function typeProvider(): array
{
return [
Expand Down

0 comments on commit afad3e9

Please sign in to comment.