I'm wandering a jungle of "php oil test" command for few days.
I installed phpunit via pear in windows7.
After the installation, When I execute "php oil test" command, following error occurs.
> php oil test
Uncaught exception Oil\Exception: PHPUnit does not appear to be installed.
However, it looks phpunit is installed correctly because "phpunit --version" command works fine(refer following).
>phpunit --version
PHPUnit 4.0.14 by Sebastian Bergmann.
Of course, "pear list" command shows PHPUnit package.
>pear list
INSTALLED PACKAGES, CHANNEL PEAR.PHPUNIT.DE:
PACKAGE VERSION STATE
File_Iterator 1.2.3 stable
PHPUnit 4.0.14 stable
PHPUnit_SkeletonGenerator 1.2.1 stable
PHP_CodeCoverage 1.0.2 stable
PHP_Timer 1.0.0 stable
PHP_TokenStream 1.2.2 stable
Text_Template 1.2.0 stable
I tried some way listed following page, but cannot still resolve.
Installing PHPUnit via PEAR
Could anyone pl give some advice to run "php oil test" command w/o error?
Any advice is welcomed!!
add my code.
/fuel/core/classes/testcase.php
namespace Fuel\Core;
class TestCase extends \PHPUnit_Framework_TestCase { }
/fuel/app/tests/controller_testcase.php
use Fuel\Core\Log;
use Fuel\Core\DBUtil;
use Fuel\Core\DB;
use Fuel\Core\TestCase;
use Fuel\Core\Config;
use Fuel\Core\Request;
class ControllerTestCase extends TestCase {
public function setUp() {
..
php is installed C:\php and pear.bat & phpunit.bat are also there.
PHPUnit folder does not exist in C:\php\pear folder.
Oil uses the configuration key "oil.phpunit.autoload_path" to find the location of PHPUnit autoloader, and if not defined, it uses "PHPUnit/Autoload.php", in combination with the defined PHP include paths.
It then attempts to include this file, and checks if the class "PHPUnit_Framework_TestCase" is available. If not, it bails out with the error message you see.
It has nothing to do with the PHPUnit binary, which is located using the defined path.
This simply means the location where PHPunit is installed is not in PHP's search paths, and no custom path is configured.
Related
I have this exercice folder that gave me instructions on how to install the web application:
So this folder contains a .sh file that installs the necessary things:
npm install
curl -o phpunit -L https://phar.phpunit.de/phpunit-7.phar
chmod +x phpunit
./phpunit --version
So basically this adds a file called phpunit inside root folder. So by far I kind of understand what's going on, so this installs node dependencies and also installs phpunit (I think so), but this project has a test example unit:
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class HelloWorldTest extends TestCase
{
public function testWhenGetDataFromHelloWorld(): void
{
$this->assertEquals('Hello World', 'Hello World');
}
}
At this point is where I don't get how is use PHPUnit\Framework\TestCase; working, since I don't have any folder called PHPUnit, I get that use is something like importing a class, but still, how is this working (when I run the test it does not give me any kind of error)?, also, it appears that vscode detects the import as an error because it seems that it doesn't exist.
My file tree is as follows:
Can someone explain me, please?
This is because all the dependencies are in the phpunit-7.phar file, which was named phpunit by that script.
"The easiest way to obtain PHPUnit is to download a PHP Archive (PHAR) that has all required (as well as some optional) dependencies of PHPUnit bundled in a single file."
PHPUnit - Installing PHPUnit - PHP Archive (PHAR)
I followed the instructions on the official PHPUnit page to install PHPUnit 6.
composer require --dev phpunit/phpunit ^6.0
However, If I go to the project folder and execute phpunit --version then I get PHPUnit 3.7.21 by Sebastian Bergmann..
Why is PHPUnit 3.7.21 installed instead of PHPUnit 6?
I suppose you have xampp installed? It comes with PHPUnit 3.x.x preinstalled with PEAR which strangely can not be uninstalled with pear uninstall. And since its config is in php root folder, that 3-ish version has priority when running phpunit command (even if you have phpunit installed globally) in CMD or PS. How to fix:
Go to xampp/php folder and delete two files phpunit (with no extension) and phpunit.bat. Usually it's enough to prevent older PHPUnit version from being run but let's be on the safer side:
Go to xampp/php/PEAR dir and delete two folders PHPUnit and PHPUnit2.
Go to Control Panel, then navigate System and Security->System and click "Advanced system settings" link on the left. This will open Advanced tab in System Properties window. Click "Environment Variables" button, then under System Variables select "Path" variable and click "Edit..." button. In the new window, click "New" button and type your path to vendor/bin folder (if you already installed PHPUnit for your project there will be phpunit.bat file). By default for xamp it looks like this: C:\xampp\htdocs\yourprojectname\vendor\bin.
Restart your Command Prompt (or PowerShell) window, then type phpunit --version to see the that it's PHPUnit 6.x.x now.
P.S. (If you want latest PHPUnit do not use ^6.0 in require string, since it will install v6.0.0, write it in composer.lock file that will never update PHPunit to the latest e.g. 6.2.1 version atm). Just use
composer require --dev phpunit/phpunit
to install the latest stable version for your project.
You run your global PHPUnit version which is installed in another folder. To get the installed version you have to go to the vendor/bin folder.
vendor/bin/phpunit --version
PHPUnit 6.0.8 by Sebastian Bergmann and contributors.
In newer versions you can run it with bin/phpunit there should be the executable. When you need another PHP-Version then define it before php74 bin/phpunit.
If you use XAMPP, why don't you update XAMPP version of global PHPUnit to desired.
1.
Read this post, which quickly explains what to do:
StackOverflow post
2.
You can get phar file for version you need here:
proper PHPUnit phar file
3.
Which version of PHPUnit you need depends on your PHP version and you can identify it here:
which phar file version you need
Just click on links: PHPUnit 9 - PHPUnit 8 - PHPUnit 7 - PHPUnit 6 - PHPUnit 5 - PHPUnit 4 and read description explaining which PHP version it works with.
I am trying to work with Visual PHPUnit.
When I am using phpunit command its running nicely. No error occurs and my tests running successfully. Output of phpunit --version is as follows:
PHPUnit 4.0.14 by Sebastian Bergmann.
I installed phpunit using PEAR. Output of which pear is as follows:
/usr/bin/pear
On Line #9 of app/config/bootstrap.php of Visual PHPUnit, I set /usr/bin/pear as pear_path.
It shows the following errors when I try to run VPU from browser...
Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in /path_to_vpu/app/config/bootstrap.php on line 83
Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.:/usr/share/php:/usr/bin/pear:/path_to_vpu:/usr/share/php') in /path_to_vpu/app/config/bootstrap.php on line 83
Output of which php is as follows:
/usr/bin/php
My Server is Ubuntu 13.10 Saucy. Output of php -v is as follows:
PHP 5.5.3-1ubuntu2.2 (cli) ....
Output of pear list -c phpunit is as follows:
INSTALLED PACKAGES, CHANNEL PEAR.PHPUNIT.DE:
============================================
PACKAGE VERSION STATE
DbUnit 1.3.1 stable
File_Iterator 1.3.4 stable
PHPUnit 4.0.14 stable
PHPUnit_Selenium 1.3.3 stable
PHPUnit_Story 1.0.2 stable
PHPUnit_TicketListener_GitHub 1.0.0 stable
PHP_CodeCoverage 1.2.17 stable
PHP_Invoker 1.1.3 stable
PHP_Timer 1.0.5 stable
PHP_TokenStream 1.2.2 stable
Text_Template 1.2.0 stable
My question is, why I can't include PHPUnit/Autoload.php?
Edit
My php.ini files (both cli and web) has the following:
include_path = ".:/usr/share/php:/usr/share/pear"
Your include path is probably not setup correctly.
Follow the instructions in the PEAR manual, section "Verifying the include path".
This is what happened to me after PHPUnit upgrade with PEAR. Before upgrade, VPU was working. Also I could not downgrade it via PEAR. After some tweaking, it worked again.
I installed PHPUnit under VPU web directory using composer. Place this composer.json file in VPU web directory.
composer.json
{
"require-dev": {
"phpunit/phpunit": "4.1.*"
}
}
and run composer install. After this, a small change in app/config/bootstrap.php file is needed;
//require_once 'PHPUnit/Autoload.php';
//require_once 'PHPUnit/Util/Log/JSON.php';
// this should be absolute path
require_once '/var/www/.... vpu web path ..../vendor/autoload.php';
and it will work.
I need to install PHPUnit for a web dev project on my Ubuntu box, but am having serious issues. Using suggestions from various sources, I've installed via pear and tried the following:
Currently, phpunit --version returns
PHPUnit 3.7.20 by Sebastian Bergman
when in /usr/share but throws errors everywhere else.
My include path is
include_path = ".:/usr/share/php:/usr/share/php/PEAR:/usr/share/php/File/Iterator"
I've tried different variations ranging from simple /usr/share/php to the full string above. PEAR is in all caps since that is the folder it is in.
Executing with a test case results in
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream:
No such file or directory in /usr/share/php/PHPUnit/Autoload.php on line 64
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. require() /usr/bin/phpunit:43
PHP Fatal error: require_once(): Failed opening required
'File/Iterator/Autoload.php'(include_path='/usr/share/php/libzend-framework-php')
in /usr/share/php/PHPUnit/Autoload.php on line 64
pear list -c phpunit returns
Installed packages, channel pear.phpunit.de:
============================================
Package Version State
File_Iterator 1.3.3 stable
PHPUnit 3.7.20 stable
PHPUnit_MockObject 1.2.3 stable
PHP_CodeCoverage 1.2.10 stable
PHP_Invoker 1.1.2 stable
PHP_Timer 1.0.3 stable
PHP_TokenStream 1.1.5 stable
Text_Template 1.1.2 stable
I've confirmed that Autoload.php exist at both php/PHPUnit/ and php/File/Iterator/
My loaded php.ini file is at `/etc/php5/cli.php.ini1 as verified by
php --info | grep "onfiguration"
Any other suggestions would be appreciated.
Search for a file on your computer that is called Autoload.php and is in a file structure like this:
../File/Iterator/Autoload.php
Now open the file that throws the error (/usr/share/php/PHPUnit/Autoload.php in your case) and include a set_include_path statement that points to the absolute path of that file.
You seem to have a very similar problem to what I experienced on Mac OSX. For more information look at this very similar question. If all of this doesn't help, try to install with Composer, which I have heard doesn't have this issue.
For recent projects, I'm using Composer to install PHPUnit and the other related tools. It's quite easy:
## ... rest of the composer.json file
# "php -f composer.phar update --dev" to install
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
I also then have a shell script to actually run the PHPUnit command-line tool from the ./vendor/bin/ directory where a link to the locally installed script is installed.
Like Alister's answer, relying on Composer,
but I prefer to deploy the updated PHPUnit globally across my projects with:
composer.phar global require "phpunit/phpunit=dev-master"
That way, when I am at the root dir of my Symfony project, I can just run
~/.composer/vendor/bin/phpunit -c app/ -v --filter testFireNotifications |tee phpunit.log
That last bit with --filter was to run something selectively (actually, more for fast web automation via crontab, than testing...)
Even on a current Ubuntu 14.04.2 server, the repo is stuck with an outdated PHPUnit 3.7.28 "stable", so I sidestep the OS-provided one with this custom install that won't conflict (I haven't put ~/.composer/vendor/bin in my PATH).
I'm able to run my individual tests for each model in a plugin called Agg, but when I try to run a CakeTestSuite, then I get an error.
class ModelsTest extends CakeTestSuite
{
public static function suite()
{
$suite = new CakeTestSuite('All model tests');
$suite->addTestDirectory(TESTS . 'Case' . DS . 'Model');
return $suite;
}
}
Running that suite generates this error.
Fatal error: Class 'PHPUnit_Util_Skeleton_Test' not found in C:\work\zend\cake\Cake\TestSuite\CakeTestSuiteCommand.php on line 77
I'm using PHP 5.3.15 and have PHPUnit 3.7.12 installed with CakePHP 2.2.5
I get this error when running tests both via the web and the CLI.
Any help would be appreciated.
UPDATE:
If I search for 'PHPUnit_Util_Skeleton_Test' in PEAR folder for PHPUnit it's not found. This seems strange to me. Am I using the wrong version of PHPUnit? When was this class introduced?
UPDATE:
It seems that this class is no longer used in PHPUnit 3.7.x, and I'm wondering if CakePHP 2.2 will only work with PHPUnit 3.6. I tried to uninstall the pear package, and then install the 3.6.x version but always installs the newest version. Any ideas on how to downgrade PHPUnit?
UPDATE:
Downgrading using the --force to install older versions of PHPUnit didn't resolve the problem. I tried 3.6.12, 3.6.5 and 3.5. With the 3.6.12 I got an error with is_file() somewhere in the PHPUnit code.
PHPUnit_Util_Skeleton_Test is available in PHPUnit 3.6, see https://github.com/sebastianbergmann/phpunit/blob/3.6/PHPUnit/Util/Skeleton/Test.php
I suggest uninstalling all phpunit packages and reinstalling phpunit 3.6 with
$ pear install phpunit/phpunit-3.6.12
It might be that dependencies were broken when downgrading the single phpunit package with --force, and this should fix it.