Skip to content

2.2.0 introduced BC breaks #180

@mxr576

Description

@mxr576

I am a strong advocate for type safety and the use of PHPStan in legacy projects. However, I encountered an issue stemming from the recent changes in the MinkBrowserKitDriver library, which introduced a breaking change in a minor version update.

The commit c1c3a2fd143e78ccfe8ec4363d42edcc46e3fdfa narrowed the type from no type to string for several parameters. This change was released in a minor version (2.2.0) instead of a major version, resulting in a backward compatibility (BC) break.

This change has caused test failures in downstream projects, such as Drupal core and contrib/custom modules, which previously worked with version 2.1.0 but now fail with version 2.2.0.

Example of Failure

In Drupal core, the following test fails:

1) Drupal\Tests\.......
Behat\Mink\Exception\DriverException: Only string values can be used for a radio input.

/mnt/files/local_mount/build/vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php:415
/mnt/files/local_mount/build/vendor/behat/mink/src/Element/NodeElement.php:118
/mnt/files/local_mount/build/web/core/tests/Drupal/Tests/UiHelperTrait.php:96
/mnt/files/local_mount/build/web/core/modules/user/tests/src/Functional/UserRegistrationTest.php:136
/mnt/files/local_mount/build/vendor/phpunit/phpunit/src/Framework/TestResult.php:729

Changes in Downstream Projects

To address this issue, Drupal core has updated its minimum requirement to >=2.2.0 and modified integer method parameters to strings to comply with the new type constraints. You can view the changes made in Drupal core here.

Backward Compatibility Check

Using Roave/BackwardCompatibilityCheck, the following breaking changes were identified:

$ git clone https://github.com/minkphp/MinkBrowserKitDriver.git
$ cd MinkBrowserKitDriver
$ docker run --rm -v `pwd`:/app nyholm/roave-bc-check --from=v2.1.0

[BC] CHANGED: The parameter $baseUrl of Behat\Mink\Driver\BrowserKitDriver#__construct() changed from no type to a non-contravariant string|null
...
[BC] CHANGED: The parameter $xpath of Behat\Mink\Driver\BrowserKitDriver#getFormField() changed from no type to string

(Full list of changes omitted for brevity)

Conclusion

Releasing such significant type changes in a minor version has caused unexpected failures in dependent projects. It would be prudent to release such changes in a major version update to adhere to semantic versioning principles and avoid breaking backward compatibility.

Recommendation In the 2.x branch, trigger user level deprecations for invalid input by using trigger_error() instead of throwing an exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions