Magento2: Class 'PHPUnit\Framework\TestCase' not found when execute UnitTests

Created on 28 Sep 2017  Â·  16Comments  Â·  Source: magento/magento2


Preconditions


  1. Magento Open Source 2.2

Steps to reproduce

  1. Install Magento 2.2
  2. enter Terminal in Document Root of Magento 2.2
  3. execute ./vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist

Expected result

  1. the tests are running

Actual result


1.Class 'PHPUnit\Framework\TestCase' not found in /var/www/htdocs/setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php on line 14
image

Format is valid needs update

Most helpful comment

@jigar48 If you're using PHPUnit version 6, please replace class 'PHPUnit_Framework_TestCase' in your test file to 'PHPUnit\Framework\TestCase'. So it'd look like this:

class YourTest extends \PHPUnit\Framework\TestCase {
    ...
}

All 16 comments

Looks like you forgot to run composer install.

In 2.2.0 PHPUnit version was upgraded to 6.x which introduced this new class.

hmm did a composer require magento/product-community-edition --no-update
and after that a composer update...

2017-09-28 12:15 GMT+02:00 Vlad Veselov notifications@github.com:

Looks like you forgot to run composer install.

In 2.2.0 PHPUnit version was upgraded to 6.x which introduced this new
class.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/11114#issuecomment-332792709,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAjp6CJE-dl3hbEnv-X6KVNCaO3lK1-vks5sm3HGgaJpZM4Pm5wA
.

Just check that it removed phpunit package of version 4.1 and added a new one 6.x. Probably autoload was not regenerated or something.

ok now it works, but i have to delete the hole vendor dir to get it installed in the correct version

I got same problem. Can you please let me know what is the solution ?

when I run the compile command

php bin/magento setup:di:compile

Its output this

Compilation was started.
Repositories code generation... 1/7 [====>-----------------------] 14% 1 sec 58.0 MiB
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /home/devspice/public_html/vendor/psr/log/Psr/Log/Test/LoggerInterfaceTest.php on line 14

See my previous post

I uploaded latest vendor folder but Its not helped me

This issue is bigger.
Found that installing composer in module will break setup:di:compile.
Step to reproduce:

  • Working Magento 2.2
  • Install module
    Eveything working except setup:di:compile
  • Run in module composer install
  • Remove and add once more phpunit
    Problem exist
  • Remove vendor catalog from module
    Problem resolved

There is somewhere problem path or/and multi composer installation.
Be sure to remove all vendors except main one.
Re add phpunit in version ~6.2.0 for Magento 2.2
Run composer install on end to regenerate files paths

Even more: check if vendor/bin/phpunit is symlink to vendor/phpunit/phpunit/phpunit

vendor catalog is magento 2 core module how can we remove that ?

Problem still exist not solved

Sorry about not precise. /vendor catalog in custom modules create problem. I think recursive vendor in the right directory isn't problem. This is propably to second installation of composer with rewrite previous settings of path.

but why its displaying the problem in this path instead of the custom extension.
vendor\psr\log\Psr\Log\Test\LoggerInterfaceTest.php on line 14

Repositories code generation... 1/7 [====>-----------------------] 14% 7 secs 52.0 MiBPHP
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in D:\xampp\htdocs\spicevalam2\vendor\psr\log\Psr\Log\Test\LoggerInterfaceTest.php on line 14

I already tried with composer clear cache also composer update and install but nothing work for me

I am still looking for the hope!

Do you check symlink? Reinstall by composer phpunit in right version? Are you regenerated composer files ? What version of Magento you use? Remove /generated directory after all step

Magento 2.2.1
Phpunit 6.2

Yes I have regenrated composer files because Its throwing same error as I discussed. also have tried to remove generated directly.

Also upgraded magento version to 2.2.3 but when I run compilation command it throwing error
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in D:\xampp\htdocs\spicevalam2\vendor\psr\log\Psr\Log\Test\LoggerInterfaceTest.php on line 14

I was confused here as well. I'm currently running Magento 2.2.4 and it seems to ship with PHPUnit 4, not 6: Running composer depends phpunit/phpunit tells me magento/project-community-edition 2.2.4 requires (for development) phpunit/phpunit (4.1.0). However, it turns out that my composer.json originates from way back and it mentions specifically to use PHPUnit 4. Once I started updating my composer.json by referring to the updated version https://raw.githubusercontent.com/magento/magento2/2.2/composer.json as a draft version, I was able to upgrade correctly. Perhaps this leads others to the solution as well? (Please note that you should NOT copy the entire file as an example - this is the GitHub version, not the real project version. Perhaps somebody has a better link?)

@jigar48 If you're using PHPUnit version 6, please replace class 'PHPUnit_Framework_TestCase' in your test file to 'PHPUnit\Framework\TestCase'. So it'd look like this:

class YourTest extends \PHPUnit\Framework\TestCase {
    ...
}

@advcha

Thanks, man I was having the issue with Class 'PHPUnit_Framework_TestCase' not found in **app/code/WebShopApps/MatrixRate/test/Unit/Block/Adminhtml/Form/Field/ExportTest.php on line 37 by following your suggestion it is fixed now.

Thanks

Was this page helpful?
0 / 5 - 0 ratings