<?php


namespace TheCodingMachine\Discovery;

class DiscoveryTest extends \PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        parent::setUp();
        // Let's load the autogenerated class for the unit tests.
        require_once __DIR__.'/../.discovery/Discovery.php';
    }

    public function testSingleton()
    {
        $this->assertSame(Discovery::getInstance(), Discovery::getInstance());
    }

    public function testValues()
    {
        $result = Discovery::getInstance()->get('test-asset');

        $this->assertSame([ 'a1', 'a2', 'b' ], $result);
    }

    public function testEmptyValues()
    {
        $result = Discovery::getInstance()->get('not-exist');

        $this->assertSame([], $result);
    }

    public function testAssetType()
    {
        $result = Discovery::getInstance()->getAssetType('test-asset');

        $this->assertSame('a1', $result->getAssets()[0]->getValue());
        $this->assertSame('package/a', $result->getAssets()[0]->getPackage());
        $this->assertSame('vendor/package/a/', $result->getAssets()[0]->getPackageDir());
    }

    public function testEmptyAssetType()
    {
        $result = Discovery::getInstance()->getAssetType('not-exist');

        $this->assertSame([], $result->getAssets());
    }

    public function testLocalDiscoveryJsonDetection()
    {
        $result = Discovery::getInstance()->getAssetType('local');

        $this->assertSame('local', $result->getAssets()[0]->getValue());
    }

}
