1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
<?php
declare(strict_types=1);
namespace DI\Test\UnitTest\Definition\ObjectDefinition;
use DI\Definition\ObjectDefinition\MethodInjection;
use PHPUnit\Framework\TestCase;
/**
* @covers \DI\Definition\ObjectDefinition\MethodInjection
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\DI\Definition\ObjectDefinition\MethodInjection::class)]
class MethodInjectionTest extends TestCase
{
public function testBasicMethods()
{
$definition = new MethodInjection('foo');
$this->assertEquals('foo', $definition->getMethodName());
$this->assertEquals('', $definition->getName());
$this->assertEmpty($definition->getParameters());
}
public function testMergeParameters()
{
$definition1 = new MethodInjection('foo', [
0 => 'a',
1 => 'b',
]);
$definition2 = new MethodInjection('foo', [
1 => 'c',
2 => 'd',
]);
$definition1->merge($definition2);
$this->assertEquals(['a', 'b', 'd'], $definition1->getParameters());
}
/**
* Check that a merge will preserve "null" injections.
*/
public function testMergeParametersPreservesNull()
{
$definition1 = new MethodInjection('foo', [
0 => null,
]);
$definition2 = new MethodInjection('foo', [
0 => 'bar',
]);
$definition1->merge($definition2);
$this->assertEquals([null], $definition1->getParameters());
}
public function testEmptyParameters()
{
$this->assertEmpty((new MethodInjection('foo'))->getParameters());
}
public function testGetParameters()
{
$definition = new MethodInjection('foo', ['bar']);
$this->assertEquals(['bar'], $definition->getParameters());
}
public function testReplaceParameters()
{
$definition = new MethodInjection('foo', ['bar']);
$definition->replaceParameters(['bim']);
$this->assertEquals(['bim'], $definition->getParameters());
}
}
|