Skip to content

Test that propertyNotExists() passes when the property is absent - #369

Merged
shadowhand merged 1 commit into
webmozarts:masterfrom
renanmpimentel:test/property-not-exists-success-case
Oct 5, 2026
Merged

shadowhand merged 1 commit into
webmozarts:masterfrom
renanmpimentel:test/property-not-exists-success-case

Conversation

@renanmpimentel

Copy link
Copy Markdown
Contributor

What changed

Adds one row to AssertTest::getTests():

['propertyNotExists', [(object) ['property' => null], 'foo'], true],

Why

Every existing propertyNotExists row expects a failure (the property exists). No row covers the passing case, where the property is absent. Its siblings cover both sides: propertyExists has passing and failing rows, and methodNotExists has true rows for stdClass.

So a regression that makes propertyNotExists() reject every object goes unnoticed. For example, either of these changes to the condition in Assert::propertyNotExists() leaves the whole suite green:

// A: negation dropped
if (\is_string($classOrObject) || \is_object($classOrObject) || \property_exists($classOrObject, $property)) {
// B: always throws
if (true) {

The new row mirrors the existing propertyExists failing case ('foo' on an object that only has property). Through the shared data provider it also exercises the nullOr*, all* and custom-message variants.

Verification

  • composer run test: 4913 tests, 5830 assertions (was 4906 / 5823)
  • composer run cs-check: 0 files to fix
  • composer run static-analysis: no errors
Suite Correct code Regression A Regression B
Before this PR OK OK (undetected) OK (undetected)
After this PR OK 7 errors (uncaught InvalidArgumentException), all on the new propertyNotExists row same

I found this while experimenting with Supertest, a tool for evaluating test effectiveness using mutation testing and test-harness mutilation.

@shadowhand
shadowhand merged commit 49d59e8 into webmozarts:master Oct 5, 2026
9 checks passed
@shadowhand

Copy link
Copy Markdown
Collaborator

Thanks!

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