<commit_before><?php

namespace Tonik\Gin\Asset;

use Mockery;
use TestCase;
use Tonik\Gin\Asset\Asset;
use Brain\Monkey\Functions;
use phpmock\phpunit\PHPMock;
use Tonik\Gin\Foundation\Config;
use Tonik\Gin\Foundation\Exception\FileNotFoundException;

class AssetTest extends TestCase
{
    use PHPMock;

    /**
     * @test
     */
    public function test_file_setter_and_getter()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $this->assertEquals($asset->getFile(), 'js/sample-asset.js');
    }

    /**
     * @test
     */
    public function test_relative_path_getter()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $config->shouldReceive('offsetGet')
            ->with('directories')
            ->andReturn(['public' => 'public']);

        $this->assertEquals($asset->getRelativePath(), 'public/js/sample-asset.js');
    }

    /**
     * @test
     */
    public function test_public_path_getter()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $config->shouldReceive('offsetGet')
            ->with('paths')
            ->andReturn(['directory' => 'abs/path']);

        $config->shouldReceive('offsetGet')
            ->with('directories')
            ->andReturn(['public' => 'public']);

        $this->assertEquals($asset->getPublicPath(), 'abs/path/public/js/sample-asset.js');
    }

    /**
     * @test
     */
    public function test_public_uri_getter()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $config->shouldReceive('offsetGet')
            ->with('paths')
            ->andReturn(['uri' => 'uri/path']);

        $config->shouldReceive('offsetGet')
            ->with('directories')
            ->andReturn(['public' => 'public']);

        $this->assertEquals($asset->getPublicUri(), 'uri/path/public/js/sample-asset.js');
    }

    /**
     * @test
     */
    public function test_uri_getter()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $exists = $this->getFunctionMock(__NAMESPACE__, "file_exists");
        $exists->expects($this->once())->willReturn(true);

        $config->shouldReceive('offsetGet')
            ->with('paths')
            ->andReturn([
                'directory' => 'abs/path',
                'uri' => 'uri/path'
            ]);

        $config->shouldReceive('offsetGet')
            ->with('directories')
            ->andReturn(['public' => 'public']);

        $this->assertEquals($asset->getUri(), 'uri/path/public/js/sample-asset.js');
    }

    /**
     * @test
     */
    public function it_should_throw_on_file_if_no_asset_file()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $config->shouldReceive('offsetGet')
            ->with('paths')
            ->andReturn(['directory' => 'abs/path']);

        $config->shouldReceive('offsetGet')
            ->with('directories')
            ->andReturn(['public' => 'public']);

        $this->expectException(FileNotFoundException::class);

        $asset->getUri();
    }

    public function getConfig()
    {
        return Mockery::mock(Config::class, [
            'paths' => [
                'uri' => 'uri/path',
            ],
            'directories' => [
                'assets' => 'resources/assets'
            ]
        ]);
    }

    public function getAsset($config, $name)
    {
        return (new Asset($config))->setFile($name);
    }
}<commit_msg>Do not mock out Config class in AssetTest<commit_after><?php

namespace Tonik\Gin\Asset;

use Mockery;
use TestCase;
use Tonik\Gin\Asset\Asset;
use Brain\Monkey\Functions;
use phpmock\phpunit\PHPMock;
use Tonik\Gin\Foundation\Config;
use Tonik\Gin\Foundation\Exception\FileNotFoundException;

class AssetTest extends TestCase
{
    use PHPMock;

    /**
     * @test
     */
    public function test_file_setter_and_getter()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $this->assertEquals($asset->getFile(), 'js/sample-asset.js');
    }

    /**
     * @test
     */
    public function test_relative_path_getter()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $this->assertEquals($asset->getRelativePath(), 'public/js/sample-asset.js');
    }

    /**
     * @test
     */
    public function test_public_path_getter()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $this->assertEquals($asset->getPublicPath(), 'abs/path/public/js/sample-asset.js');
    }

    /**
     * @test
     */
    public function test_public_uri_getter()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $this->assertEquals($asset->getPublicUri(), 'uri/path/public/js/sample-asset.js');
    }

    /**
     * @test
     */
    public function test_uri_getter()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $exists = $this->getFunctionMock(__NAMESPACE__, "file_exists");
        $exists->expects($this->once())->willReturn(true);

        $this->assertEquals($asset->getUri(), 'uri/path/public/js/sample-asset.js');
    }

    /**
     * @test
     */
    public function it_should_throw_on_file_if_no_asset_file()
    {
        $config = $this->getConfig();
        $asset = $this->getAsset($config, 'js/sample-asset.js');

        $this->expectException(FileNotFoundException::class);

        $asset->getUri();
    }

    public function getConfig()
    {
        return new Config([
            'paths' => [
                'uri' => 'uri/path',
                'directory' => 'abs/path',
            ],
            'directories' => [
                'assets' => 'resources/assets',
                'public' => 'public',
            ]
        ]);
    }

    public function getAsset($config, $name)
    {
        return (new Asset($config))->setFile($name);
    }
}
{'fraction_non_alphanumeric': 0.17697295587537562, 'fraction_numerical': 0.0, 'mean_word_length': 2.223241590214067, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 108, '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': '2109662', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1910, 'n_words': 273}