<commit_before><?php

namespace Illuminated\Testing\Asserts;

use Illuminate\Console\Scheduling\Event;
use Illuminate\Console\Scheduling\Schedule;

trait ScheduleAsserts
{
    protected function seeScheduleCount($count)
    {
        $message = "Failed asserting that schedule events count is {$count}.";
        $this->assertCount($count, app(Schedule::class)->events(), $message);
    }

    protected function dontSeeScheduleCount($count)
    {
        $message = "Failed asserting that schedule events count is not {$count}.";
        $this->assertNotCount($count, app(Schedule::class)->events(), $message);
    }

    protected function seeInSchedule($command, $expression, $runInBackground = false)
    {
        $event = $this->getScheduleEvent($command);

        $message = "Failed asserting that command `{$command}` is in schedule.";
        $this->assertNotEmpty($event, $message);
        $this->assertInstanceOf(Event::class, $event, $message);

        $message = "Failed asserting that command `{$command}` is in schedule as `{$expression}`.";
        $expression = $this->normalizeScheduleExpression($expression);
        $this->assertEquals($expression, $event->expression, $message);

        $message = "Failed asserting that command `{$command}` is scheduled with the same `run in background` mode.";
        $this->assertEquals($runInBackground, $event->runInBackground, $message);
    }

    protected function dontSeeInSchedule($command)
    {
        $message = "Failed asserting that command `{$command}` is not in schedule.";
        $this->assertEmpty($this->getScheduleEvent($command), $message);
    }

    private function getScheduleEvent($command)
    {
        $schedule = app(Schedule::class);

        foreach ($schedule->events() as $event) {
            if (ends_with($event->command, $command)) {
                return $event;
            }
        }

        return false;
    }

    private function normalizeScheduleExpression($expression)
    {
        $event = new Event('command');
        if (method_exists($event, $expression)) {
            $event->$expression();
            return $event->getExpression();
        }

        return $expression;<commit_msg>ITT: Laravel 5.4 support added.<commit_after><?php

namespace Illuminated\Testing\Asserts;

use Illuminate\Console\Scheduling\Event;
use Illuminate\Console\Scheduling\Schedule;

trait ScheduleAsserts
{
    protected function seeScheduleCount($count)
    {
        $message = "Failed asserting that schedule events count is {$count}.";
        $this->assertCount($count, app(Schedule::class)->events(), $message);
    }

    protected function dontSeeScheduleCount($count)
    {
        $message = "Failed asserting that schedule events count is not {$count}.";
        $this->assertNotCount($count, app(Schedule::class)->events(), $message);
    }

    protected function seeInSchedule($command, $expression, $runInBackground = false)
    {
        $event = $this->getScheduleEvent($command);

        $message = "Failed asserting that command `{$command}` is in schedule.";
        $this->assertNotEmpty($event, $message);
        $this->assertInstanceOf(Event::class, $event, $message);

        $message = "Failed asserting that command `{$command}` is in schedule as `{$expression}`.";
        $expression = $this->normalizeScheduleExpression(clone $event, $expression);
        $this->assertEquals($expression, $event->expression, $message);

        $message = "Failed asserting that command `{$command}` is scheduled with the same `run in background` mode.";
        $this->assertEquals($runInBackground, $event->runInBackground, $message);
    }

    protected function dontSeeInSchedule($command)
    {
        $message = "Failed asserting that command `{$command}` is not in schedule.";
        $this->assertEmpty($this->getScheduleEvent($command), $message);
    }

    private function getScheduleEvent($command)
    {
        $schedule = app(Schedule::class);

        foreach ($schedule->events() as $event) {
            if (ends_with($event->command, $command)) {
                return $event;
            }
        }

        return false;
    }

    private function normalizeScheduleExpression(Event $event, $expression)
    {
        if (method_exists($event, $expression)) {
            $event->$expression();
            return $event->getExpression();
        }

        return $expression;
{'fraction_non_alphanumeric': 0.13435874236598055, 'fraction_numerical': 0.00045238633793259444, 'mean_word_length': 3.167766258246937, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '498532', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1123, 'n_words': 286}