Yii2: Unit Tests And Netbeans

Following problem: When I run the unit tests from within netbeans, the cache tests fail. When I run phpunit from the command line, everything works as expected.

Did anyone experience similar problems? Does anyone know a solution?

Not sure if I posted it here accidently or if it was moved, but for the record: this question is about the yii2 repositorie’s unit tests.

That will teach you to be specific. :)

None of us are psychic, AFAIK.

Does what you do with Yii2 work with Yii1 ?

[color="#006400"]/* Moving it back… */[/color]

Consider creating a new ticket/issue at the bug tracker @ Github, Ben. :)


Little bit weird. I tested yii1, and it gave me different outputs on console and from within NB. Console seemed to skip way more tests. In both environments, the unit tests ultimately failed. After looking into it, it turned out I had no sqlite driver installed. With the driver, unit tests for yii1 give the same results on console and from within NB:

I don’t understand how test results could differ without the driver being installed…

I ensured NB uses the same php.ini as phpunit when run from console.

Same php modules loaded, same settings. Environment differs though.

Now, back to yii2. Once again, I get different results.

From within NB, DbCacheTest and FileCacheTest fail. From the command line, those tests pass.

I think it has something to do with the generic test suite NB is using. They call phpunit like this, which causes the problems:


  -log-junit /tmp/nb-phpunit-log.xml

  --configuration /var/www/yii2/phpunit.xml.dist



It works as long as I execute the single tests directly, or on the cache folder. Everywhere above that, it causes the tests to fail.

Now the question is: Do you want to work around that problem, to provide the possibility to unit test the framework from within NB?

// EDIT:

There is the possibility to configure a custom test suite, but that had to be written as a class, not configured in the phpunit.xml.

// EDIT 2:

Implemented a test suite wrapper:


namespace yiiunit;

class FrameworkSuite extends \PHPUnit_Framework_TestSuite




	 * Suite factory.


	 * @access public

	 * @static

	 * @return FrameworkSuite


	public static function suite()


		$configuration = \PHPUnit_Util_Configuration::getInstance(

			__DIR__ . '/../../phpunit.xml.dist'


		return $configuration->getTestSuiteConfiguration();




// EDIT 3:

Seems my custom test suite is only used when I test the whole project. NB still uses its internal test suite as soon as I try to test specific folders.

Another idea to approach the problem might be to refactor the problematic tests themselves. I don’t exactly know what is causing the problems, but I realized the failing tests both extend CacheTest, which is an abstract class (the only one in the test suite).

However, the best way would probably be to fix that test suite. It is distributed under GPL or CDDL, so it could be fixed and redistributed.

This keeps bugging me. I compared how those two test suits collect the tests. Turns out, phpunit adds test files alphabetically sorted to the suite, whereas NB does not sort them. If I add an


to the NB test suite, the tests do not fail any longer.

This makes me wonder if the unit tests depend on each other in some way?

Maybe running the unit tests from command line only works, because some required tests are run before the cache tests?

HA! Here we go:

// /var/www/yii2/tests/unit/framework/helpers/HtmlTest.php

class HtmlTest extends \yii\test\TestCase


	public function setUp()


		new Application(array(

			'id' => 'test',

			'basePath' => '@yiiunit/runtime',

			'components' => array(

				'request' => array(

					'class' => 'yii\web\Request',

					'url' => '/test',





	public function tearDown()


		Yii::$app = null;



// /var/www/yii2/framework/caching/Cache.php

abstract class Cache extends Component implements \ArrayAccess


	public function init()



		if ($this->keyPrefix === null) {

			$this->keyPrefix = \Yii::$app->id;




So, if HtmlTest runs before CacheTests, CacheTests will fail, because there is no longer a Yii::$app instance.