Problem including PHPUnit

I want to start writing tests for my code, so I installed the latest version of PHPUnit with the following commands

wget http://pear.phpunit.de/get/phpunit.phar chmod +x phpunit.phar mv phpunit.phar /usr/local/bin/phpunit 

http://phpunit.de/manual/3.8/en/installation.html

then I added / usr / local / bin to my php.ini include path that looks like

include_path = ".:/Applications/MAMP/bin/php/php5.4.10/lib/php:/usr/local/bin"

but I get the following errors when I visit /my-app/test.php

Warning (2): include (PHPUnit / Autoload.php): stream could not be opened: No such file or directory [CORE / Cake / TestSuite / CakeTestSuiteDispatcher.php, line 150]

Warning (2): include () [function.include]: Error opening 'PHPUnit / Autoload.php' to enable (Include_path = '/ Users / DevinCrossman / Sites / Studios Bliss / Library:.: / Applications / MAMP / bin / PHP / php5.4.10 / Library / PHP: / USR / local / bin ') [CORE / Cake / TestSuite / CakeTestSuiteDispatcher.php, line 150]

I tried changing /usr/local/bin/phpunit to /usr/local/bin/phpunit , but that didn't work. I also tried changing the inclusion path from /usr/local/bin to /usr/local/bin/phpunit and restarted apache (I use MAMP PRO on this computer, but it also did not work on my ubuntu server)

a phpinfo() shows that the enable path is set correctly.

maybe something obvious that i missed. Can someone tell me why this is not working?

+4
source share
2 answers

CakePHP recommends using PEAR to install PHPUnit . It should work better in your case.

Entering phar in / usr / local / bin with the phpunit file name is intended for use by PHPUnit testrunner via the command line , as this will make the phpunit command available. e.g. running command:

 phpunit MyTest test.php 

When launched in a browser, you need PHPUnit classes to load, which do not work, just having the path to your phar in the include path. I'm not sure, but this might work if you include phar in your test file:

 require_once '/path/to/phpunit.phar' 
+2
source

Edit or create a composition in the application directory. Add the following lines.

 { "require-dev" : {"phpunit/phpunit":"3.7.*"} } 

Then install using composer .

 composer install 
+1
source

Source: https://habr.com/ru/post/1498502/


All Articles