Viewed   120 times

I am using the Symfony3 plugin in PhpStorm. My PHP Interpreter is 7.0.18. I have PHPUnit 6.3.0 configured in PhpStorm by having the .phar file in the root directory of my project.

Unit test work like a charm inside the IDE however performing any operation on the server (like bin/console server:start) triggers the following messages:

PHP Fatal error: Class 'PHPUnitFrameworkTestCase' not found in /1tb/programming/PhpstormProjects/binary_search/src/AppBundle/Search/BinarySearchTest.php on line 13
PHP Fatal error: Class 'PHPUnitFrameworkTestCase' not found in /1tb/programming/PhpstormProjects/binary_search/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/TestCase.php on line 17

BinarySearchTest.php:

 <?php

namespace AppBundleSearch;

use PHPUnitFrameworkTestCase;

class BinarySearchTest extends TestCase
{

}

TestCase.php:

<?php

namespace SymfonyBundleFrameworkBundleTests;

use PHPUnitFrameworkTestCase as PHPUnitTestCase;

class TestCase extends PHPUnitTestCase
{

}

I have read many posts with problems similar but none of them describe the problem the way I do. Then I tried running PHPUnit with phpunit . in the root directory of the folder with this error:

PHP Fatal error: Class 'DoctrineTestsCommonCacheCacheTest' not found in /1tb/programming/PhpstormProjects/binary_search/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php on line 10

It seems whatever I do I just run into more errors. I only just got started with Symfony and read a bit of the documentation but I can't get a grip on this thing, I have been at it for two days. Any suggestions for me?

 Answers

1

Installation of PHPUnit via composer worked. It turns out my composer installation went wrong in some way. After composer was successfully installed, I let it handle installing PHPUnit. After that it just worked. Tests work fine in the IDE and the server is responsive again. Thanks LazyOne.

Saturday, October 29, 2022
3

I ran into the same problem and if you are not too familiar with the inner workings of both PHPUnit and Composer this can indeed seem perplexing.

PHPunit does not use use the Composer autoloader to find any of your test classes. It just scans any directory you give it and operates on one file at a time.

Hence it does not know about any other class than the one in the file it is currently operating on. That is where the bootstrap file comes into play.

If you want to use the Composer Autoloader to load other test classes, you need to tell it where it can find these test classes (and, optionally, in which namespace).

There are two ways to do this:

  1. Add an autoload-dev section to your composer.json or
  2. Add the test directory to the Composer Autoloader

Use autoload-dev

The autoload-dev sections allows you to define autoload rules for development purposes.

Quoting directly from the manual:

Classes needed to run the test suite should not be included in the main autoload rules to avoid polluting the autoloader in production and when other people use your package as a dependency.

Therefore, it is a good idea to rely on a dedicated path for your unit tests and to add it within the autoload-dev section.

Example:

{
    "autoload": {
        "psr-4": { "MyLibrary\": "src/" }
    },
    "autoload-dev": {
        "psr-4": { "MyLibrary\Tests\": "tests/" }
    }
}

Add to the Composer Autoloader

An alternative would be to get the Composer Autoloader and add your testing namespace (if you have any) and the directory where your tests live. How to do this, as described in the manual (at the bottom of the autoloading section in "Basic Usage") is :

$loader = require('/path/to/vendor/autoload.php');
$loader->add('Test\', __DIR__ . '/Tests');

If your tests use namespaces that mirror the test directory and you still run into trouble, you can try omitting the prefix by replacing the first parameter ('Test\') with ''.


If you want further insight into how all of this works you should take a look at the Composer ClassLoader class, especially the add() and findFile() methods.

Sunday, December 25, 2022
 
3

Finally managed to fix it! I removed the @runInSeparateProcess annotation for the test that was failing and also the --stderr option in the run configurations. Instead, I added stderr="true" option in the phpunit tag present in the phpunit.xml and it worked. Strange.

Thank you Ian Bytchek for your time and effort. :)

Sunday, November 20, 2022
 
ish
 
ish
4

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Sunday, November 6, 2022
2

ADL VCL is not available for XE4, since it was discontinued some time before XE4 was released. If you have the ADL source code, and have ported it to XE4, then it's plausible that you may have some success.

The error message you describe is symptomatic of not having the design-time packages for the components installed. You'll need to build and install design-time packages for any components that you want to interact with at design-time.

Thursday, November 17, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :