Skip to content

Issue in mocking Throwable with php7.0, 7.1 and 7.2 #2995

@DeepDiver1975

Description

@DeepDiver1975
Q A
PHPUnit version 6.5.6
PHP version 7.0.23, 7.1.13, 7.2.2
Installation Method Composer

Error

Testing started at 18:17 ...
/usr/bin/php7.2 /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/phpunit --no-configuration Test /home/deepdiver/Development/phpunit-mock-throwable/test.php --teamcity
PHPUnit 6.5.6 by Sebastian Bergmann and contributors.

PHP Fatal error:  Class Mock_MyException_6ab00dfe cannot implement interface Throwable, extend Exception or Error instead in /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit-mock-objects/src/Generator.php(264) : eval()'d code on line 1
PHP Stack trace:
PHP   1. {main}() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/phpunit:53
PHP   3. PHPUnit\TextUI\Command->run() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/src/TextUI/Command.php:148
PHP   4. PHPUnit\TextUI\TestRunner->doRun() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/src/TextUI/Command.php:195
PHP   5. PHPUnit\Framework\TestSuite->run() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:546
PHP   6. Test->run() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/src/Framework/TestSuite.php:755
PHP   7. PHPUnit\Framework\TestResult->run() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/src/Framework/TestCase.php:894
PHP   8. Test->runBare() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/src/Framework/TestResult.php:698
PHP   9. Test->runTest() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/src/Framework/TestCase.php:939
PHP  10. ReflectionMethod->invokeArgs() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/src/Framework/TestCase.php:1071
PHP  11. Test->test() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/src/Framework/TestCase.php:1071
PHP  12. Test->createMock() /home/deepdiver/Development/phpunit-mock-throwable/test.php:16
PHP  13. PHPUnit\Framework\MockObject\MockBuilder->getMock() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit/src/Framework/TestCase.php:1497
PHP  14. PHPUnit\Framework\MockObject\Generator->getMock() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit-mock-objects/src/MockBuilder.php:118
PHP  15. PHPUnit\Framework\MockObject\Generator->getObject() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit-mock-objects/src/Generator.php:200
PHP  16. PHPUnit\Framework\MockObject\Generator->evalClass() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit-mock-objects/src/Generator.php:221
PHP  17. eval() /home/deepdiver/Development/phpunit-mock-throwable/vendor/phpunit/phpunit-mock-objects/src/Generator.php:264

Process finished with exit code 255

Code

<?php
interface MyException extends \Throwable
{

}

class Test extends \PHPUnit\Framework\TestCase {
    public function __construct(string $name = null, array $data = [], string $dataName = '')
    {
        parent::__construct($name, $data, $dataName);
    }

    public function test()
    {
        $this->createMock(MyException::class);
    }
}

composer

deepdiver@alien:~/Development/phpunit-mock-throwable$ ./composer.phar info
doctrine/instantiator              1.1.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
myclabs/deep-copy                  1.7.0 Create deep copies (clones) of your objects
phar-io/manifest                   1.0.1 Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                    1.0.1 Library for handling version information and constraints
phpdocumentor/reflection-common    1.0.1 Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock  4.3.0 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver        0.4.0
phpspec/prophecy                   1.7.3 Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage          5.3.0 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator          1.4.5 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template          1.2.1 Simple template engine.
phpunit/php-timer                  1.0.9 Utility class for timing
phpunit/php-token-stream           2.0.2 Wrapper around PHP's tokenizer extension.
phpunit/phpunit                    6.5.6 The PHP Unit Testing framework.
phpunit/phpunit-mock-objects       5.0.6 Mock Object library for PHPUnit
sebastian/code-unit-reverse-lookup 1.0.1 Looks up which function or method a line of code belongs to
sebastian/comparator               2.1.3 Provides the functionality to compare PHP values for equality
sebastian/diff                     2.0.1 Diff implementation
sebastian/environment              3.1.0 Provides functionality to handle HHVM/PHP environments
sebastian/exporter                 3.1.0 Provides the functionality to export PHP variables for visualization
sebastian/global-state             2.0.0 Snapshotting of global state
sebastian/object-enumerator        3.0.3 Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector         1.1.1 Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context        3.0.0 Provides functionality to recursively process PHP variables
sebastian/resource-operations      1.0.0 Provides a list of PHP built-in functions that operate on resources
sebastian/version                  2.0.1 Library that helps with managing the version number of Git-hosted PHP projects
theseer/tokenizer                  1.1.0 A small library for converting tokenized PHP source code into XML and potentially other formats
webmozart/assert                   1.3.0 Assertions to validate method input/output with nice error messages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions