spatie / enum

Strongly typed enums in PHP supporting autocompletion and refactoring

Home Page:https://docs.spatie.be/enum/v3/introduction

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHPUnit assertions trait changed to class

gbuckingham89 opened this issue · comments

It seems that this commit changed the trait that provided PHPUnit assertions into an abstract class: 45245a1

I've got a project on PHP 7.4 with spatie/enum v3.10.0. I ran a composer update this morning and was given v3.11.1. I'm now getting a fatal error when running my tests:

PHP Fatal error:  Tests\TestCase cannot use Spatie\Enum\Phpunit\EnumAssertions - it is not a trait in /home/runner/work/example.com/example.com/tests/TestCase.php on line 19

I can obviously refactor my tests to use the static methods on what is now the class - but should this not have been documented as a breaking change and a new major version released?

Ah, I wasn't aware that people were using this trait in such a way, that's my bad.

PHP 8.1 made a change so that calling static methods on traits isn't possible anymore. I'll fix it!

@Gummibeer this is actually a difficult one to fix. We do want to support 8.1 with the current version to allow people for a more smooth upgrade path when we tag our new major. But PHP 8.1 disallowed static calls on traits.

I also don't want to tag a new major version…

Thinking about it: @gbuckingham89 why exactly are you using the trait in your test classes? These are all static methods and can't be called on the instance, so in my mind it didn't make any sense to ever use this trait?

Checking the README, it only shows examples of using this trait statically and not by importing it. That's why I don't think this should be considered a breaking change: it was never intended to work this way.

So the breaking change comes from PHP itself. Because of that I would also stick to the promoted usage in the README.

I've just checked the older versions of the README and as you say, it's always been documented that the assertions should be called statically.

It was obviously implemented wrong in our codebase - so apologies for any confusion!

No problem!