Skip to content

Conversation

@jackbayliss
Copy link
Contributor

@jackbayliss jackbayliss commented Oct 6, 2025

I had a thought, if we constantly chained this method it would be nice to cache the parser to save time so it saves the content having to be parsed over and over.

It could be nice doing this for assertElementExists... But I guess people tend to do assertions within the callback.

@jackbayliss jackbayliss marked this pull request as ready for review October 6, 2025 20:03
@sinnbeck
Copy link
Owner

sinnbeck commented Oct 9, 2025

Looks great, but I wonder if this might break in a future PHP version due to that error? Perhaps it would be better to put it in the container? I believe it will flush after each test.

if (! app()->has('dom-assertions.parser')) {
    app()->bind('dom-assertions.parser', DomParser::new($this->getContent()));
}

//and
app()->get('dom-assertions.parser')->query($selector);

Laravel uses the container as well in TestResponse

$session = app('session.store');

@jackbayliss
Copy link
Contributor Author

@sinnbeck I've used the container now, thanks for the suggestion 👍🏻 - not sure if it'll affect things if tests are running in parallel but I'm guessing not!

@sinnbeck sinnbeck merged commit cbb143f into sinnbeck:main Oct 9, 2025
28 checks passed
@sinnbeck
Copy link
Owner

sinnbeck commented Oct 9, 2025

I tested it in parallel and it seems to work as expected :)

Tests: 190 passed (876 assertions)
Duration: 0.37s
Parallel: 22 processes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants