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

Subject Inspectors #87

Open
bbatsche opened this issue Oct 3, 2022 · 4 comments
Open

Subject Inspectors #87

bbatsche opened this issue Oct 3, 2022 · 4 comments
Milestone

Comments

@bbatsche
Copy link
Owner

bbatsche commented Oct 3, 2022

Verifier to add assertions about the contents of an array or JSON string. Something like:

verify([1, 2, 3])->arrayContent()->is()->int();

verify('{"name":"George","gpa":3.8}')->jsonContent()
    ->name->is()->identicalTo('George')
    ->gpa->within(0.01)->is()->equalTo(3.8);
@bbatsche
Copy link
Owner Author

bbatsche commented Oct 4, 2022

Use __get() to allow more detailed assertions about individual array elements (if they're assoc)

@bbatsche bbatsche added this to the 3.2.0 milestone Oct 18, 2022
@bbatsche
Copy link
Owner Author

bbatsche commented Aug 5, 2023

Also add fileContent() for strings

@bbatsche bbatsche modified the milestones: 3.2.0, 4.0.0 Aug 15, 2023
@bbatsche
Copy link
Owner Author

Saving this off for 4.0.0 since complex inspectors like this are really going to benefit from multiple levels of chaining

@bbatsche
Copy link
Owner Author

Challenge:

With 4.0.0 we're trying to support deeper inspection of subject through property chaining, but that could interfere with inspecting JSON/array content. Something wild like subject has a user prop, toJson() method, and we want to inspect its structure

Solution

JSON & Array content inspectors accept an optional callback that allows multiple assertions on content. Something like:

verify($subject)->user->toJson()
    ->jsonContent(static function (Verifier $jsonConent): void {
        $jsonContent->first_name->is()->identicalTo('John')
            ->and()->last_name->is()->identicalTo('Smith');
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready
Development

No branches or pull requests

1 participant