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
2 changes: 1 addition & 1 deletion src/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function setDefaultValue(\ReflectionParameter $parameter)
private function getType(\ReflectionParameter $parameter) : string
{
$type = $parameter->getType();
if ($type instanceof \ReflectionType && \in_array((string) $type, ['bool', 'int', 'string', 'array'], true)) {
if ($type instanceof \ReflectionType && \in_array((string) $type, ['bool', 'int', 'string', 'array', 'resource', 'callable'], true)) {
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ArgumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testToString()

public function testToStringScalar()
{
$argument = new Argument(new \ReflectionParameter([FakeScalarType::class, 'stringId'], 'id'), Name::ANY);
$argument = new Argument(new \ReflectionParameter([FakeInternalTypes::class, 'stringId'], 'id'), Name::ANY);
$this->assertSame('-' . Name::ANY, (string) $argument);
}
}
16 changes: 16 additions & 0 deletions tests/Fake/FakeInternalTypeModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace Ray\Di;

class FakeInternalTypeModule extends AbstractModule
{
protected function configure()
{
$this->bind('')->annotatedWith('type-bool')->toInstance(false);
$this->bind('')->annotatedWith('type-int')->toInstance(1);
$this->bind('')->annotatedWith('type-string')->toInstance('1');
$this->bind('')->annotatedWith('type-array')->toInstance([1]);
$this->bind('')->annotatedWith('type-callable')->toInstance(function(){});
$this->bind('')->annotatedWith('type-object')->toInstance(new \stdClass);
$this->bind('')->annotatedWith('type-resource')->toInstance(fopen("foo", "w"));
}
}
35 changes: 35 additions & 0 deletions tests/Fake/FakeInternalTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Ray\Di;

use Ray\Di\Di\Named;

class FakeInternalTypes
{
public $bool;
public $int;
public $string;
public $array;
public $callable;

/**
* @Named("bool=type-bool,int=type-int,string=type-string,array=type-array,callable=type-callable")
*/
public function __construct(
bool $bool,
int $int,
string $string,
array $array,
callable $callable
) {
$this->bool = $bool;
$this->int = $int;
$this->string = $string;
$this->array = $array;
$this->callable = $callable;
}

public function stringId(string $id)
{
unset($id);
}
}
10 changes: 0 additions & 10 deletions tests/Fake/FakeScalarType.php

This file was deleted.

12 changes: 12 additions & 0 deletions tests/InjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,16 @@ public function testIsOptionalValue()
$this->assertInstanceOf(\PDO::class, $pdo);
}
}

public function testInternalTypes()
{
$injector = new Injector(new FakeInternalTypeModule);
/* @var FakeInternalTypes $types */
$types = $injector->getInstance(FakeInternalTypes::class);
$this->assertInternalType('bool', $types->bool);
$this->assertInternalType('callable', $types->callable);
$this->assertInternalType('array', $types->array);
$this->assertInternalType('string', $types->string);
$this->assertInternalType('int', $types->int);
}
}