<?php
use Symfony\Component\Yaml\Parser;
use PHPUnit\Framework\TestCase;
class MockProxyTest extends TestCase
{
public function testParseStr() : void
{
$str = 'root: ' . PHP_EOL .
' key1: value1' . PHP_EOL .
' key2: value2';
$parser = $this->getMockBuilder(Parser::CLASS)
->enableProxyingToOriginalMethods()
->getMock();
$parser->expects($this->once())
->method('parse');
$val = (new Foo($parser))->parseStr($str);
$this->assertEquals('value1', $val['root']['key1']);
$this->assertEquals('value2', $val['root']['key2']);
}
}
class Foo
{
private $parser;
public function __construct(Parser $parser)
{
$this->parser = $parser;
}
public function parseStr($str)
{
return $this->parser->parse($str);
}
}