Setup include path for PEAR on Wamp - php

Installed PEAR and followed the directions on http://www.phpunit.de/manual/current/en/installation.html:
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit.
Then, I created the test:
<?php
# error reporting
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
# include TestRunner
require_once 'PHPUnit/TextUI/TestRunner.php';
# our test class
class ExampleTest extends PHPUnit_Framework_TestCase
{
public function testOne()
{
$this->assertTrue(FALSE);
}
}
# run the test
$suite = new PHPUnit_Framework_TestSuite('ExampleTest');
PHPUnit_TextUI_TestRunner::run($suite);
?>
I included the following in php.ini file and restarted Apache:
include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8"
include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8/pear"
include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8/pear/PHPUnit"
I get Warning: require_once(PHPUnit/TextUI/TestRunner.php) [function.require-once]: failed to open stream: No such file or directory in ...
Why doesn't the include path work? Is it because there is a space in Program files?
Working in Windows XP and WAMP.
EDIT: I updated the path as suggested.
The output of echo ini_get('include_path'); before require_once call is:
.;C:\Program Files/wamp/bin/php/php5.3.8/pear
Also, removing the require_once command throws Fatal error: Class 'PHPUnit_Framework_TestCase' not found in...

By adding those three lines to the ini, the last one will override everything. Only use this one
include_path = ".;C:\Program Files\wamp\bin\php\php5.3.8\pear"
Edit: adding #Gordon comment. We need to keep \pear. Because inner pear libraries are assuming that pear already in the include path.
http://pear.php.net/manual/en/installation.checking.php#installation.checking.cli.modifyingphpini

Related

How to install mysqli (Fatal error: Class 'mysqli' not found) NO mysqli section in phpinfo() [duplicate]

I just deployed my website to a staging environment and am getting the following error:
Fatal error: Class 'mysqli' not found in D:\ClientSites\baileyboiler.com\www\new\php\db.php on line 11
At first I assumed that MySQLI was simply not installed, but running a phpinfo() reveals the following:
To me it looks like MySQLI is installed (though I could be reading this wrong). What should I do?
Code
class DB
{
public static function GetConnection()
{
return new mysqli(DBHOST, DBUSER, DBPASSWORD, DEFAULTDATABASE);
}
}
(line 11 is the return new mysql(...);)
Update
I added extension=php_mysqli.dll to my php.ini located at /Windows/php.ini (according to phpinfo(), this is the one being loaded):
Loaded Configuration File C:\WINDOWS\php.ini
But the error persists. I know that mysqli.dll exists at C:\php\ext - because I can see the file. What now?
I got the error corrected by enabling/editing the following config in php.ini:
1st (uncomment and add config):
include_path = "C:\php\includes"
2nd (uncomment):
extension_dir = "ext"
3rd (uncomment and edit config):
extension=D:/PHP/ext/php_mysql.dll
extension=D:/PHP/ext/php_mysqli.dll
Make sure is enabled under php.ini just find php_mysqli.dll and remove semi-colon and restart apache
Christian Mark is right but I think it need:
4rd Copy php.ini to "C:\Windows". On my computer, need copy it to "C:\Windows", Because phpinfo() output "Configuration File (php.ini) Path: C:\Windows" and "Loaded Configuration File: C:\Windows\php.ini"
5rd login out Computer and login in.
Then it work for me.
If I don't do 4,5rd, It's also don't work for me, the phpinfo output include_path is not my configured. and extension_di also not. run the test also not work.

PHP: Class 'Thread' not found

I know guys, this question has been answered but belive me before I ask it I followed step by step these two questions but still having the same error.
pthread not working in php
PHP pthreads: Fatal error: Class 'Thread' not found
I have added this line extension=php_pthreads.dll to the php.ini file located in the apache directory C:\wamp\bin\apache\apache2.4.9\bin\php.ini.
Also I have the file pthreadVC2.dll under C:\wamp\bin\apache\apache2.4.9\bin, and the file php_pthreads.dll under C:\wamp\bin\php\php5.5.12\ext.
After that I restarted the wamp server and checked the php_pthreads extension and it's activated.
I did everything as described but still facing this error.
This is my class that extends from Thread:
class MyThread extends \Thread
{
public function run()
{
echo 'This is a thread';
}
}
And this is how I called it:
$myThread = new MyThread();
$myThread->start();
You should use pthreads 2.0.10 for PHP version 5.5.12. You should also try copying pthreadVC2.dll and php_pthreads.dll at your c:/windows/system32 directory.

require_once: No such file or directory 'HTTP/Client.php';

