Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Running PHPUnit on PHP 7.1-Beta 3 #1002

Closed
DragonBe opened this issue Aug 23, 2016 · 7 comments
Closed

Running PHPUnit on PHP 7.1-Beta 3 #1002

DragonBe opened this issue Aug 23, 2016 · 7 comments

Comments

@DragonBe
Copy link

DragonBe commented Aug 23, 2016

Hi,

Just wanted to report I'm hitting a couple of issues running Faker unit tests on PHP 7.1-Beta 3.

See my results at https://gist.github.com/DragonBe/da9da4d9c54ae463a3c7e6ff4a4a0924

BTW, thanks for the good job! Really appreciating Faker 🎖

Here's my PHP Module/Extension list for completion:

[PHP Modules]
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
hash
iconv
intl
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]
@fzaninotto
Copy link
Owner

Thanks for the feedback, please keep us informed of your progress.

@oittaa
Copy link
Contributor

oittaa commented Oct 6, 2016

@DragonBe it's because mt_rand() implementation has changed.

https://github.com/php/php-src/blob/php-7.1.0RC3/UPGRADING

Fixes to random number generators mean that mt_rand() now produces a
different sequence of outputs to previous versions. If you relied on
mt_srand() to produce a deterministic sequence, it can be called using
mt_srand($seed, MT_RAND_PHP) to produce the old sequences.

@oittaa
Copy link
Contributor

oittaa commented Oct 6, 2016

Here's a possible fix to Generator.php:

    public function seed($seed = null)
    {
        if ($seed === null) {
            mt_srand();
        } else {
            mt_srand((int) $seed);
        }
    }

changed to:

    public function seed($seed = null)
    {
        if ($seed === null) {
            mt_srand();
        } else {
            if (PHP_VERSION_ID < 70100) {
                mt_srand((int) $seed);
            } else {
                mt_srand((int) $seed, MT_RAND_PHP);
            }
        }
    }

@oittaa
Copy link
Contributor

oittaa commented Oct 6, 2016

Made a pull request #1045, but one of the tests still fails with PHP 7.1.
https://travis-ci.org/fzaninotto/Faker/jobs/165646578

There was 1 failure:
1) Faker\Test\Provider\UuidTest::testUuidExpectedSeed
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'8e2e0c84-50dd-367c-9e66-f3ab455c78d6'
+'b0367973-37c8-3d64-a9e1-24157824df1c'
/home/travis/build/fzaninotto/Faker/test/Faker/Provider/UuidTest.php:18
--

@oittaa
Copy link
Contributor

oittaa commented Oct 6, 2016

The reason is that the test calls mt_srand() directly, not the provided seed() function.

@oittaa
Copy link
Contributor

oittaa commented Oct 6, 2016

Now all tests pass in #1045 with the latest commit 19dcb90.

@fzaninotto
Copy link
Owner

Fixed in #1045

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants