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

[Question] Module class made final, Codeception docs seem to indicate extends #110

Open
qrazi opened this issue Dec 9, 2024 · 6 comments

Comments

@qrazi
Copy link

qrazi commented Dec 9, 2024

(apologies if the title is too convoluted!)

So, one of the changes introduced between 1.1.10 & 1.1.11 is that the Module class is made final. See src/Codeception/Module/Yii2.php, line 168/169.

Craft CMS is a CMS that is built on Yii2. For its testing API it uses Codeception and this Codeception yii2 module. Amongst others it extends this module: https://github.com/craftcms/cms/blob/5.x/src/test/Craft.php#L65

And of course extending a final class is not possible, so our test suites now throw an error:

Fatal error: Class craft\test\Craft cannot extend final class Codeception\Module\Yii2 in /app/vendor/craftcms/cms/src/test/Craft.php on line 65

The documentation of Codeception 5 mentions the following when it comes to extending a Module: https://codeception.com/docs/ModulesAndHelpers#Extending-a-Module. So I think this means that the Codeception\Module\Yii2 class should not be final.

I'm submitting this more as a question, because I might be missing the context for which the change to final was made.

@samdark
Copy link
Member

samdark commented Dec 9, 2024

I've just tagged new release un-finalizing it.

@samdark samdark closed this as completed Dec 9, 2024
@qrazi
Copy link
Author

qrazi commented Dec 10, 2024

Just tested with the newest version and as expected the test suite runs again, thank you!

@SamMousa
Copy link
Collaborator

@qrazi

I'm reopening this issue for the next major release.
I've looked at the craft implementation of the subclass and I'm wondering if the same could not be achieved via composition?

Opening up class internals for extension by 3rd party code is really bad for our maintainability and makes it harder to reason about the (supposedly) internal state of our module.

@SamMousa SamMousa reopened this Feb 26, 2025
@SamMousa
Copy link
Collaborator

@qrazi, just a heads up i'm releasing v2; this will reintroduce this issue for you.
I'm doing this because finalizing is a major release and we could always unfinalize it in a minor one.
I checked the composer.json for CraftCMS and it should not lead to problems since you're using "codeception/module-yii2": "^1.1.9", which won't match 2.

@qrazi
Copy link
Author

qrazi commented Feb 27, 2025

Makes total sense to me, thanks!

Now the extending of a (this) module does not work anymore as described in the general documentation: https://codeception.com/docs/ModulesAndHelpers#Extending-a-Module:

If accessing modules doesn’t provide enough flexibility, you can extend a module inside a Helper class:

namespace Tests\Support\Helper;

class MyExtendedSelenium extends \Codeception\Module\WebDriver
{
}

So, is this a case where Codeception Modules decide for themselves how they can be extended? So, I / someone should make PR for the documentation on Codeception?

@SamMousa
Copy link
Collaborator

So, is this a case where Codeception Modules decide for themselves how they can be extended? So, I / someone should make PR for the documentation on Codeception?

I think so yes.

But I'd still like to make sure that your specific case can actually be solved using composition; or if it requires other changes to the Yii2 module.

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

No branches or pull requests

3 participants