40 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace NoccyLabs\React\CommandBus;
 | 
						|
 | 
						|
use PHPUnit\Framework\Attributes\CoversClass;
 | 
						|
 | 
						|
#[CoversClass(Context::class)]
 | 
						|
class ContextTest extends \PHPUnit\Framework\TestCase
 | 
						|
{
 | 
						|
 | 
						|
    public function testContextPropertyAccess()
 | 
						|
    {
 | 
						|
        $context = new Context("", [ 'foo'=>true, 'bar'=>'hello' ]);
 | 
						|
 | 
						|
        $this->assertEquals(true, $context->foo);
 | 
						|
        $this->assertEquals('hello', $context->bar);
 | 
						|
    }
 | 
						|
 | 
						|
    public function testMakingParameters()
 | 
						|
    {
 | 
						|
        $func1 = function () {};
 | 
						|
        $func2 = function (Context $context) {};
 | 
						|
        $func3 = function ($a, ?int $b, ?string $c, $d) {};
 | 
						|
 | 
						|
        $context = new Context("", [ 'a'=>true, 'b'=>42, 'c'=>'hello' ]);
 | 
						|
 | 
						|
        $expect1 = [];
 | 
						|
        $expect2 = [$context];
 | 
						|
        $expect3 = [true,42,'hello',null];
 | 
						|
 | 
						|
        $args1 = $context->toMethodParameters($func1);
 | 
						|
        $this->assertEquals($expect1, $args1);
 | 
						|
 | 
						|
        $args2 = $context->toMethodParameters($func2);
 | 
						|
        $this->assertEquals($expect2, $args2);
 | 
						|
 | 
						|
        $args3 = $context->toMethodParameters($func3);
 | 
						|
        $this->assertEquals($expect3, $args3);
 | 
						|
    }
 | 
						|
} |