PHPUnit fatal error and include_path - php

I just installed PHP and PEAR on my Mac OSX using MacPorts and then installed PHPUnit using PEAR. When I try to run PHPUnit, I get the following error message:
$ phpunit StackTest.php
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
PHP Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Okay, so the file File/Iterator/Autoload.php isn't in my include_path, so I tried
$ ls -l /opt/local/lib/php/File/Iterator/Autoload.php
-rw-r--r-- 1 root admin 2682 May 23 14:38 /opt/local/lib/php/File/Iterator/Autoload.php
$ phpunit --include-path /opt/local/lib/php StackTest.php
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
PHP Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
It's still not working, and the it's not including the new path that it should be. Does anybody know what I can do about this? (I'd rather not modify my php.ini file if I can help it because it's read-only and I'm fairly new to PHP and don't want to mangle it in ways I don't understand.) Thanks.

Still don't have an answer for why --include-path on the command line isn't working, so here's what I did:
$ which phpunit
/opt/local/bin/phpunit
$ sudo emacs /opt/local/bin/phpunit
The plan is to modify the php.ini file, so first I had to figure out which php.ini was initializing phpunit. If anyone has a better way to do this, I'm happy to hear it. I added the following line to the phpunit code right after the <?php opening tag:
echo php_ini_loaded_file();
Now, when I ran phpunit, I got the following (here truncated) output:
/opt/local/etc/php5/php.iniPHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45...
Then:
$ sudo emacs /opt/local/etc/php5/php.ini
I searched for the include_path directive and appended :/opt/local/lib/php to the end. So now, phpunit works, although I have no idea if I broke anything else in terms of my setup.

I had a similar problem with a Windows install, but I am not sure that it is the same problem on OSX. I found the that the PEAR install created the wrong path in the batch file used to launch the program.
The standard install causes the installed batch files to have errors. The final script line of the pear.bat batch file needs to have the include_path wrapped in single quotes ("include_path='%VARIABLE%'").
The change I made is:
"%PHP_PEAR_PHP_BIN%" -C -d memory_limit="-1" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" -d variables_order=EGPCS -d open_basedir="" -d output_buffering=1 -d "include_path='%PHP_PEAR_INSTALL_DIR%'" -f "%PHP_PEAR_INSTALL_DIR%\pearcmd.php" -- %1 %2 %3 %4 %5 %6 %7 %8 %9
I am not sure if you have a similar problem to the one above for your install.
Failing that, my batch file for PHPUnit on Windows 7 is
if "%PHPBIN%" == "" set PHPBIN=C:\Program Files (x86)\PHP\php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "C:\Program Files (x86)\PHP\phpunit" %*

A less invasive way (without changing the php.ini permanently) is to include the following line in the script that fails: set_include_path("/opt/local/lib/php/");
The location you are including might be slightly different. If this doesn't work, search for a file called Autoload.php that is in a folder structure like this: File/Iterator/Autoload.php and use the path to File as the path in set_include_path().

Related

Error while using running chat application in CodeIgniter 4

Downloaded a git repo for a chat application using the below link
Git Repo for Chat Application
Then changed the env file to .env file and also uncommented default database block as shown below.
database.default.hostname = localhost
database.default.database = chat
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi
Then opened terminal and executed this command php spark migrate
But while executing this error pops up
PS C:\xampp\htdocs\Codeigniter-4-Chat-Tutorial> php spark migrate
PHP Warning: require(C:\xampp\htdocs\Codeigniter-4-Chat-
Tutorial\app\Config/../../vendor/codeigniter4/framework/system/bootstrap.php): failed to
open stream: No such file or directory in C:\xampp\htdocs\Codeigniter-4-Chat-Tutorial\spark on line 44
Warning: require(C:\xampp\htdocs\Codeigniter-4-Chat-
Tutorial\app\Config/../../vendor/codeigniter4/framework/system/bootstrap.php): failed to open
stream: No such file or directory in C:\xampp\htdocs\Codeigniter-4-Chat-Tutorial\spark on line 44
PHP Fatal error: require(): Failed opening required 'C:\xampp\htdocs\Codeigniter-4-Chat-
Tutorial\app\Config/../../vendor/codeigniter4/framework/system/bootstrap.php'
(include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\Codeigniter-4-Chat-Tutorial\spark on line 44
Fatal error: require(): Failed opening required 'C:\xampp\htdocs\Codeigniter-4-Chat-
Tutorial\app\Config/../../vendor/codeigniter4/framework/system/bootstrap.php'
(include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\Codeigniter-4-Chat-Tutorial\spark on line 44
PS C:\xampp\htdocs\Codeigniter-4-Chat-Tutorial>
How to resolve this? Any help appreciated.
It looks to me that you didn't run the composer update command after starting the project. So in this case your vendor folder is probably missing a lot of files.
Go to the root of your project in the terminal and run:
$ composer update
And you should be fine.

PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0

I start with PHP, wampserver and Composer on windows 10 and it will be a week that I can not fix this problem: When I type:
php -S localhost:8000 -d display_errors = 1 public/
on the browser by running: "localhost:8000/test", I have this error:
Warning: Unknown: failed to open stream: Permission denied in Unknown
on line 0
Fatal error: Unknown: Failed opening required 'public/' (include_path
= '.;C:\wamp64\bin\php7.1.9\pear') in Unknown on line 0
I installed the famous "pear", I modify the access mode to my project with:
chmod -R 777 or 755 myFramework
I even touched php.ini in apache folder and in php folder to add this line :
include_path
= '.;C:\wamp64\bin\php7.1.9\pear'
But nothing is working ! Can you help me ?
The command line is wrong.
From man php or from the PHP CLI online Manual :
First
--define foo[=bar]
-d foo[=bar] Define INI entry foo with value bar
(note that there is no space before and after the = sign)
Second
--docroot docroot
-t docroot Specify the document root to be used by the built-in web server
(you need to specify the document root with the -t parameter)
So, the final command will look like this :
php -S localhost:8000 -d display_errors=1 -t public/
And it should work as expected.

Phing execute error : Fatal error: require_once(): Failed opening required

I have a problem with phing.
I want to start phing in the commandline with " :> phing " but if I do this, I get this error:
Warning: require_once(phing/Project.php): failed to open stream: No
such file or directory in C:\develop\php\pear\pear\phing\Phing.php on
line 19
Fatal error: require_once(): Failed opening required 'phing/Project.php'
(include_path='C:\develop\php\pear\pear/../classes;.;C:\php\pear') in
C:\develop\php\pear\pear\phing\Phing.php on line 19
I installed Apache and php. This worked.
I tested using
php -c "c:/develop/php/php.info" -r "echo get_include_path();"
and got
-> .;C:\php\pear
What can I do. I looked here but this not help me:
Reference
Your include path is not setup correctly.
Run $ pear list-files phing/phing and have a look at the first php file. It will have a path C:\develop\php\pear\pear\phing\....
Edit your php.ini and append that path to the include path:
include_path=C:\develop\php\pear\pear;.;...

error: require(): Failed opening required file

i am getting the following errors when i am trying to include a file.. i have tried chmod 777 for the directory..checked twice ,the path is correct ..but still the errors persist
the errors are:
Warning: require(../lib/GoogleChart.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/project1/admin/googlechart/examples/line_chart_full.php on line 3
Fatal error: require(): Failed opening required '../lib/GoogleChart.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/project1/admin/googlechart/examples/line_chart_full.php on line 3
What might be wrong is it with the permission cause i have done chmod -R 777 on the directory
You coul try with absolute path starting from documen root (if you have no needs to run the script in command line because $_SERVER array is not provided if the script is launched by a shell)
require($_SERVER['DOCUMENT_ROOT'] . "/lib/GoogleChart.php";
Giving that the lib directory is in the root (www.example.com/lib/GoogleChart.php).
I would suggest require_once instead

Running PHPUnit on command line errors out

I run this on the command line: phpunit --version
I get the following errors:
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /usr/lib/php/pear/PHPUnit/Autoload.php on line 45
PHP Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/Users/dennismonsewicz/pear/share/pear:/usr/local/share/pear:/usr/lib/php/pear/PHPUnit') in /usr/lib/php/pear/PHPUnit/Autoload.php on line 45
Anyone else run into these issues? It is also causing me issues when I try to run my tests via the command line.
Ended being an issue with my include_path
This is my updated include path
include_path = ".:/php/includes:/usr/lib/php/pear"

Categories