9

Note : I've read all questions about this problem

PEAR is installed and configured on my system (Ubuntu 11.10 + Apache/2.2.20). Because

<?php
require_once 'System.php';
var_dump(class_exists('System', false));
?> 

Returning this :

bool(true)

(PEAR Manual : Checking if PEAR works Step 4)

When i tried to use phpunit i'm getting this error.

PHP Warning:  require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 38
PHP Fatal error:  require_once(): Failed opening required 'PHP/CodeCoverage/Filter.php' (include_path='.:/usr/share/php:/usr/share/pear') in /usr/bin/phpunit on line 38

After this error i've decided to install it

sudo /usr/bin/pear install phpunit/PHP_CodeCoverage

But i'm getting

phpunit/PHP_CodeCoverage requires PEAR Installer (version >= 1.9.4), installed version is 1.9.2

I'm getting this error when upgrading PEAR with sudo pear upgrade

PHP Fatal error:  Call to undefined method PEAR_Registry::packageinfo() in /usr/share/php/PEAR/Dependency2.php on line 687

I'm not sure what is the problem ?

ADDITIONAL

(command : result)

/usr/bin/pear config-get php_dir : /usr/share/php

Configuration File (php.ini) Path (on phpinfo();) : /etc/php5/apache2

php -c /etc/php5/apache2/php.ini -r 'echo get_include_path()."\n";' : .:/usr/share/php

pear upgrade pear : PHP Fatal error: Call to undefined method PEAR_Registry::packageinfo() in /usr/share/php/PEAR/Dependency2.php on line 687

PEAR Version : 1.9.2 and php-pear package installed.

Eray
  • 7,038
  • 16
  • 70
  • 120
  • Whats your current PEAR version? Also did you install `php-pear` with apt-get or did you do a manual install? – prodigitalson Jan 21 '12 at 01:46
  • PEAR Version : 1.9.2 . I've installed php-pear – Eray Jan 21 '12 at 01:50
  • @cweiske , `PHP Fatal error: Call to undefined method PEAR_Registry::packageinfo() in /usr/share/php/PEAR/Dependency2.php on line 687` – Eray Jan 22 '12 at 00:33
  • @Eray: I published an article on how to install PHPUnit without PEAR. Take a look and see if will help you get PHPUnit going again, either way can you let me know what you thought? If it worked I'd like to post as an answer to your question. http://melikedev.com/2012/01/25/php-phpunit-use-phpunit-without-pear/ – Mike Purcell Jan 26 '12 at 17:35

4 Answers4

9

PEAR 1.9.2 is outdated and broken beyond any hope of repair with newer pear server infrastructure.

I have no clue why distributions still insist on something that is just broken :)

Install a new pear via go-pear.phar and make sure you have pear version 1.9.4 and then force pear to ignore it's old cache files using

sudo pear install --force --alldeps phpunit/phpunit

Getting rid of the old pear:

sudo apt-get purge php5-pear

Now

which pear

should result in the command not being found. If it is still there delete the binary and the associated php classes in /usr/share/php.

From your console history I'd say you didn't install the new pear with sudo rights so it landed in /home/ or in /usr/local/ instead of in the default system location.

It shouldn't matter as long as you

  • Get rid of the old pear
  • Change your php.ini include_path to the new pear install location
Community
  • 1
  • 1
edorian
  • 38,542
  • 15
  • 125
  • 143
  • I'm getting `Unknown Role class: "PEAR_Installer_Role_Pear_Installer_role_php` error while installing PEAR. You can check here : http://pastebin.com/jkH4AAkJ as you can see version still 1.9.2 – Eray Jan 21 '12 at 17:46
  • You're hitting http://stackoverflow.com/a/6596669/282601 - remove php-pear first. – cweiske Jan 22 '12 at 00:28
  • @cweiske , it's not solve my problem. Because , `dpkg -L php-pear` and `pear config-get php_dir` are both same, pointing to `/usr/share/php` – Eray Jan 22 '12 at 00:39
  • @cweiske no i executed this command : `apt-get remove php-pear` . And then installed a new pear via *go-pear.phar* but this it's installed to `/home/eray/pear/bin/pear` . I'm really confused, totally. – Eray Jan 22 '12 at 00:48
  • @Eray Expanded a little on the answer – edorian Jan 23 '12 at 09:20
  • @edorian i removed my old pear installation (*php5-pear*), yesterday. I record a little screencast. Can you watch this : http://screenr.com/Ebas **notice** this error on last screen : `** WARNING! Old version found at /usr/bin, please remove it or be sure to use the new /usr/bin/pear command` – Eray Jan 23 '12 at 18:21
  • @Eray That error message is just complaining that there is already a pear executable in your path. Simply do a `rm /usr/bin/pear` to zap the old executable then perform the same reinstall steps and you won't receive the warning. –  Jan 24 '12 at 18:17
  • @Eray you might try the answer I just posted in its entirety and let me know if you still have issues from there ... –  Jan 24 '12 at 18:31
