<?php
namespace App\Tests\Unit\Service\Utils\Parser;

use App\Service\Utils\Parser\YamlParser;
use PHPUnit\Framework\TestCase;

class YamlParserTest extends TestCase
{
    public const FIXTURES = __DIR__.'/fixtures';

    /**
     * @see YamlParser::yamlParser()
     */
    public function testParse():void
    {
        $parser = new YamlParser();
        $parsingArray = $parser->parse("
opentalent:
    modulesbyconditions:
        CotisationCall:
            roles:
                - ROLE_COTISATION
            conditions:
                service:
                    name: opentalent.cotisation.utils
                    function: isLastParentAndCMF");
        $this->assertIsArray($parsingArray);
        $this->assertIsArray($parsingArray['opentalent']);
        $this->assertEquals('ROLE_COTISATION', $parsingArray['opentalent']['modulesbyconditions']['CotisationCall']['roles'][0]);
    }

    /**
     * @see YamlParser::yamlParser()
     */
    public function testParseFile():void
    {
        $parser = new YamlParser();
        $parsingArray = $parser->parseFile(self::FIXTURES . '/fixture.yaml');
        $this->assertIsArray($parsingArray);
        $this->assertIsArray($parsingArray['opentalent']);
        $this->assertEquals('ROLE_COTISATION', $parsingArray['opentalent']['modulesbyconditions']['CotisationCall']['roles'][0]);
    }
}
