PHP Fatal error when running behat init.php

PHP Fatal error when running behat init.php

by Joanna Beaver -
Number of replies: 8
Picture of Plugin developers

Hello

I have setup behat, selenium, chromedriver, geckodriver, and if I run php admin/tool/behat/cli/init.php I see the following error:

PHP Fatal error:  During inheritance of IteratorAggregate: Uncaught ArgumentCountError: Too few arguments to function default_error_handler(), 4 passed in /home/joanna/development/projname/moodle/lib/navigationlib.php on line 897 and exactly 5 expected in /home/joanna/development/projname/moodle/lib/setuplib.php:425

I am on Linux, NGINX, with a Moodle 3.9 running on PHP7.4 from the nginx serverbox. (If I run php --version I get the laptop general version of PHP 8.3.8. Unsure if this is relevant but saw a previous post that mentioned php versions so thought I'd mention it).

Any idea what is causing the error and how to resolve it?

Thanks!

Jo

Average of ratings: -
In reply to Joanna Beaver

Re: PHP Fatal error when running behat init.php

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
That's almost certainly the PHP version. I suspect that the code is being executed by PHP 8.3.8 (certainly >=8.0). Which would account for that error. I don't know why, unfortunately.
 
I should probably also mention that Moodle 3.9 is out of support by several months. 
In reply to Howard Miller

Re: PHP Fatal error when running behat init.php

by Joanna Beaver -
Picture of Plugin developers

Thanks Howard, that gives me some where to start.

Yes, this is just a local dev site but I have moved to 4.1 dev site running 8.0 to be sure. 

Just to check, where should the vendor files be located? Mine are in 
   projname
        > features
        > vendor  > behat
                  > bin
                  > composer
        > moodle
        > moodledata
The selenium jar is currently just running from Downloads 😬

In reply to Joanna Beaver

Re: PHP Fatal error when running behat init.php

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Vendor is usually within the moodle direcroy. How are you installing behat?
In reply to Andrew Lyons

Re: PHP Fatal error when running behat init.php

by Joanna Beaver -
Picture of Plugin developers
I think I confused the issue by following generic behat installation instructions before switching to the moodle specific ones resulting in my directories being in incorrect place. I have corrected that now and can run the behat init.php.

As you suggested the fpm php was different to the CLI php so I changed the command to specify php version like so:
/usr/bin/php8.0 vendor/bin/behat --config /home/joanna/development/moodle41/moodledata_behat/behatrun/behat/behat.yml

This seems to work and the tests are running. 

Because this is NGINX, I have:
a dev site on a server box with $CFG->wwwroot = 'http://moodle41.test';
the behat site on a server box with $CFG->behat_wwwroot = 'http://behat.moodle41.test';
(unsure if this is correct setup)

If I visit that URL http://behat.moodle41.test/ I get this (so it seems to be ok?)



but when the tests are running I see a popup showing the server page then a 404 and it looks like whatever test its running then Fail

 
Is that as expected or should I be seeing something different here?
 
In reply to Joanna Beaver

Re: PHP Fatal error when running behat init.php

by Joanna Beaver -
Picture of Plugin developers
in the 2 screenshots, the base url is http://127.0.0.1/ and not http://behat.moodle41.test. Could that be what's causing it to error? Should it be showing behat.moodle41.test?

behat.moodle41.test is mapped to 127.0.0.1 in /etc/hosts and I can successfully ping it.
In reply to Joanna Beaver

Re: PHP Fatal error when running behat init.php

by Joanna Beaver -
Picture of Plugin developers
Resolved by updating the base_url in the behat.yml

Thanks everyone for your help smile
In reply to Joanna Beaver

Re: PHP Fatal error when running behat init.php

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

All your PHP instances should be 7.4 when you want to use Moodle 3.9: the PHP client, the PHP nginx module, and perhaps also the PHP-fpm module. 

Perhaps you can uninstall all versions of PHP8?

In reply to Joanna Beaver

Re: PHP Fatal error when running behat init.php

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Jo,

You mention that you're running PHP 7.4, and also PHP 8.3.8.

The set_error_handler() method notes in its docs in relation to the errcontext variable: https://www.php.net/manual/en/function.set-error-handler.php

This parameter has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. If the function defines this parameter without a default, an error of "too few arguments" will be raised when it is called.

Behat initialises on the CLI, so I'd imagine it's getting your 'laptop general version' of PHP, that is 8.3.8,

Your CLI version of PHP should really match your web version. I suspect once you've go that sorted, it will work.