3

It can be difficult to troubleshoot for a specific environment ... but, here goes ...

I've had issues when not using the actual pear.phpunit.de channel to install PHPUnit, especially when trying to use a package manager like apt-get or yum. First, you need to be sure your pear installation is up to date. Kill the existing install from your package manager:

  • sudo apt-get purge php5-pear

Then make sure you delete the executable binary file if it still exists. This is probably /usr/bin/pear, but you may need to modify the path based on your environment:

  • rm /usr/bin/pear

Next install the new pear by downloading go-pear.phar and executing it. Make sure you install it with sudo rights (or as root) so that it is installed in the correct location:

You can then verify that pear works by executing the next command. If so, you'll get a list of commands:

  • pear help

Finally, upgrade pear (just in case -- you did just get the latest version using go-pear.phar, after all). After this, make sure you use the actual pear.phpunit.de channel to install PHPUnit:

  • sudo pear upgrade PEAR
  • sudo pear config-set auto_discover 1
  • sudo pear install --alldeps pear.phpunit.de/PHPUnit

This has worked well for me ... hope it helps.

UPDATE

To get all the features of PHPUnit working you'll likely need to also do the following:

  • sudo pear install pear.phpunit.de/PHPUnit_MockObject

You'd think --alldeps would cover this but ...

UPDATE 2

This method won't work with the current Ubuntu 11.10 because it installs the broken pear installer 1.9.2 ...

Here's an alternative method given your continued issues using the go-pear.phar install method ...

  • sudo apt-get install php-pear

Next, tell PEAR to update its own channel.

  • sudo pear channel-update pear.php.net

Then, tell PEAR to upgrade itself to the newest version.

  • sudo pear upgrade-all

Finally, install PHPUnit as proscribed above ...

  • sudo pear config-set auto_discover 1
  • sudo pear install --alldeps pear.phpunit.de/PHPUnit
  • Recently i don't have any pear installation (i think) . Because when i tried to execute `pear` or `/usr/bin/pear` command. I'm getting error like *pear isn't installed* . And all other commands, you said returning an error. I said them before, in my question. – Eray Jan 24 '12 at 18:38
  • i just try install it again. While installing i set `/usr/bin` as my *Binaries directory* . After installation i got `** The 'pear' command is not currently in your PATH, so you need to ** use '/usr/bin/pear' until you have added ** '/usr/bin' to your PATH environment variable.` this notification. And then i'm executing `pear help` and `/usr/bin/pear help` commands but getting `pear iisn't installed` and `there is no file like usr/bin/pear` errors. – Eray Jan 24 '12 at 18:50
  • @Eray You just need to reference pear in your environment path somewhere. You can follow the instructions in this SO post to make that happen: [Ubuntu: How to link a binary](http://stackoverflow.com/questions/4608496/ubuntu-how-to-link-a-binary) –  Jan 24 '12 at 18:56
  • there isn't pear file on /usr/bin – Eray Jan 24 '12 at 19:03
  • Oh, ok i misunderstood. BUt what should be content of this file ? Why it's automatically created when we install pear with phar ? – Eray Jan 24 '12 at 19:11
  • It *is* automatically created when you install with go-pear.phar. Your issue is making sure that wherever it's installed, it can be accessed from your path. So, if it's installed to `/home/eray/pear/bin/pear` as you mention in the comments to the other answer, you need to create a symlink in `/usr/bin` or `~/bin` to that file (wherever it was installed). For example: `ln -s /home/eray/pear/bin/ ~/bin` ... which is why I referenced [Ubuntu: How to link a binary](http://stackoverflow.com/questions/4608496/ubuntu-how-to-link-a-binary) in my earlier comment. –  Jan 24 '12 at 19:18
  • Nothing more I can add ether. *maybe* removing /usr/lib/php5/ too just in case. All in all really solid an complete answer. definitely +1 – edorian Jan 24 '12 at 19:26
  • I have tried them (with sudo) : `ln -s /home/eray/pear/bin/ ~/bin` , `ln -s /home/eray/pear/bin/ /usr/bin` . But still getting `pear isn't installed when tried this : 'pear help' or `pear version` – Eray Jan 24 '12 at 19:31
  • `locate /home/eray/pear/bin/pear` outputing *nothing* :) I'm really tired . I think there isn't any pear installation on my machine. Because `require_once 'System.php'; var_dump(class_exists('System', false))` outputting just blank page, too. – Eray Jan 24 '12 at 19:41
  • @rdlowrey , http://screenr.com/385s :D On last screen i was trying to say : *BUt it say's `The 'pear' command is now at your service at /usr/bin/pear` * haha :) – Eray Jan 24 '12 at 20:03
  • Haha that's a little funny :) I'm going to update the answer with a different method to install pear. Hopefully this one won't leave you pulling your hair out ... now updated. –  Jan 24 '12 at 20:12
  • @rdlowrey `sudo apt-get install php5-pear` => `php5-pear` package couldn't located :D – Eray Jan 24 '12 at 20:29
  • @rdlowrey `PEAR Version: 1.9.2 PHP Version: 5.3.6-13ubuntu3.3 Zend Engine Version: 2.3.0 Running on: Linux eray-ubuntu 3.0.0-15-generic-pae #25-Ubuntu SMP Mon Jan 2 19:40:15 UTC 2012 i686 ` – Eray Jan 24 '12 at 20:47
  • Okay, so it seems the only way it's going to work is to use the go-pear.phar installer. Remove the `apt-get php-pear` again and execute the go-pear.phar install steps. Even though the installer lies about /usr/bin/pear being at your service, it **must** be on the machine somewhere. Try a `locate pear` after the install and figure out where the binary executable was installed. It seems the only option is to figure out where it's located and create the appropriate symlink. Once you find the *actual* location of the executable, attempt to run it and see if you can get expected output from pear –  Jan 24 '12 at 20:59
  • How much of the comment stream can be cleaned up? It looks like everything before @Eray comment about update 2 would be appropriate to be cleaned up. – casperOne Jan 24 '12 at 21:00
  • @rdlowrey i found it ! It's `/usr/bin/pear~` – Eray Jan 24 '12 at 21:05
  • @rdlowrey , i was renamed it from `pear~` to `pear` :D Haha i'll undo it. And try it . and then i'll delete comments. – Eray Jan 24 '12 at 21:10
  • `pear install --alldeps pear.phpunit.de/PHPUnit` => `bash: /usr/bin/pear there is no file` and `pear~ install --alldeps pear.phpunit.de/PHPUnit` => `Could not open input file: /usr/share/php/pearcmd.php` – Eray Jan 24 '12 at 21:13
  • first, what does `pear -V` give you? Also, what output do you get for `locate pearcmd.php`? –  Jan 24 '12 at 21:17
  • (It name is `pear~` recently) . `pear~ -V` => `Could not open input file: /usr/share/php/pearcmd.php` AND `locate pearcmd.php` => nothing. – Eray Jan 24 '12 at 21:21
  • Okay, do you get anything from `pear~ config-get php_dir` ? –  Jan 24 '12 at 21:22
  • `pear~ config-get php_dir` => `Could not open input file: /usr/share/php/pearcmd.php` – Eray Jan 24 '12 at 21:23
  • Sometimes people have to restart the whole machine physically, probably due to PATH changes not propagating correctly. Before wasting hours and after you tried everything else, you might give that one a try and lemme know if that fixes it ... –  Jan 24 '12 at 21:25
  • Well perhaps it's possible that symlinks you created before are intercepting the pear command before it gets to /usr/bin/pear ??? you might check your *~/bin* directory to ensure there's nothing there to interfere as well as the */home/eray/pear/bin/pear* directory. Also, I would `rm /usr/bin/pear /usr/bin/pear~` and try the pear install again with go-pear once you know for sure that `/usr/bin/pear` doesn't exist. –  Jan 24 '12 at 21:42
