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

Detect changes in ENUMs as BC breaks #768

Merged
merged 32 commits into from
May 22, 2024
Merged

Conversation

bdsl
Copy link
Contributor

@bdsl bdsl commented May 19, 2024

See #767

I went slightly further than discussed in the issue, reporting a BC break for cases removed, as well as for cases added. In both cases cases marked @internal do not trigger the BC break.

I think there's more to do for a complete handling of enums, including detecting if an entire Enum is removed, or becomes a trait, class or interface. Actually I see the entire Enum removed is already handled by the catch of IdentifierNotFound

} catch (IdentifierNotFound) {

and I could easily extend this PR to handle became trait/interface/class by simply treating one of those as a thing that has no cases - so an enum becoming one of those is not an issue itself, its only an issue because it means cases go away. And an enum with no cases becoming a different sort of classlike is not a BC break. Let me know if you'd like me to do that.

@bdsl bdsl force-pushed the 767-enum-cases branch 4 times, most recently from 69e22a7 to 20779b5 Compare May 19, 2024 14:45
@bdsl bdsl marked this pull request as ready for review May 19, 2024 15:22
@bdsl bdsl changed the title Roave/BackwardCompatibilityCheck#767 WIP - add tests Roave/BackwardCompatibilityCheck#767 Detect case addittions or removals from Enums as BC breaks May 19, 2024
@bdsl
Copy link
Contributor Author

bdsl commented May 19, 2024

If you approve the workflow I'll try to fix any issues it detects.

I've run unit tests, psalm and phpcs on my local. It might be nice to have some end to end testing as well though. For this sort of project I wish git would work recursively, letting us have a git repo of a sample project inside this repo's test assets directory.

@Ocramius
Copy link
Member

@bdsl done

@bdsl
Copy link
Contributor Author

bdsl commented May 19, 2024

I also noticed there seems to be quite a bit of code duplication in the existing code between the handling of Classes, Traits and Interface. I think there could be a nice way to remove that duplication, but I didn't want to get into restructuring the existing code on my first PR. E.g. the ClassBased, TraitBased, InterfaceBased and new EnumBased interfaces are all the same except with differently named parameters, and the three MultipleChecksOnA... classes are also extremely similar. I didn't feel like writing MultipleChecksOnAnEnum which is partly why I implemented all the checks within one class EnumBased\ClassChanged

@bdsl bdsl force-pushed the 767-enum-cases branch 2 times, most recently from d195486 to 3d288ec Compare May 19, 2024 15:51
@bdsl
Copy link
Contributor Author

bdsl commented May 19, 2024

ah didn't realise you need to approve the workflow separately for every commit. I've turned on github actions in my fork so we can see the results there: https://github.com/bdsl/BackwardCompatibilityCheck/actions

@bdsl bdsl changed the title Roave/BackwardCompatibilityCheck#767 Detect case addittions or removals from Enums as BC breaks Roave/BackwardCompatibilityCheck#767 Detect case additions or removals from Enums as BC breaks May 19, 2024
@bdsl
Copy link
Contributor Author

bdsl commented May 19, 2024

The Infection check is currently failing. But on my local using vendor/bin/roave-infection-static-analysis-plugin --threads=8 --logger-html=infection.html I'm now getting 0 undetected mutants, so I'm not quite sure why. I'll have to come back to this later to see how to reproduce the way that github actions is running infection.

@bdsl
Copy link
Contributor Author

bdsl commented May 19, 2024

@Ocramius can you see where I'm going wrong with the mutation tests? On my laptop (php 8.3 with xdebug in WSL) I'm getting 0 returned from the infection command as shown below. I don't know if it could be because I'm running xdebug rather than phpdbg.

$ git show --stat; git status; ./vendor/bin/roave-infection-static-analysis-plugin; echo $?
commit b5cfc9b2e141b0cd772db8e5f7ca95d9cf68a898 (HEAD -> 767-enum-cases, bdsl/767-enum-cases)
Author: Barney Laurance <barney@redmagic.org.uk>
Date:   Sun May 19 17:34:06 2024 +0100

    Roave/BackwardCompatibilityCheck#767: Remove unecassary array_values calls
    
    Infection detected that these were not needed

 src/DetectChanges/BCBreak/EnumBased/CasesChanged.php | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
On branch 767-enum-cases
nothing to commit, working tree clean

    ____      ____          __  _
   /  _/___  / __/__  _____/ /_(_)___  ____
   / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
 _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /
/___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/

#StandWithUkraine

Infection - PHP Mutation Testing Framework version 0.27.10


Running initial test suite...

PHPUnit version: 9.6.18

  755 [============================] 7 secs

Generate mutants...

Processing source code files: 115/115
.: killed, M: escaped, U: uncovered, E: fatal error, X: syntax error, T: timed out, S: skipped, I: ignored

..................................................   ( 50 / 639)
..................................................   (100 / 639)
..................................................   (150 / 639)
..................................................   (200 / 639)
..................................................   (250 / 639)
..................................................   (300 / 639)
..................................................   (350 / 639)
..................................................   (400 / 639)
..................................................   (450 / 639)
..................................................   (500 / 639)
..................................................   (550 / 639)
....E.............................................   (600 / 639)
.......................................              (639 / 639)

639 mutations were generated:
     638 mutants were killed
       0 mutants were configured to be ignored
       0 mutants were not covered by tests
       0 covered mutants were not detected
       1 errors were encountered
       0 syntax errors were encountered
       0 time outs were encountered
       0 mutants required more time than configured

Metrics:
         Mutation Score Indicator (MSI): 100%
         Mutation Code Coverage: 100%
         Covered Code MSI: 100%

Note: to see escaped mutants run Infection with "--show-mutations" or configure file loggers.

Please note that some mutants will inevitably be harmless (i.e. false positives).
Escaped mutants:
================

Timed Out mutants:
==================

Skipped mutants:
================

Not Covered mutants:
====================
[warning] Dashboard report has not been sent: The current process is not executed in a CI build
 ! [NOTE] The MSI is 9.9% percentage points over the required MSI. Consider increasing the required MSI percentage the  
 !        next time you run Infection.


Time: 55s. Memory: 0.11GB. Threads: 1
0

@Ocramius
Copy link
Member

Notice: You are running Infection with phpdbg enabled.

Perhaps it's using phpdbg for coverage, rather than XDebug

@bdsl
Copy link
Contributor Author

bdsl commented May 19, 2024

Notice: You are running Infection with phpdbg enabled.

Perhaps it's using phpdbg for coverage, rather than XDebug

Yes possibly. I'll see if I can it working with phpdbg on my local.

Trying to work out whether this is related to the infection check
failure - I haven't been able to reproduce the way its failing on my
local.
bdsl added 2 commits May 22, 2024 00:52
Perhaps the semantics are arguable, but I think it's safest to say
making a case no longer internal is a BC break, as it means we no-longer
gurantee to not return it and client code may need to check for it as
part of an exhaustive match.
@bdsl
Copy link
Contributor Author

bdsl commented May 22, 2024

This is ready for re-review.

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

final to be added, plus some minor adjustments, then this can 🚢 :)

