<commit_before><?php

namespace Tests\Concerns;

use PHPUnit\Framework\Assert;

class ArtisanResult
{
    private $output;
    private $status;
    private $parameters;

    public function __construct($parameters, $output, $status)
    {
        $this->output = $output;
        $this->status = $status;
        $this->parameters = $parameters;
    }

    public function assertStatus($expected)
    {
        Assert::assertEquals($expected, $this->status);
    }

    public function assertStepOutput($expectedLines)
    {
        foreach ($this->stepLines() as $index => $actualLine) {
            Assert::assertEquals($expectedLines[$index], $actualLine);
        }
    }

    public function dump()
    {
        return tap($this, function () {
            dump("Status: {$this->status}");
            dump("Output:\n{$this->output}");
        });
    }

    public function dumpIfFailed()
    {
        return $this->status === 0 ? $this : $this->dump();
    }

    private function stepLines()
    {
        foreach (explode("\n", $this->output) as $index => $actualLine) {
            if ($actualLine === "" || substr($actualLine, 0, 7) === "PHPUnit") {
                break;
            }

            yield $index => $actualLine;
        }<commit_msg>Fix problem with detecting step lines with failed steps<commit_after><?php

namespace Tests\Concerns;

use PHPUnit\Framework\Assert;

class ArtisanResult
{
    private $output;
    private $status;
    private $parameters;

    public function __construct($parameters, $output, $status)
    {
        $this->output = $output;
        $this->status = $status;
        $this->parameters = $parameters;
    }

    public function assertStatus($expected)
    {
        Assert::assertEquals($expected, $this->status);
    }

    public function assertStepOutput($expectedLines)
    {
        foreach ($this->stepLines() as $index => $actualLine) {
            Assert::assertEquals($expectedLines[$index], $actualLine);
        }
    }

    public function dump()
    {
        return tap($this, function () {
            dump("Status: {$this->status}");
            dump("Output:\n{$this->output}");
        });
    }

    public function dumpIfFailed()
    {
        return $this->status === 0 ? $this : $this->dump();
    }

    private function stepLines()
    {
        foreach (explode("\n", $this->output) as $index => $actualLine) {
            if (substr($actualLine, 0, 1) !== "[") {
                break;
            }

            yield $index => $actualLine;
        }
{'fraction_non_alphanumeric': 0.14775413711583923, 'fraction_numerical': 0.002364066193853428, 'mean_word_length': 2.2426564495530013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '2469498', 'n_tokens_mistral': 717, 'n_tokens_neox': 692, 'n_words': 156}