Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove parsing, selector logic from the trait; introduce custom constraints #46

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

stevegrunwell
Copy link
Owner

In preparation for version 2.x of this library, this PR introduces a series of custom PHPUnit constraints (based on PHPUnit\Framework\Constraint\Constraint), enabling greater flexibility with regards to how assertions are handled.

For example, assertContainsSelector() currently relies on counting the number of matches:

$this->assertGreaterThan(0, count($results), $message);

When the assertion fails, users see a message like "Failed asserting that 0 is greater than 0", which isn't particularly helpful.

With the new version, we can get messages like this:

Failed asserting that '

This is unexpected

' contains selector '.outer .expected'.

The new constraints also make code much easier to test and re-use across assertions.

The Selector class

Rather than having a series of internal methods end up exposed on implementing test classes, this PR uses a new Selector class, which acts as a value object for CSS selectors. If given an array of attributes, this is automatically converted into the appropriate CSS selector.

The DOM class

This PR also defines the DOM class, which is a simple wrapper around Symfony's Crawler class that exposes the methods necessary to query using Selector objects.

Backwards compatibility

In order to be compatible with current versions of PHPUnit, this PR does raise the minimum PHP version to 7.0. While I want to keep support as broad as possible (after all, this originally started because I had to try to write some regression tests around WordPress), the fact that version 1.x is still available for those poor, unlucky souls means they aren't totally left out in the cold.

@coveralls
Copy link

coveralls commented Dec 11, 2023

Coverage Status

coverage: 100.0%. remained the same
when pulling f85fca4 on refactor/remove-logic-from-trait
into 62cfbb1 on develop.

@stevegrunwell stevegrunwell changed the title Refactor/remove logic from trait Remove parsing, selector logic from the trait; introduce custom constraints Dec 11, 2023
@stevegrunwell stevegrunwell force-pushed the refactor/remove-logic-from-trait branch from d0b13e8 to 705a1a6 Compare December 12, 2023 01:08
@stevegrunwell stevegrunwell added this to the Version 2.0.0 milestone Dec 12, 2023
@stevegrunwell stevegrunwell force-pushed the refactor/remove-logic-from-trait branch from 705a1a6 to 8dbabbc Compare December 12, 2023 01:19
@stevegrunwell stevegrunwell force-pushed the refactor/remove-logic-from-trait branch 2 times, most recently from d0dfc60 to 895c8d0 Compare December 12, 2023 01:53
@stevegrunwell stevegrunwell force-pushed the refactor/remove-logic-from-trait branch 2 times, most recently from 0d6a9cd to f85fca4 Compare December 12, 2023 03:11
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