Skip to content

Commit

Permalink
Cover #452 with a test: PHP 7.1's nullable types
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Dec 9, 2017
1 parent 93ac9f1 commit 6afc629
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/IntegrationTest/Definitions/AutowireDefinition/Php71.php
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

namespace DI\Test\IntegrationTest\Definitions\AutowireDefinition;

class Php71
{
/**
* @var null|\stdClass
*/
public $param;

public function __construct(?\stdClass $param)
{
$this->param = $param;
}
}
17 changes: 17 additions & 0 deletions tests/IntegrationTest/Definitions/AutowireDefinitionTest.php
Expand Up @@ -7,6 +7,7 @@
use DI\ContainerBuilder;
use DI\Test\IntegrationTest\BaseContainerTest;
use DI\Test\IntegrationTest\Definitions\AutowireDefinition\OptionalParameterFollowedByRequiredParameter;
use DI\Test\IntegrationTest\Definitions\AutowireDefinition\Php71;
use DI\Test\IntegrationTest\Definitions\AutowireDefinitionTest\ConstructorInjection;
use DI\Test\IntegrationTest\Definitions\AutowireDefinitionTest\LazyService;
use DI\Test\IntegrationTest\Definitions\AutowireDefinitionTest\NullableConstructorParameter;
Expand Down Expand Up @@ -321,6 +322,22 @@ public function test_optional_parameter_followed_by_required_parameters(Containe
self::assertNull($object->first);
self::assertInstanceOf(\stdClass::class, $object->second);
}

/**
* @dataProvider provideContainer
*/
public function test_php71_nullable_typehint(ContainerBuilder $builder)
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('This test cannot run on PHP 7');
}

$container = $builder->build();

$object = $container->get(Php71::class);

self::assertEquals(new \stdClass, $object->param);
}
}

namespace DI\Test\IntegrationTest\Definitions\AutowireDefinitionTest;
Expand Down

0 comments on commit 6afc629

Please sign in to comment.