M
M
Maxim Melnik2016-12-05 08:56:03
PHP
Maxim Melnik, 2016-12-05 08:56:03

Why does not find the required class in phpunit?

Good afternoon!
I'm setting up PHPUnit for the first time and I ran into such a problem, unit tests inherited from the PHPUnit_Framework_TestCase class work fine, but for some needs I still needed to connect more listeners components via PHPUnit_Framework_BaseTestListener and tests to the database via PHPUnit_Extensions_Database_TestCase . And phpunit does not see them.
Details:
phpunit.xml

<?xml version="1.0" encoding="UTF-8" ?>
<phpunit
        bootstrap="./vendor/autoload.php"
        colors="true"
        convertErrorsToExceptions="true"
        convertNoticesToExceptions="true"
        convertWarningsToExceptions="true"
        processIsolation="false"
        stopOnFailure="false"
        syntaxCheck="false">
   <listeners>
        <listener class="DBInit" file="./tests/listeners/DBInit.php">
        </listener>
    </listeners>
    <testsuites>
        <testsuite name="Main PHPUnit Tests">
            <directory>./tests/</directory>            
        </testsuite>
    </testsuites>
    <php>
        <var name="DB_HOST" value="localhost" />
        <var name="DB_USER" value="root" />
        <var name="DB_PASSWORD" value="" />
        <var name="DB_DBNAME" value="ural_catalog_tests" />
        <var name="VERSION" value="1.0" />
    </php>
</phpunit>

phpshtorm
5a26f236d1cd4256b599ae58e328886a.png
settings: Test settings:
4d782a25af16423281214b936c26ea62.pngDownloaded the latest version of phpunit.
listener code
se PHPUnit\Framework\TestCase;

class DBInit extends PHPUnit_Framework_BaseTestListener
{
  static $wasCalled = false;

  public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
  {
     // DO SOMETHING
  }
}

Test code for database
class SearchTest extends PHPUnit_Extensions_Database_TestCase
{
  // Imortant methods 
  // some tests
}

Errors:
C:\xampp\php\php.exe C:/Users/Gesparo/AppData/Local/Temp/ide-phpunit.php --configuration C:\xampp\htdocs\sitename\phpunit.xml
Testing started at 10:46 ...

Warning: Module 'openssl' already loaded in Unknown on line 0

Fatal error: Class 'PHPUnit_Framework_BaseTestListener' not found in C:\xampp\htdocs\sitename\tests\listeners\DBInit.php on line 6

Call Stack:
    0.0030     225984   1. {main}() C:\Users\Gesparo\AppData\Local\Temp\ide-phpunit.php:0
    0.0210     783736   2. IDE_Base_PHPUnit_TextUI_Command::main() C:\Users\Gesparo\AppData\Local\Temp\ide-phpunit.php:589
    0.0210     787136   3. PHPUnit_TextUI_Command->run() C:\Users\Gesparo\AppData\Local\Temp\ide-phpunit.php:299
    0.2510    2341656   4. PHPUnit_TextUI_TestRunner->doRun() C:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
    0.2510    2342448   5. PHPUnit_TextUI_TestRunner->handleConfiguration() C:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php:139
    0.2540    2353600   6. require_once('C:\xampp\htdocs\sitename\tests\listeners\DBInit.php') C:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php:624

PHP Warning:  Module 'openssl' already loaded in Unknown on line 0
PHP Fatal error:  Class 'PHPUnit_Framework_BaseTestListener' not found in C:\xampp\htdocs\sitename\tests\listeners\DBInit.php on line 6
PHP Stack trace:
PHP   1. {main}() C:\Users\Gesparo\AppData\Local\Temp\ide-phpunit.php:0
PHP   2. IDE_Base_PHPUnit_TextUI_Command::main() C:\Users\Gesparo\AppData\Local\Temp\ide-phpunit.php:589
PHP   3. PHPUnit_TextUI_Command->run() C:\Users\Gesparo\AppData\Local\Temp\ide-phpunit.php:299
PHP   4. PHPUnit_TextUI_TestRunner->doRun() C:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
PHP   5. PHPUnit_TextUI_TestRunner->handleConfiguration() C:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php:139
PHP   6. require_once() C:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php:624

Process finished with exit code 255

Can you suggest why it does not see these classes. Maybe I made a mistake somewhere in the test settings?
PS The php version I am using is 5.6

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question