<commit_before><?php

namespace Recca0120\Terminal\Tests\Console\Commands;

use Mockery as m;
use Webmozart\Glob\Glob;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Recca0120\Terminal\Console\Commands\Tail;
use Symfony\Component\Console\Output\BufferedOutput;

class TailTest extends TestCase
{
    protected function setUp()
    {
        parent::setUp();
        $structure = [
            'logs' => [
                '1.log' => '
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                ',
                '2.log' => '
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                ',
                '3.log' => '
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                ',
                '4.log' => '
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                ',
                '5.log' => '
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                ',
            ],
        ];
        $this->root = vfsStream::setup('root', null, $structure);
        $container = m::mock(new Container);
        $container->shouldReceive('basePath')->andReturn($this->root->url());
        $container->instance('path.storage', $this->root->url());
        Container::setInstance($container);
    }

    protected function tearDown()
    {
        parent::tearDown();
        m::close();
    }

    public function testFire()
    {
        $command = new Tail(
            $files = m::mock(new Filesystem)
        );
        $this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
        $this->mockProperty($command, 'output', $output = new BufferedOutput);

        $input->shouldReceive('getArgument')->once()->with('path')->andReturn(null);
        $input->shouldReceive('getOption')->once()->with('lines')->andReturn($lines = 5);
        $command->setLaravel(
            $laravel = m::mock('Illuminate\Contracts\Foundation\Application')
        );
        $storagePath = $this->root->url();
        $files->shouldReceive('glob')->once()->with($storagePath.'/logs/*.log')->andReturnUsing(function ($path) {
            return Glob::glob($path);
        });

        $command->fire();

        $this->assertContains('1.log', $output->fetch());
    }

    public function testFirePath()
    {
        $command = new Tail(
            $files = m::mock('Illuminate\Filesystem\Filesystem')
        );
        $this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
        $this->mockProperty($command, 'output', $output = new BufferedOutput);

        $command->setLaravel(
            $laravel = m::mock('Illuminate\Contracts\Foundation\Application')
        );

        $input->shouldReceive('getArgument')->once()->with('path')->andReturn($path = 'logs/5.log');
        $input->shouldReceive('getOption')->once()->with('lines')->andReturn($lines = 5);

        $command->fire();

        $this->assertContains('5.log', $output->fetch());
    }

    protected function mockProperty($object, $propertyName, $value)
    {
        $reflectionClass = new \ReflectionClass($object);

        $property = $reflectionClass->getProperty($propertyName);
        $property->setAccessible(true);
        $property->setValue($object, $value);
        $property->setAccessible(false);
    }
}<commit_msg>filemtime<commit_after><?php

namespace Recca0120\Terminal\Tests\Console\Commands;

use Mockery as m;
use Webmozart\Glob\Glob;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Recca0120\Terminal\Console\Commands\Tail;
use Symfony\Component\Console\Output\BufferedOutput;

class TailTest extends TestCase
{
    protected function setUp()
    {
        parent::setUp();
        $structure = [
            'logs' => [
                '1.log' => '
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                    1.log
                ',
                '2.log' => '
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                    2.log
                ',
                '3.log' => '
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                    3.log
                ',
                '4.log' => '
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                    4.log
                ',
                '5.log' => '
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                    5.log
                ',
            ],
        ];
        $this->root = vfsStream::setup('root', null, $structure);
        $i = 0;
        foreach ($structure as $directory => $files) {
            foreach ($files as $file => $content) {
                $this->root->getChild($directory.'/'.$file)->lastAttributeModified(time() + $i);
                $i++;
            }
        }

        $container = m::mock(new Container);
        $container->shouldReceive('basePath')->andReturn($this->root->url());
        $container->instance('path.storage', $this->root->url());
        Container::setInstance($container);
    }

    protected function tearDown()
    {
        parent::tearDown();
        m::close();
    }

    public function testFire()
    {
        $command = new Tail(
            $files = m::mock(new Filesystem)
        );
        $this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
        $this->mockProperty($command, 'output', $output = new BufferedOutput);

        $input->shouldReceive('getArgument')->once()->with('path')->andReturn(null);
        $input->shouldReceive('getOption')->once()->with('lines')->andReturn($lines = 5);
        $command->setLaravel(
            $laravel = m::mock('Illuminate\Contracts\Foundation\Application')
        );
        $storagePath = $this->root->url();
        $files->shouldReceive('glob')->once()->with($storagePath.'/logs/*.log')->andReturnUsing(function ($path) {
            return Glob::glob($path);
        });

        $command->fire();

        $this->assertContains('5.log', $output->fetch());
    }

    public function testFirePath()
    {
        $command = new Tail(
            $files = m::mock('Illuminate\Filesystem\Filesystem')
        );
        $this->mockProperty($command, 'input', $input = m::mock('Symfony\Component\Console\Input\InputInterface'));
        $this->mockProperty($command, 'output', $output = new BufferedOutput);

        $command->setLaravel(
            $laravel = m::mock('Illuminate\Contracts\Foundation\Application')
        );

        $input->shouldReceive('getArgument')->once()->with('path')->andReturn($path = 'logs/1.log');
        $input->shouldReceive('getOption')->once()->with('lines')->andReturn($lines = 5);

        $command->fire();

        $this->assertContains('1.log', $output->fetch());
    }

    protected function mockProperty($object, $propertyName, $value)
    {
        $reflectionClass = new \ReflectionClass($object);

        $property = $reflectionClass->getProperty($propertyName);
        $property->setAccessible(true);
        $property->setValue($object, $value);
        $property->setAccessible(false);
    }
}
{'fraction_non_alphanumeric': 0.13607216606890554, 'fraction_numerical': 0.014889685903706118, 'mean_word_length': 1.2329531667071099, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 112, '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': '2214741', 'n_tokens_mistral': 2503, 'n_tokens_neox': 2358, 'n_words': 367}