Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't pear recognize regex in phpt tests?

I'm trying to write a test for a PHPUnit extiontion I'm working on which needs a regex matcher in the expected section of the test.

The documentations of PHPT file states that there is a %r flag which can be used to match regex in the --EXPECTF-- section of the test. You can get more details from: PHPT - Test File Layout

I tried to use it in my tests, but it always fail! So I decided to write a simple test to check the problem and the test looked like this:

--TEST--
Test the %r tag of EXPECTF in phpt
--FILE--
<?php

echo '1';

?>
--EXPECTF--
%r.%r

This test fails when I run it using pear's run-tests command. The .diff file contains the following:

001- %r.%r
001+ 1

It seems as if this tag doesn't get recognized by the tests runner. So I tried to find an example which uses this tag in the tests of the source of PHP. There was only one test to be found using it (inside: php-src-5.3/ext/standard/tests/network/gethostbyaddr_basic1.phpt).

I'm not sure what I'm doing wrong here... Any ideas?

like image 610
Maher4Ever Avatar asked Dec 03 '25 07:12

Maher4Ever


1 Answers

It only works with the run-tests.php that comes with the PHP source distribution (in its root), not with PEAR's version.

PHPRC=. TEST_PHP_EXECUTABLE=./sapi/cli/php php run-tests.php a.phpt
PASS Test the %r tag of EXPECTF in phpt [a.phpt]

If you take a look at PEAR's version in <PHP prefix>/lib/php/PEAR/RunTest.php around line 520, you'll notice it doesn't support %r.

like image 159
Artefacto Avatar answered Dec 05 '25 23:12

Artefacto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!