Skip to content

WIZ-11443 Fix inheritance with phpunit #13

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

Merged
merged 4 commits into from
Apr 6, 2022

Conversation

aurelas87
Copy link
Contributor

@aurelas87 aurelas87 commented Apr 5, 2022

Due to incompatibility with phpunit > 7

We cannot extend anymore from PHPUnit\TextUI\TestRunner which is now final.

In order to get the right number of tests in the PHPUnit\TextUI\TestSuite we can apply the slice directly in the Command.

Now it is the function handleArguments of PHPUnit\TextUI\Command which is overriden. This function parses the arguments and creates the PHPUnit\TextUI\TestSuite instance. So after that, we can slice and reset the tests in the TestSuite. It will be this modified TestSuite which will be given to the run function.

Therefore, we do not need anymore the TestRunner.php file, nor the override of the createRunner function.

NB: I also removed the unbreakable spaces in the tests files.

@aurelas87 aurelas87 self-assigned this Apr 5, 2022
@aurelas87 aurelas87 requested review from ecourtial and wizagael April 5, 2022 12:16
@aurelas87 aurelas87 changed the title WIZ-11443 Slice tests in handleArguments instead of run and remove Te… WIZ-11443 Fix inheritance with phpunit Apr 5, 2022
@mfn
Copy link

mfn commented Apr 5, 2022

I tried this out, but couldn't get it to work:

  • php 7.4.28
  • phpunit 9.5.20

What I tried it:

  • install composer require --dev wizaplace/phpunit-slicer:dev-master
  • manually replaced Command.php
  • ran vendor/bin/phpunit-slicer --slices 1/100
  • got
    vagrant@dev /vagrant/project $ vendor/bin/phpunit-slicer --slices 1/100
    PHPUnit suite slicer, running slice 1/100 (194 tests: from #1 to #194)
    PHP Fatal error:  Uncaught TypeError: Argument 1 passed to PHPUnit\Runner\BaseTestRunner::getTest() must be of the type string, null given, called in /vagrant/project/vendor/phpunit/phpunit/src/TextUI/Command.php on line 120 and defined in /vagrant/project/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:88
    Stack trace:
    #0 /vagrant/project/vendor/phpunit/phpunit/src/TextUI/Command.php(120): PHPUnit\Runner\BaseTestRunner->getTest(NULL, Array)
    #1 /vagrant/project/vendor/phpunit/phpunit/src/TextUI/Command.php(96): PHPUnit\TextUI\Command->run(Array, true)
    #2 /vagrant/project/vendor/wizaplace/phpunit-slicer/phpunit-slicer(52): PHPUnit\TextUI\Command::main()
    #3 /vagrant/project/vendor/bin/phpunit-slicer(112): include('/vagrant/api.sw...')
    #4 {main}
    
    Next PHPUnit\TextUI\RuntimeException: Argument 1 passed to PHPUnit\Runner\BaseTestRunner::getTest() must be of the type string, null given, called in /vagrant/project/vendor/phpunit/phpunit/src/TextUI/Command.php on line 120 in /vagrant/project/vendor/ in /vagrant/project/vendor/phpunit/phpunit/src/TextUI/Command.php on line 98
    

Maybe I did something wrong, not sure what a better way would be to test this.

My phpunit.xml.dist (nothing special AFAICS):

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
         backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="tests/bootstrap.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         cacheResult="false"
         failOnWarning="true"
         executionOrder="random"
>
  <testsuites>
    <testsuite name="Application Test Suite">
      <directory>./tests/</directory>
    </testsuite>
  </testsuites>
</phpunit>

@aurelas87
Copy link
Contributor Author

I tried this out, but couldn't get it to work:

  • php 7.4.28
  • phpunit 9.5.20

What I tried it:

  • install composer require --dev wizaplace/phpunit-slicer:dev-master
  • manually replaced Command.php
  • ran vendor/bin/phpunit-slicer --slices 1/100
  • got
    vagrant@dev /vagrant/project $ vendor/bin/phpunit-slicer --slices 1/100
    PHPUnit suite slicer, running slice 1/100 (194 tests: from #1 to #194)
    PHP Fatal error:  Uncaught TypeError: Argument 1 passed to PHPUnit\Runner\BaseTestRunner::getTest() must be of the type string, null given, called in /vagrant/project/vendor/phpunit/phpunit/src/TextUI/Command.php on line 120 and defined in /vagrant/project/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:88
    Stack trace:
    #0 /vagrant/project/vendor/phpunit/phpunit/src/TextUI/Command.php(120): PHPUnit\Runner\BaseTestRunner->getTest(NULL, Array)
    #1 /vagrant/project/vendor/phpunit/phpunit/src/TextUI/Command.php(96): PHPUnit\TextUI\Command->run(Array, true)
    #2 /vagrant/project/vendor/wizaplace/phpunit-slicer/phpunit-slicer(52): PHPUnit\TextUI\Command::main()
    #3 /vagrant/project/vendor/bin/phpunit-slicer(112): include('/vagrant/api.sw...')
    #4 {main}
    
    Next PHPUnit\TextUI\RuntimeException: Argument 1 passed to PHPUnit\Runner\BaseTestRunner::getTest() must be of the type string, null given, called in /vagrant/project/vendor/phpunit/phpunit/src/TextUI/Command.php on line 120 in /vagrant/project/vendor/ in /vagrant/project/vendor/phpunit/phpunit/src/TextUI/Command.php on line 98
    

Maybe I did something wrong, not sure what a better way would be to test this.

My phpunit.xml.dist (nothing special AFAICS):

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
         backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="tests/bootstrap.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         cacheResult="false"
         failOnWarning="true"
         executionOrder="random"
>
  <testsuites>
    <testsuite name="Application Test Suite">
      <directory>./tests/</directory>
    </testsuite>
  </testsuites>
</phpunit>

I just tested it on my local environment and I got the same error on PHP 8. I'm looking into it...

@aurelas87
Copy link
Contributor Author

It's working fine now. Just a missing file in my commits. Updated the tests as well.

@mfn
Copy link

mfn commented Apr 5, 2022

Yes, seems to work now 😱

@wizagael wizagael changed the title WIZ-11443 Fix inheritance with phpunit WIZ-11443 Fix inheritance with phpunit > 7 Apr 6, 2022
@wizagael wizagael changed the title WIZ-11443 Fix inheritance with phpunit > 7 WIZ-11443 Fix inheritance with phpunit Apr 6, 2022
@ecourtial ecourtial merged commit 757a715 into master Apr 6, 2022
@ecourtial ecourtial deleted the WIZ-11443-fix-inheritance-with-phpunit branch April 6, 2022 09:42
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

Successfully merging this pull request may close these issues.

4 participants