TestCase not found in KernelTestCase.php with Symfony 3.2.7 - php

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.

Related

Failed opening required '/var/www/html/sel/demo/../bootstrap.php' for Nearsoft/php-selenium-client

I have PHP v 7.1.8 / PHPUnit v 6.4.4 successfully installed on my machine.
I dowloaded Nearsoft/php-selenium-client (https://github.com/Nearsoft/php-selenium-client).
After I started selenium standalone server, I tried to run demo Nearsoft Demo test phpunit Demo1.php, but it shows:
"Failed opening required '/var/www/html/sel/demo/../bootstrap.php'"
Not sure why, because it works just fine on my other machine that uses PHPUnit v 4+ amd PHP 5.6
I don't think you can run those demos with PHPUnit v6.4.4, since v6.0 PHPUnit has changed its Class names. Try running it with PHPUnit v5.7.
Take a look at the Release Notes for PHPUnit v6.0.
A quick look at demo1.php at line 10 exposes the "old" naming schema for PHPUnit.

How to update phpunit installed with symfony3

I want to start unit testing my symfony 3 application with the latest version of phpunit. I followed this tutorial. but when i runed this command
phpunit -c
According to the official site https://phpunit.de/ the installed version of php unit is not the latest version (!= 5.6):
PHPUnit 4.8.17 by Sebastian Bergmann and contributors.
the class test is :
class CalculatorTest extends \PHPUnit_Framework_TestCase
{
public function testAdd()
{
$calc = new Calculator();
$result = $calc->add(30, 12);
// assert that your calculator added the numbers correctly!
$this->assertEquals(42, $result);
}
}
I don't know that the framework use a bundle to import the PHPUnit_Framework_TestCase class or use the phpunit installed on my pc ?
And How can i update the phpunit version ?
Class PHPUnit_Framework_TestCase (and other PHPUnit_* code) will be imported from PHPUnit that are you executed.
Symfony is not require specific version of PHPUnit. For example, you can install the test framework as project (dev-)dependency and run it directly:
vendor/bin/phpunit -c app/
But
it's recommended to use the latest stable PHPUnit version, installed as PHAR.
If your PHPUnit version doesn't support your version of PHP, obviously you can use an older version of PHPUnit or update the platform.

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.

PHPUnit_Util_Skeleton_Test not found in CakePHP

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.

How to unittest symfony2 core

After a fresh symfony2 install i can run phpunit -c app/ and phpunit tests the included demo application: OK (1 test, 1 assertion).
But i receive no output (even with verbosity) when i run phpunit -c vendor/symfony/ as described here: http://symfony.com/doc/2.0/contributing/code/tests.html.
Does anyone know how to make this work?
PHPUnit: 3.6.2
PHP: 5.3.8
Symfony: 2.0.5
Testing twig, doctrine and other plugins works as expected (although doctrine tests fail for some reason).
If you have no output it's maybe because you configured php not to display errors.
You must install the vendors using the vendors.php script before lauching the Symfony test suite:
$ php vendor/symfony/vendors.php
Are you running the tests using the provided phpunit.xml.dist configuration file?
From your projects root directory:
$ phpunit --configuration app/phpunit.xml.dist vendor/symfony/tests
That should add an autoloader for vendors.

Categories