Yii Framework Forum: Yii2: Unit Tests And Netbeans - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii2: Unit Tests And Netbeans

#1 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 266
  • Joined: 15-March 09

Posted 07 May 2013 - 06:46 PM

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?
Don't like ads in my sig...
0

#2 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 266
  • Joined: 15-March 09

Posted 08 May 2013 - 04:50 PM

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.
Don't like ads in my sig...
0

#3 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 08 May 2013 - 04:58 PM

That will teach you to be specific. :)

None of us are psychic, AFAIK.


Does what you do with Yii2 work with Yii1 ?


/* Moving it back.. */
"Less noise - more signal"
0

#4 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 08 May 2013 - 05:04 PM

Consider creating a new ticket/issue at the bug tracker @ Github, Ben. :)
"Less noise - more signal"
0

#5 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 266
  • Joined: 15-March 09

Posted 08 May 2013 - 06:41 PM

:)

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:

Quote

OK, but incomplete or skipped tests!
Tests: 1025, Assertions: 4714, Skipped: 100.


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.
Don't like ads in my sig...
0

#6 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 266
  • Joined: 15-March 09

Posted 08 May 2013 - 08:26 PM

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


/usr/bin/phpunit
  -log-junit /tmp/nb-phpunit-log.xml
  --configuration /var/www/yii2/phpunit.xml.dist
  /usr/local/netbeans-7.3/php/phpunit/NetBeansSuite.php  
    --run=/var/www/yii2/tests/unit[/whatever/you/select/in/project/explorer]


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:
<?php

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.
Don't like ads in my sig...
0

#7 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 266
  • Joined: 15-March 09

Posted 09 May 2013 - 06:15 AM

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.
Don't like ads in my sig...
0

#8 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 266
  • Joined: 15-March 09

Posted 09 May 2013 - 08:32 AM

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

asort($files)


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?
Don't like ads in my sig...
0

#9 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 266
  • Joined: 15-March 09

Posted 09 May 2013 - 08:40 AM

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()
	{
		parent::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.
Don't like ads in my sig...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users