98 lines
2.9 KiB
PHP
98 lines
2.9 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Tests\Classes\ParameterTypesClass;
|
|
use Tests\Aspects\TrackingAspect;
|
|
|
|
final class ParameterTypesTest extends TestCase
|
|
{
|
|
private ParameterTypesClass $instance;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->instance = new ParameterTypesClass();
|
|
TrackingAspect::clearCalls();
|
|
}
|
|
|
|
public function testNullableParameter(): void
|
|
{
|
|
$result = $this->instance->withNullable('test');
|
|
$this->assertEquals('test', $result);
|
|
$this->assertCount(2, TrackingAspect::$calls);
|
|
|
|
TrackingAspect::clearCalls();
|
|
$result = $this->instance->withNullable(null);
|
|
$this->assertNull($result);
|
|
$this->assertCount(2, TrackingAspect::$calls);
|
|
}
|
|
|
|
public function testVariadicParameters(): void
|
|
{
|
|
$result = $this->instance->withVariadic('a', 'b', 'c');
|
|
$this->assertEquals(['a', 'b', 'c'], $result);
|
|
|
|
$result = $this->instance->withVariadic();
|
|
$this->assertEquals([], $result);
|
|
}
|
|
|
|
public function testReferenceParameter(): void
|
|
{
|
|
$counter = 5;
|
|
$this->instance->withReference($counter);
|
|
$this->assertEquals(6, $counter);
|
|
}
|
|
|
|
public function testUnionType(): void
|
|
{
|
|
$result = $this->instance->withUnionType(42);
|
|
$this->assertEquals(42, $result);
|
|
|
|
$result = $this->instance->withUnionType('hello');
|
|
$this->assertEquals('hello', $result);
|
|
}
|
|
|
|
public function testMixedType(): void
|
|
{
|
|
$result = $this->instance->withMixed(['key' => 'value']);
|
|
$this->assertEquals(['key' => 'value'], $result);
|
|
|
|
$result = $this->instance->withMixed('string');
|
|
$this->assertEquals('string', $result);
|
|
|
|
$result = $this->instance->withMixed(null);
|
|
$this->assertNull($result);
|
|
}
|
|
|
|
public function testArrayParameter(): void
|
|
{
|
|
$result = $this->instance->withArray(['original' => true]);
|
|
$this->assertEquals(['original' => true, 'processed' => true], $result);
|
|
}
|
|
|
|
public function testDefaultValues(): void
|
|
{
|
|
$result = $this->instance->withDefaultValues();
|
|
$this->assertEquals('default:0', $result);
|
|
|
|
$result = $this->instance->withDefaultValues('John', 25);
|
|
$this->assertEquals('John:25', $result);
|
|
|
|
$result = $this->instance->withDefaultValues('Jane');
|
|
$this->assertEquals('Jane:0', $result);
|
|
}
|
|
|
|
public function testVoidReturnType(): void
|
|
{
|
|
$this->instance->voidReturn();
|
|
$this->assertCount(2, TrackingAspect::$calls);
|
|
$this->assertEquals('before', TrackingAspect::$calls[0]['event']);
|
|
$this->assertEquals('after', TrackingAspect::$calls[1]['event']);
|
|
$this->assertNull(TrackingAspect::$calls[1]['result']);
|
|
}
|
|
|
|
public function testProtectedMethod(): void
|
|
{
|
|
$result = $this->instance->callProtected('hello');
|
|
$this->assertEquals('HELLO', $result);
|
|
}
|
|
}
|