11

I am running the example from the documentation: http://docs.phalconphp.com/en/latest/reference/unit-testing.html#sample-unit-test

I want to create an abstract unit test from Phalcon\Test\UnitTestCase as in the documentation. However when I run my test I become:

PHP Fatal error:  Class 'Phalcon\Test\UnitTestCase' not found 

I have followed the exact documentation steps. Did anyone have the same problem and solved it?

llundin
  • 383
  • 2
  • 13

3 Answers3

14

This class is part of the incubator: https://github.com/phalcon/incubator

$loader = new Phalcon\Loader();

$loader->registerNamespaces(array(
    'Phalcon' => '/path/to/incubator/Library/Phalcon/'
));

$loader->register();
twistedxtra
  • 2,699
  • 1
  • 18
  • 13
  • I am getting the same. I used composer to do the installation. But still I get it. Isn't composer install them in the correct locations? Bit confused... – masterFly Jun 16 '16 at 08:12
3

I figure it out.

Basically we have to do 2 things.

  1. is whats in the @twistedxtra's answer. (setting up the path to where the incubator is)

  2. in the testsTestUnitTest.php we created, it has the following line

class UnitTest extends \UnitTestCase {

we have to change that line to

class UnitTest extends \Phalcon\Test\UnitTestCase {

What we did was set the proper namespace so that the code knows where the UnitTestCase class is.

Thats it. Cheers...!!!

masterFly
  • 1,072
  • 12
  • 24
1

Make sure you run phpunit command in tests folder. It's very important.

Don't run something like phpunit tests/

SystemZ
  • 56
  • 1
  • 4
  • no idea why this was downvoted, as this is clearly one of the many problems and the suggestion is right! I had the very same problem, just because I was running it from different directory, and autoloader failed to match the paths correctly. – Radek Jan 10 '20 at 14:33