Skip to content

Compile Error: '\self' is an invalid class name #6164

Closed

Description

@TavoNiievez

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  

Check out the failed build here.

Activity

  1. Naktibalda commented on Apr 18, 2021

    @Naktibalda
    Member

    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 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.

  2. Naktibalda commented on Apr 18, 2021

    @Naktibalda
    Member

    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.

    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 void methods return $this.
    https://github.com/Codeception/Codeception/blob/4.1.20/src/Codeception/Lib/Generator/Actions.php#L100-L147

  3. TavoNiievez commented on Apr 18, 2021

    @TavoNiievez
    MemberAuthor

    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.

  4. Naktibalda commented on Apr 18, 2021

    @Naktibalda
    Member

    I forgot that only your modules use void typehint.

    So to get fluent interface working properly we must add return types to all modules.

  5. TavoNiievez commented on Apr 18, 2021

    @TavoNiievez
    MemberAuthor

    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)

  6. Naktibalda commented on Apr 18, 2021

    @Naktibalda
    Member

    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?

  7. TavoNiievez commented on Apr 18, 2021

    @TavoNiievez
    MemberAuthor

    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:

    1. Replace the dependency of Codeception/Codeception by the new packages in modules and,
    2. Update the code standards... (If these new versions will be targeting Codeception 5, what makes the most sense is to go straight to PHP 7.3).

    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:

    • module-doctrine2
    • module-laravel
    • module-lumen
    • module-phalcon4
    • module-rest
    • module-symfony

    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:

    • lib-innerbrowser
    • module-amqp
    • module-asserts
    • module-cli
    • module-datafactory
    • module-db
    • module-filesystem
    • module-laminas
    • module-mezzio
    • module-mongodb
    • module-phpbrowser
    • module-redis
    • module-soap

    I cannot deal with modules that are not mentioned.

  8. Naktibalda commented on Apr 19, 2021

    @Naktibalda
    Member

    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.

  9. TavoNiievez commented on Apr 19, 2021

    @TavoNiievez
    MemberAuthor

    Can we move forward on the fluent interface/return types issue until then, or is it very necessary to improve the module system beforehand?

  10. DavertMik commented on Apr 23, 2021

    @DavertMik
    Member

    I agree with the proposal fluent interface. Seems really cool.
    All methods except grab can be used as a chain:

    $I->amOnPage('xx')
      ->click('yy')
      ->grab('zzz')

    To me it adds not too much value but looks cool 😎

  11. TavoNiievez commented on May 13, 2021

    @TavoNiievez
    MemberAuthor

    @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.

  12. Naktibalda commented on May 18, 2021

    @Naktibalda
    Member

    @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.

  13. TavoNiievez commented on Jun 7, 2021

    @TavoNiievez
    MemberAuthor

    @Naktibalda module-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.

  14. Naktibalda commented on Jun 7, 2021

    @Naktibalda
    Member

    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.

  15. TavoNiievez commented on Aug 2, 2021

    @TavoNiievez
    MemberAuthor

    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.

    be created, something like codeception/contracts.

  16. Naktibalda commented on Aug 6, 2021

    @Naktibalda
    Member

    What's the point if we use codeception/codeception to run the tests of that module?

  17. TavoNiievez commented on Aug 6, 2021

    @TavoNiievez
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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