@Ocramius Ocramius added this to the 8.8.0 milestone May 22, 2024
@Ocramius Ocramius self-assigned this May 22, 2024
Co-authored-by: Marco Pivetta <ocramius@gmail.com>
@Ocramius
Copy link
Member

All looking quite good!

I'll do a local check of specific mutants before merging :-)

@Ocramius
Copy link
Member

Took me a bit (because I just switched my OS / main computer), but this is pristine when running with XDebug!

692 mutations were generated:
     691 mutants were killed
       0 mutants were configured to be ignored
       0 mutants were not covered by tests
       0 covered mutants were not detected
       1 errors were encountered
       0 syntax errors were encountered
       0 time outs were encountered
       0 mutants required more time than configured

Metrics:
         Mutation Score Indicator (MSI): 100%
         Mutation Code Coverage: 100%
         Covered Code MSI: 100%

Note: to see escaped mutants run Infection with "--show-mutations" or configure file loggers.

Please note that some mutants will inevitably be harmless (i.e. false positives).
Escaped mutants:
================

Timed Out mutants:
==================

Skipped mutants:
================

Not Covered mutants:
====================
[warning] Dashboard report has not been sent: The current process is not executed in a CI build
 ! [NOTE] The MSI is 9.9% percentage points over the required MSI. Consider increasing the required MSI percentage the  
 !        next time you run Infection.

I will lower the MT requirements to get this merged, meanwhile :-)

Note that MT MSI is 100% when running with XDebug, but 85.84% when running with `phpdbg`, which is
no longer supported by PHPUnit.

This will be fixed in a later iteration of the Laminas test container: laminas/laminas-ci-matrix-action#189
@bdsl
Copy link
Contributor Author

bdsl commented May 22, 2024

Took me a bit (because I just switched my OS / main computer), but this is pristine when running with XDebug!

Yep, I ran infection on my local when I saw that it was failing on the build, so then killed all the mutants.

There are some mutations I can imagine easily that are not tested, like deleting the untested "return trait" here or equivalently replacing the if condition with false. But I think enough is tested.

image

@Ocramius
Copy link
Member

Meanwhile, 🚢

Thanks @bdsl!

@Ocramius Ocramius linked an issue May 22, 2024 that may be closed by this pull request
@Ocramius Ocramius changed the title Roave/BackwardCompatibilityCheck#767 Detect case additions or removals from Enums as BC breaks Detect changes in ENUMs as BC breaks May 22, 2024
@Ocramius Ocramius merged commit 9296147 into Roave:8.8.x May 22, 2024
12 checks passed
@bdsl bdsl deleted the 767-enum-cases branch May 22, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New feature: Detect EnumCaseAdded as a BC break
2 participants