PHPUnit_Util_Skeleton_Test not found in CakePHP - php

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.

Related

PHPUnit incompatible version with PHP 7.0

I'm trying to run unit tests using PHPUnit in a CI/CD setup. The problem is that I'm getting the following error:
PHPUnit testing framework version 6 or greater is required when running on PHP 7.0 or greater. Run the command 'composer run-script drupal-phpunit-upgrade' in order to fix this.
But I have the correct version of PHPUnit with PHP 7.2.14. I tried running the suggested command but nothing works.
vendor/bin/phpunit --version
PHPUnit 6.5.13 by Sebastian Bergmann and contributors.
Hope someone with experience has an idea.
Regards.
Probably version of PHP for cli and cgi could be different. As you are running phpunit from console, try also run php -v to find out which version is used for console.
Also, you error message suggest you:
Run the command 'composer run-script drupal-phpunit-upgrade' in order to fix this.
Probably that will fix your issue
I found out what the issue was... It seems that there was a previous installation of PHPUnit, with a version of 4.5, somewhere on the server outside my Drupal project. I manually updated that version to and now it works.

TestCase not found in KernelTestCase.php with Symfony 3.2.7

I'm having problems when running Symfony (PHPUnit integrated) tests in my server, it works as expected in my build host but when I upload them to Gitlab CI via Git it throws me the next error:
Class 'PHPUnit\Framework\TestCase' not found in /project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php on line 24
I tried executing phpunit, phpunit ., phpunit tests all with the same results
It was working until a few weeks ago.
My server Symfony version is 3.2.7 and the PHPUnit version is 4.2.6
PHPUnit version is 4.2.6 is very old, and does not contain any Namespaced classes. The Symfony KernelTestCase.php now uses those PHPUnit namespaces to pull on the TestCase class.
There is forward compatibility in PHPUnit 5.4.3, though v5.7, if not 6.0 would be better.
So, you'll want to upgrade your composer.json file and tests to use the new namespaces.

selenium testing in cakephp with phpunit

I want to learn about ui testing with selenium in phpunit. I had phpunit installed on my cakephp project, and it was running perfectly. Then I decided to install selenium following the steps described in https://phpunit.de/manual/3.7/en/selenium.html (i installed selenium in my project with the following command $ php composer.phar require --dev phpunit/phpunit-selenium: ">=1.2". Now after starting the selenium server with its jar file, I have been trying to run the example test provided in the link above, but I am receiving the following error:
$ vendor/bin/phpunit
PHP Fatal error: Class
'PHPUnit_Framework_TestCase' not found in
/var/www/html/ujols/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php
on line 97
Seems like the error is related to the Selenium2TestCase.php file that was installed with the composer. This is how the Selenium2TestCase.php file starts:
abstract class PHPUnit_Extensions_Selenium2TestCase extends PHPUnit_Framework_TestCase
{
Is there anyone here who managed to install selenium on cakephp or any other php framework? I would be super grateful if you could help me fix the problem
EDIT the sample test case i ve been trying to run to check if selenium is working:
PlainviewTest.php
<?php
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://www.example.com/');
}
public function testTitle()
{
$this->url('http://www.example.com/');
$this->assertEquals('Example WWW Page', $this->title());
}
}
?>
I figured a way to get selenium integrated with phpunit in my app with a lot of help from #ndm, here are the steps:
Follow the easy installation steps here - Testing with Selenium WebDriver + PHPUnit
*Make sure your new ui-tests are not in the same folder with unit tests, I had mine in the same folder and kept getting fatal errors.
*If running the ./vendor/bin/steward run staging firefox command returns an error, then change firefox to chrome. If you still keep getting error (like I did), install chromedriver and run again. It should work.
It was really worth all the effort.

Codeigniter Sparks with 3.0 Sparks_Path Error

I am fairly new to Codeigniter (last 6 months) and just recently started learning about sparks and how to use them. I followed Option 1 for installing Sparks here from getsparks.org and I received the Spark Manager has been installed successfully message. I then went to install my first spark found here and received this message: Spark installed to ./sparks/GoogleAPIClient/0.6.0 - You're on fire!
Upon trying to load my application I first had an error of EXT constant being undefined. After reading some threads it was suggested I add define('EXT', '.php'); to the application/config/constants.php file so I did. Now when I try to access it I get an Error has occurred message with this:
Cannot find spark path at sparks/sparks/0.0.9/
I verified the setup was installed correctly for both the manager and my spark. I read that adding APPPATH . 'sparks/' to the SPARKPATH constant would solve it (it didn't) and then trying '../sparks/' and that didn't. What am I missing?
Using Codeigniter 3.0
Usually with codeigniter4, spark comes along with bundle however you can still try the following commands on terminal (codeigniter4 or older versions still works). I ran these commands on mac osx sierra 10.12 with php 8 and codeigniter3. Go to terminal and try command :
$ php -r "$(curl -fsSL http://getsparks.org/go-sparks)"
it should give below output on terminal-
"Pulling down spark manager from
http://getsparks.org/static/install/spark-manager-0.0.9.zip ...
Pulling down Loader class core extension from
http://getsparks.org/static/install/MY_Loader.php.txt ...
Extracting zip package ...
Cleaning up ...
Spark Manager has been installed successfully!"
you can then use below command to verify if everything works.
php tools/spark help
it should return some text and description and some commands.

Oil test raises uncaught exception

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.

Categories