1

I got mine working by doing a manual installation.

Community
  • 1
  • 1
mpen
  • 272,448
  • 266
  • 850
  • 1,236
  • 1.9.4 (says at bottom of Q), but the manual installation shouldn't require any usage of pear. – mpen Jan 25 '12 at 22:03
  • i'm getting `PHP Fatal error: Class 'PHPUnit_TextUI_Command' not found in /usr/share/php/phpunit/phpunit.php on line 46` error. – Eray Jan 29 '12 at 22:01
  • @Eray: Does `phpunit` on it's own run, or do you get that error when you try to run your tests? I discovered I actually had an error in my test class, but `phpunit` itself was fine. Actually, I don't think your `phpunit.php` *should* contain a reference to that class...what's your phpunit.php look like? – mpen Jan 29 '12 at 22:33
  • I'm getting this error when i tried to launch just `phpunit` command. I'm not trying any php file. – Eray Jan 30 '12 at 18:14
  • @Eray: You sure you don't have some old phpunit code lying around? Try `which phpunit` and make sure it's running the right one. – mpen Jan 30 '12 at 21:38
1

I've just upgraded my Ubuntu system and I've got PEAR 1.9.4 stable. Run

sudo apt-get update
sudo apt-get upgrade

to get your Ubuntu synchronised and up to date.

If you were still struggling with the versions as above my suggestion is to install a previous version of PHP_CodeCoverage that is compatible with your phpunit. Before I upgraded my system, I had phpunit-3.5.15 (stable), PHP_CodeCoverage 1.0.5 (stable) installed with PEAR 1.9.2. If this is your phpunit version

sudo pear install PHP_CodeCoverage-1.0.5

should install PHP_CodeCoverage with PEAR 1.9.2.

I hope this helps and you get your unit tests running.

Al_
  • 1,481
  • 1
  • 11
  • 22