public function testShouldMapAnArrayValueToAnotherSchemaSchema()
{
// Arrange
$schema = m::mock(Schema::class);
$mySchema = m::mock(Schema::class);
$schemaMapper = new SchemaMapper($schema);
$value = ['foo' => 'bar'];
$test = $this;
// Act
Ioc::instance('Xd\\MySchema', $mySchema);
// Register MySchema in Ioc
// When instantiating the SchemaMapper with the specified $param as dependency
Ioc::bind(SchemaMapper::class, function ($container, $params) use($value, $mySchema, $test) {
// Check if mySchema has been injected correctly
$test->assertSame($mySchema, $params[0]);
// Instantiate a SchemaMapper with mySchema
$anotherSchemaMapper = m::mock(SchemaMapper::class, [$params[0]]);
// Set expectation to receiva a map call
$anotherSchemaMapper->shouldReceive('map')->once()->with($value)->andReturn(['foo' => 'PARSED']);
return $anotherSchemaMapper;
});
//Assert
$this->assertEquals([['foo' => 'PARSED']], $this->callProtected($schemaMapper, 'mapToSchema', [$value, 'Xd\\MySchema']));
}