First set of tests, argument unwrapping/injection
This commit is contained in:
		
							
								
								
									
										40
									
								
								tests/ContextTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								tests/ContextTest.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
<?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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user