<commit_before><?php

use App\Jobs\ReadCsvFile;
use App\Jobs\StartParsingGroupedByUserAgent;
use App\Models\Process;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Maatwebsite\Excel\Excel;

class ReadCsvFileTest extends TestCase
{
    use DatabaseTransactions;

    /** @test */
    public function it_updates_start_at_date_of_given_process()
    {
        $pathToTestFile = base_path('tests/support/ua-test.csv');
        $process        = factory(Process::class)->create();
        $process->addMedia($pathToTestFile)->preservingOriginal()->toCollection('csv-files');
        $carbon  = app()->make(Carbon::class);
        $excel   = app()->make(Excel::class);

        $job = new ReadCsvFile($process);
        $job->handle($carbon, $excel);

        $this->assertTrue(
            Process::whereId($process->id)->where('start_at', '>=', $carbon->now())->exists()
        );
    }

    /** @test */
    public function it_stores_user_agent_in_database()
    {
        $pathToTestFile = base_path('tests/support/ua-test.csv');
        $process        = factory(Process::class)->create();
        $process->addMedia($pathToTestFile)->preservingOriginal()->toCollection('csv-files');
        $carbon         = app()->make(Carbon::class);
        $excel          = app()->make(Excel::class);

        $job = new ReadCsvFile($process);
        $job->handle($carbon, $excel);

        $this->seeInDatabase('user_agents', [
            'process_id' => $process->id,
            'ua_string' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0'
        ]);

    }

    /** @test */
    public function it_dispatches_new_job()
    {
        $this->expectsJobs(StartParsingGroupedByUserAgent::class);

        $process = factory(Process::class)->create();
        $carbon  = app()->make(Carbon::class);
        $excel   = app()->make(Excel::class);

        $job = new ReadCsvFile($process);
        $job->handle($carbon, $excel);
    }
}
<commit_msg>Should Fix ReadCsvFileTest on Travis<commit_after><?php

use App\Jobs\ReadCsvFile;
use App\Jobs\StartParsingGroupedByUserAgent;
use App\Models\Process;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Maatwebsite\Excel\Excel;

class ReadCsvFileTest extends TestCase
{
    use DatabaseTransactions;

    /** @test */
    public function it_updates_start_at_date_of_given_process()
    {
        $pathToTestFile = base_path('tests/support/ua-test.csv');
        $process        = factory(Process::class)->create();
        $process->addMedia($pathToTestFile)->preservingOriginal()->toCollection('csv-files');
        $carbon  = app()->make(Carbon::class);
        $excel   = app()->make(Excel::class);

        $job = new ReadCsvFile($process);
        $job->handle($carbon, $excel);

        $this->assertTrue(
            !is_null(Process::whereId($process->id)->first()->start_at)
        );
    }

    /** @test */
    public function it_stores_user_agent_in_database()
    {
        $pathToTestFile = base_path('tests/support/ua-test.csv');
        $process        = factory(Process::class)->create();
        $process->addMedia($pathToTestFile)->preservingOriginal()->toCollection('csv-files');
        $carbon         = app()->make(Carbon::class);
        $excel          = app()->make(Excel::class);

        $job = new ReadCsvFile($process);
        $job->handle($carbon, $excel);

        $this->seeInDatabase('user_agents', [
            'process_id' => $process->id,
            'ua_string' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0'
        ]);

    }

    /** @test */
    public function it_dispatches_new_job()
    {
        $this->expectsJobs(StartParsingGroupedByUserAgent::class);

        $process = factory(Process::class)->create();
        $carbon  = app()->make(Carbon::class);
        $excel   = app()->make(Excel::class);

        $job = new ReadCsvFile($process);
        $job->handle($carbon, $excel);
    }
}

{'fraction_non_alphanumeric': 0.1608540925266904, 'fraction_numerical': 0.009489916963226572, 'mean_word_length': 3.0460652591170825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '1858081', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1310, 'n_words': 183}