Skip to content

Commit

Permalink
Merge pull request #278 from ray-di/cleanup
Browse files Browse the repository at this point in the history
Set tmpdir in environment variable
  • Loading branch information
koriym committed Oct 5, 2022
2 parents 1143ded + d892d2d commit 416bc48
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 86 deletions.
7 changes: 7 additions & 0 deletions composer.json
Expand Up @@ -58,5 +58,12 @@
"metrics": ["@test", "./vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception --log-junit=build/junit.xml --junit=build/junit.xml src"],
"phpmd": ["./vendor/bin/phpmd src/di text ./phpmd.xml"],
"build": ["@cs", "@sa", "@pcov", "@metrics"]
},
"extra": {
"bamarni-bin": {
"bin-links": true,
"target-directory": "vendor-bin",
"forward-command": false
}
}
}
2 changes: 2 additions & 0 deletions demo-php8/run.php
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

putenv('TMPDIR=' . __DIR__ . '/tmp');

passthru('php ' . __DIR__ . '/01a-linked-binding.php');
passthru('php ' . __DIR__ . '/01b-linked-binding-setter-injection.php');
passthru('php ' . __DIR__ . '/02-provider-binding.php');
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Expand Up @@ -10,6 +10,5 @@ parameters:
- tests/Di/tmp/*
- tests/di/Fake/*
ignoreErrors:
- '#Parameter \#1 \$interface of method Ray\\Di\\Injector::getInstance\(\) expects class-string\<\>, string given.#'
- '#contains generic class ReflectionAttribute but does not specify its types:#'
- '#generic class ReflectionAttribute but does not specify its types:#'
2 changes: 1 addition & 1 deletion src/di/AssistedInterceptor.php
Expand Up @@ -78,7 +78,7 @@ public function injectAssistedParameters(ReflectionMethod $method, Assisted $ass
$name = $this->getName($method, $parameter);
$pos = $parameter->getPosition();
/** @psalm-suppress MixedAssignment */
$arguments[$pos] = $this->injector->getInstance($interface, $name); // @phpstan-ignore-line
$arguments[$pos] = $this->injector->getInstance($interface, $name);
}

return $arguments;
Expand Down
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Expand Up @@ -4,6 +4,8 @@

use function Ray\Compiler\deleteFiles;

putenv('TMPDIR=' . __DIR__ . '/tmp');

require_once dirname(__DIR__) . '/vendor/autoload.php';

deleteFiles(__DIR__ . '/tmp');
Expand Down
6 changes: 3 additions & 3 deletions tests/di/AssistedTest.php
Expand Up @@ -14,7 +14,7 @@ class AssistedTest extends TestCase

protected function setUp(): void
{
$this->injector = new Injector(new FakeToBindModule(), __DIR__ . '/tmp');
$this->injector = new Injector(new FakeToBindModule());
}

public function testAssisted(): void
Expand Down Expand Up @@ -46,7 +46,7 @@ public function testAssistedAnyWithName(): void

public function testAssistedMethodInvocation(): void
{
$assistedConsumer = (new Injector(new FakeAssistedDbModule(), __DIR__ . '/tmp'))->getInstance(FakeAssistedParamsConsumer::class);
$assistedConsumer = (new Injector(new FakeAssistedDbModule()))->getInstance(FakeAssistedParamsConsumer::class);
[$id, $db] = $assistedConsumer->getUser(1);
/** @var FakeAbstractDb $db */
$this->assertSame(1, $id);
Expand All @@ -62,7 +62,7 @@ public function testAssistedMethodInvocationNotAvailable(): void

public function testAssistedCustomInject(): void
{
$assistedConsumer = (new Injector(new FakeAssistedDbModule(), __DIR__ . '/tmp'))->getInstance(FakeAssistedParamsConsumer::class);
$assistedConsumer = (new Injector(new FakeAssistedDbModule()))->getInstance(FakeAssistedParamsConsumer::class);
[$id] = $assistedConsumer->getUser(1);
$this->assertSame(1, $id);
}
Expand Down
16 changes: 8 additions & 8 deletions tests/di/InjectorTest.php
Expand Up @@ -198,7 +198,7 @@ public function testSerialize(Injector $injector): void

public function testAop(): void
{
$injector = new Injector(new FakeAopModule(), __DIR__ . '/tmp');
$injector = new Injector(new FakeAopModule());
$instance = $injector->getInstance(FakeAopInterface::class);
/** @var FakeAop $instance */
$result = $instance->returnSame(2);
Expand All @@ -219,7 +219,7 @@ protected function configure()
);
}
};
$injector = new Injector($module, __DIR__ . '/tmp');
$injector = new Injector($module);
$instance = $injector->getInstance(FakeAopInterface::class);
/** @var FakeAop $instance */
$result = $instance->returnSame(2);
Expand All @@ -243,7 +243,7 @@ public function testSerializeBuiltinBinding(): void

public function testAopBoundInDifferentModule(): void
{
$injector = new Injector(new FakeAopInstallModule(), __DIR__ . '/tmp');
$injector = new Injector(new FakeAopInstallModule());
$instance = $injector->getInstance(FakeAopInterface::class);
/** @var FakeAop $instance */
$result = $instance->returnSame(2);
Expand All @@ -252,7 +252,7 @@ public function testAopBoundInDifferentModule(): void

public function testAopBoundInDifferentModuleAfterAnotherBinding(): void
{
$injector = new Injector(new FakeAopInstallModule(new FakeAopModule()), __DIR__ . '/tmp');
$injector = new Injector(new FakeAopInstallModule(new FakeAopModule()));
$instance = $injector->getInstance(FakeAopInterface::class);
/** @var FakeAop $instance */
$result = $instance->returnSame(2);
Expand All @@ -261,7 +261,7 @@ public function testAopBoundInDifferentModuleAfterAnotherBinding(): void

public function testAopBoundDoublyInDifferentModule(): void
{
$injector = new Injector(new FakeAopDoublyInstallModule(), __DIR__ . '/tmp');
$injector = new Injector(new FakeAopDoublyInstallModule());
$instance = $injector->getInstance(FakeAopInterface::class);
/** @var FakeAop $instance */
$result = $instance->returnSame(2);
Expand Down Expand Up @@ -291,15 +291,15 @@ public function testAopClassAutoloader(): void

public function testAopOnDemandByUnboundConcreteClass(): void
{
$injector = new Injector(new FakeAopInterceptorModule(), __DIR__ . '/tmp');
$injector = new Injector(new FakeAopInterceptorModule());
$instance = $injector->getInstance(FakeAop::class);
$result = $instance->returnSame(2);
$this->assertSame(4, $result);
}

public function testBindOrder(): void
{
$injector = new Injector(new FakeAnnoModule(), __DIR__ . '/tmp');
$injector = new Injector(new FakeAnnoModule());
$instance = $injector->getInstance(FakeAnnoOrderClass::class);
$instance->get();
$expect = [FakeAnnoInterceptor4::class, FakeAnnoInterceptor1::class, FakeAnnoInterceptor2::class, FakeAnnoInterceptor3::class, FakeAnnoInterceptor5::class];
Expand All @@ -308,7 +308,7 @@ public function testBindOrder(): void

public function testAnnotateConstant(): void
{
$instance = (new Injector(new FakeConstantModule(), __DIR__ . '/tmp'))->getInstance(FakeConstantConsumer::class);
$instance = (new Injector(new FakeConstantModule()))->getInstance(FakeConstantConsumer::class);
$this->assertSame('default_construct', $instance->defaultByConstruct);
}

Expand Down

0 comments on commit 416bc48

Please sign in to comment.