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

Add possibility to check property name and value with toHaveProperties #760

Merged
merged 1 commit into from Apr 2, 2023

Conversation

lucasgiovanny
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
Fixed tickets no

This pull request proposes an enhancement to the existing code that deals with testing the presence and values of properties on an object.

Currently, the toHaveProperty() and toHaveProperties() methods can be used to test for the existence of properties on an object.

expect($object)->toHaveProperty('name');
//or
expect($object)->toHaveProperties(['name', 'age']);

However, to check the value of a property, only toHaveProperty() is available.

expect($object)->toHaveProperty('name', 'Daniel San');

This PR adds the functionality of testing multiple properties and their values using the toHaveProperties() method using an associative array.

expect($object)->toHaveProperties([
     'name' => 'Daniel San',
     'age' => 50,
]);

@lucasgiovanny lucasgiovanny changed the title update toHaveProperties Add possibility to check property name and value with toHaveProperties Apr 2, 2023
@nunomaduro nunomaduro merged commit cab6aa6 into pestphp:2.x Apr 2, 2023
@jameshulse
Copy link

Is it plausible that this feature could be expanded at some stage to architecture testing? The use-case would be asserting that all classes in our "Actions" namespace have a single public execute() method.

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.

None yet

4 participants