You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Compile Error: '\self' is an invalid class name #6164
I'm trying to run: vendor/bin/codecept build with a test suite which one of its modules now has methods with a fluid interface, that is, they have as return type ': self' and I get this error:
PHP Fatal error: '\self' is an invalid class name in C:\...\tests\_build\support\_
generated\FunctionalTesterActions.php on line 4474
Compile Error: '\self' is an invalid class name
I think that this issue could be fixed by handling self and other relative class references in the same way as builtin types in $type->isBuiltin() ? '' : '\\', line.
If it doesn't work, then we can try resolve fully qualified class name and use it as type.
Using self return type in generated Actions trait would be wrong.
In this context self means FunctionalTester, but your methods return instance of Codeception\Module\Symfony.
Only methods of Symfony module would be chainable.
If we implemented the same change in all other modules, only methods of the same module would be chainable together.
In this context self means FunctionalTester, but your methods return instance of Codeception\Module\Symfony.
Hmmm, in that case I'll just remove : self...
We can implement that in the same Actions Generator, by making wrappers of all void methods return $this.
Regarding this, if we think of lib-innerbrowser and framework modules as the Codeception domain, and the code that generates the actions as part of the infrastructure then I'm not sure that making that change there is the best.
"If you want your method to return the $this when generating, make it return void" sounds a strange thing to consider, especially if I'm extending from any module in some custom class.
But, on the other hand, it has its charm to know that I will be able to chain everything regardless of the module I use.
So. A third option could be the following:
What if we take 'Implement the Fluent interface' to the literal sense.
Let's make an interface called Fluid or Chainable, and make Codeception\Module implement it.
That way you could do that of changing void/Fluent to $this in the generation and I could type my methods so that they return that interface instead of void (which is what I'm not happy with if they will return to themselves in the end)
I hope I am not taking SOLID and DRY too far with this.
Well, give me a list of the modules that are ready to do without php 5.6 and I will gladly send PR adding return types. (In that case I should block the required php version of them to PHP 7.1)
Personally I no longer have reason to support PHP 5.6 (on the other hand I don't know when I will use Codeception again), so all modules can be updated.
This change will bump the major version of all modules, Codeception 5 is near, so this is a good time to improve Codeception module system.
I haven't separated modules from codeception/codeception cleanly and created this ugly circular dependency issue.
It would be great to extract all interfaces that modules depend on to separate package and make modules depend on it instead of codeception/codeception.
Some modules have shared dependencies that were left in codeception/codeception, they must be extracted to separate packages. E.g. Xml classes in https://github.com/Codeception/Codeception/tree/4.1.20/src/Codeception/Util .
I quickly realized that the idea of dropping dependency on codeception/codeception is difficult to implement because Codeception is a test framework and it is used for running tests of all modules. Using another test framework for running module tests is worse. Also module tests are not isolated from Codeception.
If you have other ideas how to improve module system, this is a good time to raise them.
@DavertMik used amOnPage and click methods in his example, but neither of them will be chainable without making breaking change in Web interface.
I think that it is fine to update interface in 5.0, but composer.json of framework modules and module-webdriver must be updated to require Codeception 5.
@Naktibaldamodule-webdriver doesn't seem to have a CI working, it's quite difficult for me to make changes there.
The PR to type the interfaces has already been merged with the 5.0 branch and the tests are passing.
In addition, in the vast majority of modules that I promised to update there is already a branch called codecept5 with the tests passing, if it does not exist it means that the changes are directly in the master branch.
I did'nt tag any changes as both PHPUnit 10 and Codeception 5 release date is still uncertain.
As things are going, it might even make sense to do without PHP 7.3 which will be discontinued this November.
please don't hesitate to ping me if you need anything else.
There were some links to CI builds on Semaphore 2, but they only appeared because I signed up to Semaphore 2 back in April and didn't bother setting it up.
Also module tests are not isolated from Codeception.
@Naktibalda I think that decoupling the methods of module-symfony from Codeception is something that can be done, only depending on interfaces, in theory, anyone could use the assertions they need by adding the individual traits to their TestCase, or creating an abstract TestCase of their own, implementing the method that returns the collector or service required to perform the assertion (or just overriding getContainer()).
It is something that requires a bit of work, but it is definitely possible.
I could work on that, but I would need to...
extract all interfaces that modules depend on to separate package.
Some modules have shared dependencies that were left in codeception/codeception, they must be extracted to separate packages.
Activity
Naktibalda commentedon Apr 18, 2021
Relevant code: https://github.com/Codeception/Codeception/blob/4.1/src/Codeception/Lib/Generator/Actions.php#L239-L257
I think that this issue could be fixed by handling
selfand other relative class references in the same way as builtin types in$type->isBuiltin() ? '' : '\\',line.If it doesn't work, then we can try resolve fully qualified class name and use it as type.
Naktibalda commentedon Apr 18, 2021
Using
selfreturn type in generated Actions trait would be wrong.In this context
selfmeansFunctionalTester, but your methods return instance ofCodeception\Module\Symfony.Only methods of Symfony module would be chainable.
If we implemented the same change in all other modules, only methods of the same module would be chainable together.
I think that the user expectation would be that all actions can be chained together.
We can implement that in the same Actions Generator, by making wrappers of all
voidmethods return$this.https://github.com/Codeception/Codeception/blob/4.1.20/src/Codeception/Lib/Generator/Actions.php#L100-L147
TavoNiievez commentedon Apr 18, 2021
Hmmm, in that case I'll just remove
: self...Regarding this, if we think of lib-innerbrowser and framework modules as the Codeception domain, and the code that generates the actions as part of the infrastructure then I'm not sure that making that change there is the best.
"If you want your method to return the
$thiswhen generating, make it returnvoid" sounds a strange thing to consider, especially if I'm extending from any module in some custom class.But, on the other hand, it has its charm to know that I will be able to chain everything regardless of the module I use.
So. A third option could be the following:
What if we take 'Implement the Fluent interface' to the literal sense.
Let's make an interface called Fluid or Chainable, and make
Codeception\Moduleimplement it.That way you could do that of changing
void/Fluentto$thisin the generation and I could type my methods so that they return that interface instead ofvoid(which is what I'm not happy with if they will return to themselves in the end)I hope I am not taking SOLID and DRY too far with this.
Naktibalda commentedon Apr 18, 2021
I forgot that only your modules use
voidtypehint.So to get fluent interface working properly we must add return types to all modules.
TavoNiievez commentedon Apr 18, 2021
Well, give me a list of the modules that are ready to do without php 5.6 and I will gladly send PR adding return types. (In that case I should block the required php version of them to PHP 7.1)
Naktibalda commentedon Apr 18, 2021
Personally I no longer have reason to support PHP 5.6 (on the other hand I don't know when I will use Codeception again), so all modules can be updated.
This change will bump the major version of all modules, Codeception 5 is near, so this is a good time to improve Codeception module system.
I haven't separated modules from codeception/codeception cleanly and created this ugly circular dependency issue.
It would be great to extract all interfaces that modules depend on to separate package and make modules depend on it instead of codeception/codeception.
Some modules have shared dependencies that were left in codeception/codeception, they must be extracted to separate packages. E.g. Xml classes in https://github.com/Codeception/Codeception/tree/4.1.20/src/Codeception/Util .
Have you got time for this?
TavoNiievez commentedon Apr 18, 2021
If you take care of those architectural tasks (I mean, create the new packages) and show me how the dependencies will be replaced, I can:
So...
The following are the modules that I would commit to update to PHP 7.3 with all the features that that implies and replace dependencies:
The following are the modules to which I commit to add return types (only that), update their PHP requirement to PHP 7.1 and replace dependencies:
I cannot deal with modules that are not mentioned.
Naktibalda commentedon Apr 19, 2021
I quickly realized that the idea of dropping dependency on codeception/codeception is difficult to implement because Codeception is a test framework and it is used for running tests of all modules. Using another test framework for running module tests is worse. Also module tests are not isolated from Codeception.
If you have other ideas how to improve module system, this is a good time to raise them.
TavoNiievez commentedon Apr 19, 2021
Can we move forward on the fluent interface/return types issue until then, or is it very necessary to improve the module system beforehand?
DavertMik commentedon Apr 23, 2021
I agree with the proposal fluent interface. Seems really cool.
All methods except
grabcan be used as a chain:To me it adds not too much value but looks cool 😎
TavoNiievez commentedon May 13, 2021
@Naktibalda I sent all the PRs.
btw, I changed my mind about the yii2 module, it is better if one of its maintainers makes the necessary specific changes.
Naktibalda commentedon May 18, 2021
@DavertMik used
amOnPageandclickmethods in his example, but neither of them will be chainable without making breaking change in Web interface.I think that it is fine to update interface in 5.0, but composer.json of framework modules and module-webdriver must be updated to require Codeception 5.
TavoNiievez commentedon Jun 7, 2021
@Naktibalda
module-webdriverdoesn't seem to have a CI working, it's quite difficult for me to make changes there.The PR to type the interfaces has already been merged with the 5.0 branch and the tests are passing.
In addition, in the vast majority of modules that I promised to update there is already a branch called
codecept5with the tests passing, if it does not exist it means that the changes are directly in themasterbranch.I did'nt tag any changes as both PHPUnit 10 and Codeception 5 release date is still uncertain.
As things are going, it might even make sense to do without PHP 7.3 which will be discontinued this November.
please don't hesitate to ping me if you need anything else.
Naktibalda commentedon Jun 7, 2021
module-webdriver has CI setup in Semaphore CI - https://semaphoreci.com/codeception/module-webdriver
Only Chrome Headless build is passing.
There were some links to CI builds on Semaphore 2, but they only appeared because I signed up to Semaphore 2 back in April and didn't bother setting it up.
TavoNiievez commentedon Aug 2, 2021
@Naktibalda I think that decoupling the methods of
module-symfonyfrom Codeception is something that can be done, only depending on interfaces, in theory, anyone could use the assertions they need by adding the individual traits to their TestCase, or creating an abstract TestCase of their own, implementing the method that returns the collector or service required to perform the assertion (or just overridinggetContainer()).It is something that requires a bit of work, but it is definitely possible.
I could work on that, but I would need to...
be created, something like
codeception/contracts.Naktibalda commentedon Aug 6, 2021
What's the point if we use codeception/codeception to run the tests of that module?
TavoNiievez commentedon Aug 6, 2021
I think it would be useful to be able to use a module individually in projects where it is not feasible to migrate to Codeception.