PHPUnit Autoload - No such file or directory - phpunit

Install:
pear install --alldeps pear.phpunit.de/PHPUnit
After manipulation broken uninstall
Reinstalling does not help.
/usr/share/pear$ pear uninstall phpunit/PHPUnit
uninstall ok: channel://pear.phpunit.de/PHPUnit-4.0.9
but, you still see after installation Autoload.php file still does not appear (((
Fatal error: main(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.:/usr/bin:/usr/share/pear:/usr/share/pear/PEAR')
I do not understand how to get to work through phpunit.phar therefore tried to install via pear and even overthrown files directly from GitHub developer.
'm Confused.

You need to modify the Bootstrap file to include the Autoloader and your directories.
My sample:
<?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://myserver'; // Set Web Server name
// Process the Include Path to allow the additional application 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
?>
You then need to specify the bootstrap file when you start PHPUnit.
phpunit --bootstrap bootstrap.php

I also found it a bit annoying to find the Autoloader file.
Mine was located at /usr/share/php/pear/share/pear/PHPUnit/Autoload.php
So I updated my php.ini file to include it include_path=".:/usr/share/php/PEAR:/usr/share/php/pear/share/pear"

run only CLI, not from web .....

Related

Composer installation error - file is not within the allowed path

I am trying to install composer on windows (symfony 2 project). The problem is that I always get some strage errors - that a couple of files are not in the allowed path.
I've tried a couple of methods to install compsoer:
Downloading raw composer.phar file, throwing it into the symfony2 root folder and running composer installation command. It gives me an error that usr/.../composer/.htaccess is not within the allowed path
php -r "path" gives similar results as above, but with more "not in the allowed path" errors
Windows installer - it throws an error that the installer couldn't execute php.exe file, no idea why.
What's wrong?
Adjust open_basedir in your php.ini to include the path to your project and the other paths that composer tries to load from/write to. The variable accepts multiple paths separated by : (unix) or ; (windows).
open_basedir = "/home/sites/yoursites/:/tmp/:/"
... or remove the restriction completely from php.ini.
; remove open_basedir completely ...
; <nothing here>
; ... comment it out like this ...
; open_basedir = "..."
; ... or set it to an empty value like this ...
open_basedir =
You can find the location of the correct php.ini for the CLI sapi with:
php --ini
First, you should make sure that the path of php.exe is in your ENV (Environment variable);
Second, if composer's windows installer can't install, just try to use "Run With Administrator Permission", and if it also does not work, just comment me your error.

Symfony 2 - How to determine the namespace and Bundle name for autoload.php & Appkernel.php

I'm very new to symfony2 and I cannot find this info:
To register a bundle located in my vendor dir, how to determine the namespace and Bundle name for autoload.php & Appkernel.php?
For example, I have downloaded Luiggio's PHPExcel Bundle. I have place it in vendorDir/ExcelBundle/
Where content is:
namespace Liuggio\ExcelBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class LiuggioExcelBundle extends Bundle
{
}
What lines should I put in Appkernel and namespace.php?
This and this does not work:
new Liuggio\ExcelBundle\LiuggioExcelBundle()
//'Liuggio\\ExcelBundle' => array($vendorDir. '/PHPExcel'),
I cannot use composer or github repo at all, too many proxies and restrictions where I am.
You shouldn't place bundles in your vendor directory manually. Let Composer do this for you. Not only does Composer know where vendor libraries / bundles should be located, it also adds them to your autoload files and performs some other automated tasks.
To tell Composer which libraries are required, you should add them to your composer.json:
"require" : {
(...)
"liuggio/ExcelBundle": "~2.0"
},
Next, using the command line, run the composer update command:
$ php composer.phar update
(if you don't have a file composer.phar in your project directory, but you have Composer installed globally instead, use the following:)
$ composer update
This will tell Composer to download the required dependencies, update the autoload script, etc, all automatically. When it's finished, you're ready to go.
If you can't use Composer on your server, then run it locally before you upload your files (although I strongly recommend moving to a server that does allow you to use Composer).
The line you're trying to add to AppKernel.php is correct, however it only works after running Composer (or you'd indeed have to download the files and update the autoloader manually, but I'd strongly recommend against that).
Edit
If you really can't use Composer, do the following:
Place the files of ExcelBundle in the following directory:
vendor/liuggio/ExcelBundle/Liuggio/ExcelBundle
Your line in AppKernel.php was already correct.
Add this line to autoload_namespaces.php:
'Liuggio\\ExcelBundle' => array($vendorDir . '/liuggio/ExcelBundle'),
Last but not least, complain to your system administrator that he's making your work impossible with his stupid security measures.
new Liuggio\ExcelBundle\LiuggioExcelBundle(),
in AppKernel should be working fine.
This is the namespace of the LuiggioExcelBundle class + the class name. Look how your bundles are loaded, its the same.
What's your error?
You say vendorDir/ExcelBundle/ but its vendor/ExcelBundle right?
And what do you mean by namespace.php? :o
https://github.com/liuggio/ExcelBundle ==> there readme is rly easy to understand, it should help you.
For your "proxies and restriction", composer is a powerful tool, I can help you to use it. Download this soft, the free version is enough http://www.frozenway.com/ (if you cant read french, the 1st input in the header is to translate the website, English is Anglais) With this, you wont have any ports restriction.

PHPUnit Never uses the correct include_path

I've recently installed PHPUnit on a Mac (10.8.3) (running PHP 5.4.7). When I attempt to a run a test phpunit testfile.php for example, I receive:
Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or
directory in /Users/myusername/pear/share/pear/PHPUnit/Autoload.php on line 64
Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php'
(include_path='.:') in /Users/myusername/pear/share/pear/PHPUnit/Autoload.php on line 64
The file, /Users/myusername/pear/share/pear/File/Iterator/Autoload.php exists.
php.ini correctly lists the pear directories in the include path:
.:/php/includes:/usr/local/apache/lib/php:/Users/myusername/pear/share/pear/
Yet when I var_dump(get_include_path()); inside of the PHPUnit/Autoload.php file, it prints .: as if it's empty.
Dumping the value of php_ini_loaded_file instead, simply returns false.
Using php -i |grep php\.ini and php --ini only show one php.ini being used/loaded:
Configuration File (php.ini) Path => /usr/local/apache/lib
Loaded Configuration File => /usr/local/apache/lib/php.ini
I repeated the var_dumps of the include_path and the loaded_ini_file from a simple test.php file I ran from the command line and they print out the correct info. So something involved with phpunit is not loading the right/any php.ini.
I'm not using any configurations that are different than default - phpunit was just installed on this machine today.
Make sure the php.ini file you are using is the one loaded for cli php. At least on my install of PHP on Linux, I have two php.ini files, one at /etc/php/cgi-php5.4/php.ini, and the other at /etc/php/cli-php5.4/php.ini. If you change the cgi version, it won't by default affect the cli version, and would cause the include path to be empty.
Another place to check is the phpunit.xml file. It has a section to specify the include path. See here for options available. I'm not sure why phpunit would reset the path but this might be a way to solve the issue.
The solution was:
After running
`pear config-get php_bin` -i | grep -E Configuration\ File\|include_path
It showed that Pear was using a different ini path than php-cli was:
Configuration File (php.ini) Path => /etc
Loaded Configuration File => (none)
include_path => .: => .:
Turns out, Pear had been configured by the original/default Mac OS copy of PHP, not by the custom version I had installed later on.
A quick fix that may not be best long-term was to symlink the ini file it was trying to find:
sudo ln -s /usr/local/apache/lib/php.ini /etc/php.ini
Afterwards, phpunit FakeTest commands are work, and the tests run.
Eventually I need to re-install/re-configure Pear to work with the version of php I've loaded.

Symfony 2, adding vendor library (PHPExcel etc.)

In my symfony 2.2 app I wanted to use PHPExcel library. So I downloaded it, and copied contents of Classes library to /vendor/phpexcel directory:
vendor/
phpexcel/
PHPExcel/
PHPExcel.php
After that I added the following to app/autoload.php directly below $loader = require ... line:
$loader = require __DIR__.'/../vendor/autoload.php';
//The following was added
$loader->registerPrefixes(array(
'PHPExcel' => __DIR__ . '/../vendor/phpexcel'
));
// intl
...
Now if I browse to my web app, it returns HTTP Error 500 (Internal Server Error). I read the following post, but wasn't able to solve the problem:
How to use PHPExcel correctly with Symfony 2
Can someone help me correct this?
You should never manually download something and put it in the vendor directory. Composer manages the vendor directory, and hence it should be save to delete this directory and run composer install again. The vendor directory also is excluded from Git by default.
To install PHPExcel using composer, add it to composer.json:
"require": {
...
"phpexcel/phpexcel": "1.7.*"
}
When installed with Composer, you should not need to worry about the autoloading either.
I installed https://github.com/liuggio/ExcelBundle for PHPExcel. Bundle includes PHPExcel (addes related links to composer). You can easily use PHPExcel without wondering what the bundle says. Call new \PHPExcel(); then you move. I hope this bundle helps.
Composer seems to have a problem with SELinux. See this. Though not recommended, setting SELinux to permissive can be a workaraound.

date_default_timezone_get(): It is not safe to rely on the system's timezone settings

Can anyone tell me why am I getting this error when running app/console in a brand new formatted macbook with the latest MAMP installed ?
Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /../Logger.php line 112
I have checked the path of php.ini and marked out the date.timezone = "Europe/Athens"
Also restarted MAMP/apache several times.
At AppKernel.php write:
public function init() {
date_default_timezone_set( 'Europe/Lisbon' );
parent::init();
}
Since init() is deprecated (and will be remove in Symfony2 3.0) it is recommended to move the code in the constructor as in the following exemple:
public function __construct($environment, $debug) {
parent::__construct($environment, $debug);
// get rid of Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone
date_default_timezone_set( 'Europe/Paris' );
}
Default php.ini in OS X is located at:
/private/etc/php.ini
Anyway, you'll can either tell CLI php to load MAMP settings, or use an alias of MAMP command itself.
You don't edit the good php.ini file
You can get a full phpinfo() using :
php -i
And, in there, there is the php.ini file used :
$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
I had the same problem, and it's true there is a command line, and MAMP/Native Mac PHP service running on Yosemite, and while I was trying to follow the directions on this page non of them seemed to work for me.
When I ran php command:
$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => <em>(Blank)</em>
I realized that the php.ini that the CLI was using, was actually php.ini.default file.
I created a symbolic link to that file as the php.ini and everything worked.
My-MacPro:/etc/$ ln -s php.ini.default php.ini
I did follow your answers, but in my case none of them worked. I decided to go change the
date_default_timezone_get()
in the logger.php file.
I replaced with my timezone setting ("Europe/Berlin"), and all went well !
Old school solution but still a solution.
I had the exact same problem with my SF2 installation.
To fix this just go into your php.ini file at /etc/php.ini and change your file to look like this (adjust your timezone to suit your local timezone):
;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;;;;;;;;;;;;;;;;
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Europe/London
Your default php.in in Mac OSX is located at /etc/php.ini which is exactly the same than the /private/etc/php.ini file.
You should know that you have the possibility of using two php version running in parallel. I had this issue 'cause I was using the native mac osx php, however I had to install a php package through homebrew, then I got the other version of php through homebrew. though I had the time zone already configured in my php.ini file at /etc/php.ini, I still had the same problem, so I run:
php -i | grep 'Configuration File'
in order to configure the correct file, so I got:
Configuration File (php.ini) Path => /usr/local/etc/php/5.3
Loaded Configuration File => /usr/local/etc/php/5.3/php.ini
PHP Warning: Unknown: It is not safe to rely on the system's
timezone settings. You are *required* to use the date.timezone
setting or the date_default_timezone_set() function. In case you
used any of those methods and you are still getting this warning,
you most likely misspelled the timezone identifier. We selected
'America/Buenos_Aires' for 'ART/-3.0/no DST' instead in Unknown on line 0
Then I knew I had to edit the /usr/local/etc/php/5.3/php.ini file.
After that, It all went right. I had not that issue any more.
I hope it helps you to solve that.
Usually, there are separate php.ini files for CLI and Apache. Make sure you've edited the needed one.
By default Mac uses in the console the PHP located at:
/private/etc/php.ini
You should use this one because MAMP always unset the timezone variable and you would always get that error.
I had a similar problem on OS X 10.9.
The problem in my case was the absence of a php.ini file in /etc.
I solved the problem by creating that php.ini file with the contents:
date.timezone = Europe/Athens

Resources