<commit_before><?php

namespace CanalTP\MediaManager\Test\Strategy;

use CanalTP\MediaManager\Registry;
use CanalTP\MediaManager\Company\Configuration\Builder\ConfigurationBuilder;
use CanalTP\MediaManager\Company\Configuration\Configuration;
use CanalTP\MediaManager\Media\Builder\MediaBuilder;
use CanalTP\MediaManager\Category\Factory\CategoryFactory;
use CanalTP\MediaManager\Category\CategoryType;
use CanalTP\MediaManager\Company\Company;

class NavitiaStrategyTest extends \PHPUnit_Framework_TestCase
{
    private $company = null;
    private $strategy = null;
    private $category = null;
    private $media = null;

    public function setUp()
    {
        $params = array(
            'name' => Registry::get('COMPANY_NAME'),
            'storage' => array(
                'type' => 'filesystem',
                'path' => Registry::get('TMP_DIR'),
            ),
            'strategy' => Registry::get('NAVITIA_STRATEGY_NAME')
        );

        $this->company = new Company();
        $configurationBuilder = new ConfigurationBuilder();
        $mediaBuilder = new MediaBuilder();
        $categoryFactory = new CategoryFactory();

        $this->company->setConfiguration(
            $configurationBuilder->buildConfiguration($params)
        );

        $this->networkCategory = $categoryFactory->create(
            CategoryType::NETWORK
        );
        $this->category = $categoryFactory->create(CategoryType::LINE);
        $this->category->setName(Registry::get('CATEGORY_NAME'));
        $this->category->setId(Registry::get('CATEGORY_NAME'));
        $this->category->setParent($this->networkCategory);

        $this->media = $mediaBuilder->buildMedia(
            Registry::get('/') . Registry::get('SOUND_FILE'),
            $this->company,
            $this->category
        );

        $this->company->setName(Registry::get('COMPANY_NAME'));
        $this->company->addMedia($this->media);
    }

    public function testGeneratePath()
    {
        $path = Registry::get('SIM_RESSOURCE_NAME') . '/';
        $path .= 0 . '/';
        $path .= Registry::get('CATEGORY_NAME') . '/';
        $path .= Registry::get('SOUND_FILENAME');

        $result = $this->company->getStrategy()->generatePath($this->media);

        $this->assertInternalType('string', $result);
        $this->assertEquals(
            $result, $path,
            Registry::get('STRATEGY_PATH')
        );
    }

    public function testFindMedia()
    {
        $this->category->setName(Registry::get('UNKNOWN'));
        $result = $this->company->getStrategy()->findMedia(
            $this->company,
            $this->category,
            Registry::get('SOUND_FILENAME')
        );
        $this->assertEquals(count($result), 1);

        // $this->company->setName('Plop');
        // $result = $this->company->getStrategy()->getMediasPathByCategory(
        //     $this->company,
        //     $this->category
        // );
        // $this->assertEquals(count($result), 0);        
    }

    public function testGetMediasByCategory()
    {
        $medias = $this->company->getMediasByCategory(
            $this->category
        );

        foreach ($medias as $media) {
            $this->assertInstanceOf(
                Registry::get('MEDIA_INTERFACE'),<commit_msg>NavitiaStrategyTest updated<commit_after><?php

namespace CanalTP\MediaManager\Test\Strategy;

use CanalTP\MediaManager\Registry;
use CanalTP\MediaManager\Company\Configuration\Builder\ConfigurationBuilder;
use CanalTP\MediaManager\Company\Configuration\Configuration;
use CanalTP\MediaManager\Media\Builder\MediaBuilder;
use CanalTP\MediaManager\Category\Factory\CategoryFactory;
use CanalTP\MediaManager\Category\CategoryType;
use CanalTP\MediaManager\Company\Company;

class NavitiaStrategyTest extends \PHPUnit_Framework_TestCase
{
    private $company = null;
    private $strategy = null;
    private $category = null;
    private $media = null;

    public function setUp()
    {
        $params = array(
            'name' => Registry::get('COMPANY_NAME'),
            'storage' => array(
                'type' => 'filesystem',
                'path' => Registry::get('TMP_DIR'),
            ),
            'strategy' => Registry::get('NAVITIA_STRATEGY_NAME')
        );

        $this->company = new Company();
        $configurationBuilder = new ConfigurationBuilder();
        $mediaBuilder = new MediaBuilder();
        $categoryFactory = new CategoryFactory();

        $this->company->setConfiguration(
            $configurationBuilder->buildConfiguration($params)
        );

        $this->networkCategory = $categoryFactory->create(
            CategoryType::NETWORK
        );
        $this->category = $categoryFactory->create(CategoryType::LINE);
        $this->category->setName(Registry::get('CATEGORY_NAME'));
        $this->category->setId(Registry::get('CATEGORY_NAME'));
        $this->category->setParent($this->networkCategory);

        $this->media = $mediaBuilder->buildMedia(
            Registry::get('/') . Registry::get('SOUND_FILE'),
            $this->company,
            $this->category
        );

        $this->company->setName(Registry::get('COMPANY_NAME'));
        $this->company->addMedia($this->media);
    }

    public function testGeneratePath()
    {
        $path = Registry::get('SIM_RESSOURCE_NAME') . '/';
        $path .= 0 . '/';
        $path .= Registry::get('CATEGORY_NAME') . '/';
        $path .= Registry::get('SOUND_FILENAME');

        $result = $this->company->getStrategy()->generatePath($this->media);

        $this->assertInternalType('string', $result);
        $this->assertEquals(
            $result, $path,
            Registry::get('STRATEGY_PATH')
        );
    }

    public function testFindMedia()
    {
        $this->category->setName(Registry::get('UNKNOWN'));
        $result = $this->company->getStrategy()->findMedia(
            $this->company,
            $this->category,
            Registry::get('SOUND_FILENAME')
        );
        $this->assertEquals(count($result), 1);
    }

    public function testGetMediasByCategory()
    {
        $medias = $this->company->getMediasByCategory(
            $this->category
        );

        foreach ($medias as $media) {
            $this->assertInstanceOf(
                Registry::get('MEDIA_INTERFACE'),
{'fraction_non_alphanumeric': 0.14921837991473236, 'fraction_numerical': 0.0007895152376440866, 'mean_word_length': 2.602957906712173, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3418143', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1702, 'n_words': 247}