Skip to content

Fix swapped preCondition and postCondition attribute mapping - #746

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-pre-post-condition-swap
Jul 31, 2026
Merged

Fix swapped preCondition and postCondition attribute mapping#746
TomasVotruba merged 1 commit into
mainfrom
fix-pre-post-condition-swap

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

@preCondition was converted to #[PostCondition] and @postCondition to #[PreCondition] - the two mappings are swapped, so the hooks end up running at the wrong point of the test lifecycle.

-        new AnnotationToAttribute('preCondition', 'PHPUnit\Framework\Attributes\PostCondition'),
-        new AnnotationToAttribute('postCondition', 'PHPUnit\Framework\Attributes\PreCondition'),
+        new AnnotationToAttribute('preCondition', 'PHPUnit\Framework\Attributes\PreCondition'),
+        new AnnotationToAttribute('postCondition', 'PHPUnit\Framework\Attributes\PostCondition'),

Before:

/**
 * @preCondition
 */
protected function setUpSomething()
{
}

was turned into:

#[\PHPUnit\Framework\Attributes\PostCondition]
protected function setUpSomething()
{
}

There was no fixture covering these two annotations, which is how the swap went unnoticed. Added pre_post_condition.php.inc.

@TomasVotruba
TomasVotruba merged commit 8746b8a into main Jul 31, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the fix-pre-post-condition-swap branch July 31, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant