Skip to content

ParseError when trying to mock exit, die #82

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

Closed
simonLeary42 opened this issue Apr 29, 2025 · 3 comments
Closed

ParseError when trying to mock exit, die #82

simonLeary42 opened this issue Apr 29, 2025 · 3 comments

Comments

@simonLeary42
Copy link

test/BuiltinMockTest.php:

<?php
namespace Foobar;
class BuiltinMockTest extends \PHPUnit\Framework\TestCase {
    use \phpmock\phpunit\PHPMock;
    public function testMockDie() {
        $mock = $this->getFunctionMock(__NAMESPACE__, "die");
    }
}
$ ./vendor/bin/phpunit --no-configuration ./test/BuiltinMockTest.php  | sed -E "s|$PWD|...|"
PHPUnit 12.0.10 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.6

E                                                                   1 / 1 (100%)

Time: 00:00.023, Memory: 8.00 MB

There was 1 error:

1) Foobar\BuiltinMockTest::testMockDie
ParseError: syntax error, unexpected token "exit", expecting "("

.../vendor/php-mock/php-mock/classes/Mock.php:188
.../vendor/php-mock/php-mock/classes/Mock.php:96
.../vendor/php-mock/php-mock-phpunit/classes/PHPMock.php:85
.../test/BuiltinMockTest.php:6

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

php version:

PHP 8.3.6 (cli) (built: Mar 19 2025 10:08:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

composer show:

hakasapl/phpopenldaper           1.0.6    Wrapper for php-ldap
myclabs/deep-copy                1.13.0   Create deep copies (clones) of your objects
nikic/php-parser                 5.4.0    A PHP parser written in PHP
paragonie/constant_time_encoding 3.0.0    Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)
paragonie/random_compat          9.99.100 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phar-io/manifest                 2.0.4    Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                  3.2.1    Library for handling version information and constraints
php-mock/php-mock                2.6.1    PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fa...
php-mock/php-mock-integration    3.0.0    Integration package for PHP-Mock
php-mock/php-mock-phpunit        2.13.0   Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespac...
phpmailer/phpmailer              6.6.4    PHPMailer is a full-featured email creation and transfer class for PHP
phpseclib/phpseclib              3.0.43   PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.
phpunit/php-code-coverage        12.1.2   Library that provides collection, processing, and rendering functionality for PHP code covera...
phpunit/php-file-iterator        6.0.0    FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker              6.0.0    Invoke callables with a timeout
phpunit/php-text-template        5.0.0    Simple template engine.
phpunit/php-timer                8.0.0    Utility class for timing
phpunit/phpunit                  12.0.10  The PHP Unit Testing framework.
psr/log                          1.1.4    Common interface for logging libraries
sebastian/cli-parser             4.0.0    Library for parsing CLI options
sebastian/comparator             7.0.1    Provides the functionality to compare PHP values for equality
sebastian/complexity             5.0.0    Library for calculating the complexity of PHP code units
sebastian/diff                   7.0.0    Diff implementation
sebastian/environment            8.0.0    Provides functionality to handle HHVM/PHP environments
sebastian/exporter               7.0.0    Provides the functionality to export PHP variables for visualization
sebastian/global-state           8.0.0    Snapshotting of global state
sebastian/lines-of-code          4.0.0    Library for counting the lines of code in PHP source code
sebastian/object-enumerator      7.0.0    Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector       5.0.0    Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context      7.0.0    Provides functionality to recursively process PHP variables
sebastian/type                   6.0.2    Collection of value objects that represent the types of the PHP type system
sebastian/version                6.0.0    Library that helps with managing the version number of Git-hosted PHP projects
staabm/side-effects-detector     1.0.5    A static analysis tool to detect side effects in PHP code
theseer/tokenizer                1.2.3    A small library for converting tokenized PHP source code into XML and potentially other formats
@simonLeary42 simonLeary42 changed the title unexpected token "exit", expecting "(" ParseError when trying to mock die Apr 29, 2025
@simonLeary42
Copy link
Author

mocking time this way works fine.

@simonLeary42 simonLeary42 changed the title ParseError when trying to mock die ParseError when trying to mock exit, die Apr 29, 2025
@michalbundyra
Copy link
Member

@simonLeary42 thanks for your time, it's expected behaviour - please see:

Hope it makes sense, thanks.

@simonLeary42
Copy link
Author

That makes sense. Is it possible to detect this and make a more useful error message?

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

No branches or pull requests

2 participants