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 objectHasProperty assertions #57

Merged
merged 6 commits into from
Feb 4, 2024

Conversation

particleflux
Copy link
Contributor

With phpunit 10.x, assertObjectHasAttribute is deprecated in favor of assertObjectHasProperty

This adds the new alternatives.

See sebastianbergmann/phpunit#4601

@@ -46,4 +46,30 @@ public function notHasAttribute(string $attributeName, string $message = ''): se
Assert::assertObjectNotHasAttribute($attributeName, $this->actual, $message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add @deprecated Deprecated in favour of hasProperty annotation to hasAttribute and hasAttribute.

To keep these old methods working, they could be updated to call Assert::assertObjectHasProperty and Assert::assertObjectNotHasProperty accordingly, right?

The lowest supported version of phpunit could be set to ^9.6.11

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in theory, the old methods could call the new ones, or directly the new phpunit assertions.

That might be an idea for a temporary solution until the old ones are dropped completely.

I actually thought to keep them around since this library supports both 9.x and 10.x of phpunit, otherwise they could probably be dropped completely.

But, since they've been added in 9.6.11, it's probably the best solution to keep the old ones, alias them to the new assertions, and raise the minimum 9.x version, as you suggested. That wouldn't require a BC release.

Will update accordingly

@@ -23,6 +23,8 @@ toHaveSameSizeAs
```
notToHaveAttribute
toHaveAttribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mark old method as deprecated or remove them completely.

By the way, link to docs dir in README.md are broken.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting.. technically, the links should work starting with /, github docs specifically say those are relative to the repository root. Yet, they are not.

Maybe it's a special case for /docs, since that also houses github docs itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the attribute assertions from the expectations and verifier docs, and attempted a fix at the README... the README links now should work, yet I am unable to test it since if I render it on my branch, it's relative to the /tree/ url.

Version 9.6.11 had the new asssertObjectHasProperty method added, which
completely replace the assertObjectHasAttribute ones in phpunit 10.x
In theory, github markdown docs say that:

> Links starting with / will be relative to the repository root.

Yet, they are resolved to be relative to the github.com domain. Maybe
it's a special case with the `/docs` , since that also references the
actual github docs.

Changed them to explicit relative links.
@icanhazstring
Copy link
Contributor

Can we get this merged? :)
Just now stumbled upon that problem to not being able the check for properties.

@Naktibalda Naktibalda merged commit f19c34e into Codeception:master Feb 4, 2024
@particleflux particleflux deleted the add-objecthas-property branch February 4, 2024 19:18
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.

3 participants