mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 09:54:17 +02:00
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace Demostf\API\Test\Providers;
|
|
|
|
use Demostf\API\Demo\Parser;
|
|
use Demostf\API\Demo\RawParser;
|
|
use Demostf\API\Test\TestCase;
|
|
|
|
class ParserTest extends TestCase {
|
|
/** @var RawParser|\PHPUnit_Framework_MockObject_MockObject */
|
|
private $rawParser;
|
|
|
|
public function setUp() {
|
|
parent::setUp();
|
|
|
|
$this->rawParser = $this->getMockBuilder(RawParser::class)
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$this->rawParser->expects($this->any())
|
|
->method('parse')
|
|
->will($this->returnCallback(function ($path) {
|
|
$jsonPath = str_replace('.dem', '-raw.json', $path);
|
|
return json_decode(file_get_contents($jsonPath), true);
|
|
}));
|
|
}
|
|
|
|
public function testAnalyse() {
|
|
$parser = new Parser($this->rawParser);
|
|
|
|
$result = $parser->analyse(__DIR__ . '/../data/product.dem');
|
|
|
|
$expected = json_decode(file_get_contents(__DIR__ . '/../data/product-analyse.json'), true);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
}
|
|
|
|
/**
|
|
* @expectedException \InvalidArgumentException
|
|
*/
|
|
public function testFailedParse() {
|
|
/** @var RawParser|\PHPUnit_Framework_MockObject_MockObject $rawParser */
|
|
$rawParser = $this->getMockBuilder(RawParser::class)
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$parser = new Parser($rawParser);
|
|
|
|
$rawParser->expects($this->any())
|
|
->method('parse')
|
|
->willReturn(null);
|
|
|
|
$parser->analyse('foo');
|
|
}
|
|
}
|