<commit_before><?php namespace Arcanedev\LogViewer\Tests;

use Arcanedev\LogViewer\Entities\Log;
use Arcanedev\LogViewer\LogViewerServiceProvider;
use Psr\Log\LogLevel;
use ReflectionClass;

/**
 * Class AbstractTestCase
 * @package Arcanedev\LogViewer\Tests
 */
abstract class TestCase extends \Orchestra\Testbench\TestCase
{
    /* ------------------------------------------------------------------------------------------------
     |  Bench Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Get package providers.
     *
     * @param  \Illuminate\Foundation\Application  $app
     *
     * @return array
     */
    protected function getPackageProviders($app)
    {
        return [
            LogViewerServiceProvider::class
        ];
    }

    /**
     * Get package aliases.
     *
     * @param  \Illuminate\Foundation\Application  $app
     *
     * @return array
     */
    protected function getPackageAliases($app)
    {
        return [
        ];
    }

    /**
     * Define environment setup.
     *
     * @param  \Illuminate\Foundation\Application  $app
     */
    protected function getEnvironmentSetUp($app)
    {
        $app['path.storage'] = __DIR__ . '/fixtures';
    }

    /* ------------------------------------------------------------------------------------------------
     |  Custom assertions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Assert log entry
     *
     * @param  array   $entry
     * @param  string  $date
     */
    protected function assertLogEntry(array $entry, $date)
    {
        $this->assertArrayHasKey('level', $entry);
        $this->assertContains($entry['level'], $this->getLogLevels());

        $this->assertArrayHasKey('header', $entry);
        $this->assertNotEmpty($entry['header']);
        $this->assertStringStartsWith('[' . $date, $entry['header']);

        $this->assertArrayHasKey('stack', $entry);
        $this->assertNotEmpty($entry['stack']);
    }

    /* ------------------------------------------------------------------------------------------------
     |  Other Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Get filesystem utility
     *
     * @return \Arcanedev\LogViewer\Utilities\Filesystem
     */
    protected function getFilesystem()
    {
        return $this->app['log-viewer.filesystem'];
    }

    /**
     * Get log levels
     *
     * @return array
     */
    public function getLogLevels()
    {
        $class = new ReflectionClass(new LogLevel);

        return $class->getConstants();
    }

    /**
     * Get a log entries
     *
     * @param  string  $date
     * @param  string  $level
     *
     * @return Log
     *
     * @throws \Arcanedev\LogViewer\Exceptions\FilesystemException
     */
    protected function getLog($date, $level = 'all')
    {
        $raw = $this->getFilesystem()->read($date);

        return new Log($raw, $this->getLogLevels(), $level);
    }

    /**
     * Create dummy log
     *
     * @param  string  $date
     *
     * @return bool
     */
    protected function createDummyLog($date)
    {
        $fixtures    = __DIR__ . '/fixtures';
        $source      = $fixtures . '/dummy.log';
        $destination = $fixtures . "/logs/laravel-{$date}.log";

        return copy($source, $destination);
    }
}<commit_msg>Updating the base TestCase class<commit_after><?php namespace Arcanedev\LogViewer\Tests;

use Arcanedev\LogViewer\Entities\EntryCollection;
use Arcanedev\LogViewer\Entities\LogEntry;
use Arcanedev\LogViewer\LogViewerServiceProvider;
use Carbon\Carbon;
use Psr\Log\LogLevel;
use ReflectionClass;

/**
 * Class AbstractTestCase
 * @package Arcanedev\LogViewer\Tests
 */
abstract class TestCase extends \Orchestra\Testbench\TestCase
{
    /* ------------------------------------------------------------------------------------------------
     |  Bench Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Get package providers.
     *
     * @param  \Illuminate\Foundation\Application  $app
     *
     * @return array
     */
    protected function getPackageProviders($app)
    {
        return [
            LogViewerServiceProvider::class
        ];
    }

    /**
     * Get package aliases.
     *
     * @param  \Illuminate\Foundation\Application  $app
     *
     * @return array
     */
    protected function getPackageAliases($app)
    {
        return [
        ];
    }

    /**
     * Define environment setup.
     *
     * @param  \Illuminate\Foundation\Application  $app
     */
    protected function getEnvironmentSetUp($app)
    {
        $app['path.storage'] = __DIR__ . '/fixtures';
    }

    /* ------------------------------------------------------------------------------------------------
     |  Custom assertions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Assert Log entries
     *
     * @param EntryCollection $entries
     * @param string          $date
     */
    protected function assertLogEntries(EntryCollection $entries, $date)
    {
        foreach ($entries as $entry) {
            $this->assertLogEntry($entry, $date);
        }
    }

    /**
     * Assert log entry
     *
     * @param  LogEntry $entry
     * @param  string  $date
     */
    protected function assertLogEntry(LogEntry $entry, $date)
    {
        $dt = Carbon::createFromFormat('Y-m-d', $date);

        $this->assertContains($entry->level, $this->getLogLevels());
        $this->assertNotEmpty($entry->header);
        $this->assertInstanceOf(Carbon::class, $entry->datetime);
        $this->assertTrue($entry->datetime->isSameDay($dt));
        $this->assertNotEmpty($entry->stack);
    }

    /**
     * Assert dates
     *
     * @param  array   $dates
     * @param  string  $message
     */
    public function assertDates(array $dates, $message = '')
    {
        foreach ($dates as $date) {
            $this->assertDate($date, $message);
        }
    }

    /**
     * Assert date [yyyy-mm-dd]
     *
     * @param  string  $date
     * @param  string  $message
     */
    public function assertDate($date, $message = '')
    {
        $this->assertRegExp('/' . REGEX_DATE_PATTERN . '/', $date, $message);
    }

    /* ------------------------------------------------------------------------------------------------
     |  Other Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Get filesystem utility
     *
     * @return \Arcanedev\LogViewer\Utilities\Filesystem
     */
    protected function getFilesystem()
    {
        return $this->app['log-viewer.filesystem'];
    }

    /**
     * Get log levels
     *
     * @return array
     */
    public function getLogLevels()
    {
        $class = new ReflectionClass(new LogLevel);

        return $class->getConstants();
    }

    /**
     * Create dummy log
     *
     * @param  string  $date
     *
     * @return bool
     */
    protected function createDummyLog($date)
    {
        $fixtures    = __DIR__ . '/fixtures';
        $source      = $fixtures . '/dummy.log';
        $destination = $fixtures . "/logs/laravel-{$date}.log";

        return copy($source, $destination);
    }
}
{'fraction_non_alphanumeric': 0.26620799153215136, 'fraction_numerical': 0.0, 'mean_word_length': 1.2823067632850242, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '4582137', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1958, 'n_words': 361}