I want to write tests for MySQL Database. When I try to extend the database extension, it gives me the above error in title:
class FixtureTestCase extends PHPUnit_Extensions_Database_TestCase
Note: I have installed PHPUnit
globally and I can access it through phpunit in cmd. I have latest PHPUnit
4.5.1.
I also installed Dbunit
globally through composer
:
composer global require phpunit/dbunit
Any help will be much appreciated. I've used PHP 5.4.
For referring to classes that are located within the global namespace, you can simply prefix them with a backward ( \ ) slash. Try with this:
class FixtureTestCase extends \PHPUnit_Extensions_Database_TestCase
With the leading backward ( \ ) slash, PHP knows that we are referring to the PHPUnit_Extensions_Database_TestCase
class in the global namespace, and located that one.
More info here
Hope this help.
Test your DB how? Through an API you created or direct accesses to DB? i would recommend you to write an API to access your DB and then write the tests to the API. for exemple if you want to insert a user you call your web-server address (localhost:3000) or something you have and then call /users through POST to insert and make the routes to that. I would suggest using LARAVEL for that.
It just might be the version of DBUnit. For example I'm using PHPUnit 4.8
and it works with DBUnit 1.4
.
I had the above error when I was using composer with "phpunit/dbunit": ">=1.2"
and I ended up with DBUnit 2.0.