0

I've set up Travis with Magento 2 unit tests to test our code. My PHPunit config is like this:

File dev/tests/unit/phpunit.custom.xml.dis:

 <testsuite name="Magento Unit Tests">
        <directory suffix="Test.php">../../../app/code/*/*/Test/Unit</directory>
        <directory suffix="Test.php">../../../dev/tools/*/*/Test/Unit</directory>
        <directory suffix="Test.php">../../../dev/tools/*/*/*/Test/Unit</directory>
        <directory suffix="Test.php">../../../lib/internal/*/*/Test/Unit</directory>
        <directory suffix="Test.php">../../../lib/internal/*/*/*/Test/Unit</directory>
        <!-- <directory suffix="Test.php">../../../setup/src/*/*/Test/Unit</directory> -->
        <directory suffix="Test.php">../../../vendor/*/module-*/Test/Unit</directory>
        <!-- <directory suffix="Test.php">../../../vendor/*/framework/Test/Unit</directory> -->
        <!-- <directory suffix="Test.php">../../../vendor/*/framework/*/Test/Unit</directory> -->
    </testsuite>

I've commented out some rules, because they contain known Magento 2 bugs. If I run the tests via the command line everything is fine:

........................................................... 11269 / 12140 ( 92%)
........................................................... 11328 / 12140 ( 93%)
........................................................... 11387 / 12140 ( 93%)
........................................................... 11446 / 12140 ( 94%)
........................................................... 11505 / 12140 ( 94%)
........................................................... 11564 / 12140 ( 95%)
........................................................... 11623 / 12140 ( 95%)
........................................................... 11682 / 12140 ( 96%)
........................................................... 11741 / 12140 ( 96%)
........................................................... 11800 / 12140 ( 97%)
........................................................... 11859 / 12140 ( 97%)
........................................................... 11918 / 12140 ( 98%)
........................................................... 11977 / 12140 ( 98%)
........................................................... 12036 / 12140 ( 99%)
........................................................... 12095 / 12140 ( 99%)
............................................

Time: 51.83 seconds, Memory: 572.00MB

OK, but incomplete, skipped, or risky tests!
Tests: 12137, Assertions: 36333, Incomplete: 41, Skipped: 150.

When I run the same test in Travis, i'm getting another result:

...........................................................  7375 / 12140 ( 60%)
...........................................................  7434 / 12140 ( 61%)
...........................................................  7493 / 12140 ( 61%)
....................................IIIIIIIIIIIII..........  7552 / 12140 ( 62%)
...........................................................  7611 / 12140 ( 62%)
...........................................................  7670 / 12140 ( 63%)
...........................................................  7729 / 12140 ( 63%)
...........................................................  7788 / 12140 ( 64%)
.......................................................PHP Fatal error:  Class Mock_OrderPaymentExtensionInterface_4f2544b4 contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Magento\Sales\Api\Data\OrderPaymentExtensionInterface::getVaultPaymentToken) in /home/travis/build/xxx/xxx.nl/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php(290) : eval()'d code on line 1
Fatal error: Class Mock_OrderPaymentExtensionInterface_4f2544b4 contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Magento\Sales\Api\Data\OrderPaymentExtensionInterface::getVaultPaymentToken) in /home/travis/build/xxx/xxx.nl/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php(290) : eval()'d code on line 1

My script line in .travis.yml:

script:
   - $COMPOSER_BIN_DIR/phpunit -c dev/tests/unit/phpunit.custom.xml.dist

Can anyone explain this behaviour? Why are the unit tests in failing only in Travis?

1

The error was caused by running php bin/magento setup:di:compile before the unit tests, instead of after the unit tests. Switching both commands solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.