I am working on ubuntu 12.04. I installed HTTP_Client by sudo pear install HTTP_Client. But when I am using require_once 'HTTP/Client.php';. It's showing:
Warning: require_once(HTTP/Client.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /var/www/mai.php on line 3
How I remove this error?
How paths are resolved when using include or require is controlled by the include_path php.ini setting, which is typically set to:
include_path=".:/usr/share/php"
Whereby /usr/share/php points to where PEAR is installed.
It can be set using set_include_path() during runtime as well:
set_include_path(".:/usr/share/php");
Should be run before you include anything else.
'HTTP/Client.php' is a relative path. The error message means that the file doesn't exist at that location. You'll need to modify the path, or move the file.
In this case your PHP file is in "/var/www/" and there is no HTTP directory there.
Edit: I would recommend modifying the path to be the full path rather than the relative path:
require_once 'HTTP/Client.php';
Change to:
require_once '/usr/share/php/HTTP/Client.php';

Installing and working with PHPUnit

I am having a hard time trying making PHPUnit work. My Directory is for php is C:/wamp/bin/php/php5.4.3 Now, I read PHPUnit does not work without PEAR, so I got the go-pear.phar file and placed it in C:/wamp/bin/php/php5.4.3/PEAR/ ran the go-pear.phar file and installed in on the system. third, I installed PHPUnit using Git Bash and put it in C:/wamp/www/local/unit-testing/ (Not sure if the directories are correct)
Now, I created a simple UserTest file
<?php
require_once "phpunit/PHPUnit/Autoload.php";
require_once "User.php";
class UserTest extends PHPUnit_Framework_TestCase
{
protected $user;
// test the talk method
protected function setUp() {
$this->user = new User();
$this->user->setName("Tom");
}
protected function tearDown() {
unset($this->user);
}
public function testTalk() {
$expected = "Hello world!";
$actual = $this->user->talk();
$this->assertEquals($expected, $actual);
}
}
And tried to require this file and run it from the command line in Windows. But, due to lack of instructions on where this files should exactly be, I can't seem to run it.
As of now the problem is command line does not recognize the PEAR command. Even though, I had run PEAR_ENV.reg file to add PATH variables to the file.
secondly, I am not sure where exactly PEAR & PHPUnit should be installed in my current structure. I keep all my php pages/project in C:/wamp/www/local/<-- I need to test files in this directory.
The PHPUnit batch file should be in your path. Then running PHPUnit from the command line would be done in a shell, with the current directory being where you have installed everything, and it assumes that your User.php file is there as well.
I sue a bootstrap.php file to run from my source code directory.
<?php
/**
* This file is used to configure the basic environment for testing in PHPUnit.
*/
// PHP and Web server settings
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set("America/Toronto"); // Set the default timezone
$_SERVER['SERVER_NAME'] = 'http://xxx'; // Set Web Server name
// Process the Include Path to allow the additional applications to be set.
$IncludePaths = explode( PATH_SEPARATOR, get_include_path() );
$NewIncludePaths = array_merge( $IncludePaths, array(dirname(__FILE__) ));
set_include_path( implode( PATH_SEPARATOR, array_unique($NewIncludePaths))); // Update Include Path
//define('PHPUNIT_RUNNING', 1); // Indicate to the code that Automated Testing is running.
?>
I was able to follow the PEAR Installation Instructions for PHPUnit and get things up and running once the directory where PHPUnit.bat existed was in my DOS Path.

PHPUnit out of box not working on OSX

Installed PHPUnit via PEAR and copied the latest repository from https://github.com/sebastianbergmann/phpunit/
Wrote a basic test and saved it in the root directory (also tried /Tests/)
<?php
require_once 'PHPUnit/Autoload.php';
class CalculatorTest extends PHPUnit_Framework_TestCase{
public function testAdd(){
$c = New Calculator();
$result = $c->add(5, 10);
$this->assertEquals(15, $result);
}
}
Throws errors about not being able to load require_once(SebastianBergmann/Diff/autoload.php) In the PHPUnit/Autoload.php there is three lines, 69, 70 and 71.
require_once 'SebastianBergmann/Diff/autoload.php';
require_once 'SebastianBergmann/Exporter/autoload.php';
require_once 'SebastianBergmann/Version/autoload.php';
The directory SebastianBergmann doesn't even exist.... why are these lines in here?
What am I doing wrong, did I copy from the wrong place?
Also trying to run /Tests/Runner/BaseTestRunnerTest.php fails with Class 'PHPUnit_Runner_BaseTestRunner' not found
You cannot just clone it and expect to work. Either completely install via PEAR or composer.
As of those particular references - they are satisfied as composer dependencies: see here https://github.com/sebastianbergmann/phpunit/blob/master/composer.json#L32

Categories