Yii Framework Forum: Running unit tests on windows problem - Yii Framework Forum

Jump to content

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

Running unit tests on windows problem Rate Topic: -----

#1 User is offline   KJedi 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 381
  • Joined: 19-October 08
  • Location:Nikolaev, Ukraine (Europe)

Posted 01 October 2009 - 12:21 AM

I created unit test, that should select * from Project table and that selection should be exactly one row, which I'll compare with fixture. Purpose is to verify DB connection and illustrate testing.
Here's the class:
class ApplicationTest extends CDbTestCase
{
    public $fixtures=array(
		'projects'=>':Project',
	);

	public function testSelect()
	{
		$command = Yii::app()->db->createCommand('SELECT * FROM Project');
		$result = $command->query();
		$this->assertEquals($this->projects['row1'], $result);
	}
}

Here's the command I'm running:

Quote

E:\XAMPP\htdocs\tasctrak\protected\tests>phpunit --bootstrap bootstrap.php unit\ApplicationTest.php
"""E:" не является внутренней или внешней
командой, исполняемой программой или пакетным файлом.
PHpunit 3.3.9 by Sebastian Bergmann.

Class CTestCase could not be found in E:\XAMPP\htdocs\tasctrak\protected\tests\unit\ApplicationTest.php.

First 2 lines translated into English:

Quote

"""E:" is not an internal or external
command, executable program or batch file.

That message does not actually matte, it's some bug that appear all the time.
But CTestCase is not found for some reason... Any ideas why?
Also, if I run phpunit unit\ApplicationTest.php without bootstrap key I get error:

Quote

Fatal error: Class 'CDbTestCase' not found in E:\XAMPP\htdocs\tasctrak\protected\tests\unit\ApplicationTest.php on line 13


What's wrong and how can I fix this?
Posted Image
My Blog: http://programmersnotes.info/ - tips, design patterns, client and server-side coding, yii articles and simply my experience.

Follow me on twitter: http://twitter.com/KonstantinMirin
Add me to your friends on facebook: http://www.facebook....hp?id=784832902
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,193
  • Joined: 17-January 09
  • Location:Russia

Posted 01 October 2009 - 01:53 AM

Maybe this one can help: http://www.yiiframew...hpunit-and-yii/
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#3 User is offline   KJedi 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 381
  • Joined: 19-October 08
  • Location:Nikolaev, Ukraine (Europe)

Posted 01 October 2009 - 05:09 AM

I'm working with 1.1 SVN version.
It has built-in unit testing framework that is based on phpunit and selenium.
selenium tests run OK, but phpunit ones - don't
the difference between 1.0.9 and 1.1 is that in 1.1 there is a special fie yiit.php, that should be included when testing.
And since I'm covering 11.1 version in my writing, I can't ignore the existance of the unit testing framework :)
Posted Image
My Blog: http://programmersnotes.info/ - tips, design patterns, client and server-side coding, yii articles and simply my experience.

Follow me on twitter: http://twitter.com/KonstantinMirin
Add me to your friends on facebook: http://www.facebook....hp?id=784832902
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 01 October 2009 - 05:42 AM

Are you able to run the unit tests under demos/blog successfully?
0

#5 User is offline   KJedi 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 381
  • Joined: 19-October 08
  • Location:Nikolaev, Ukraine (Europe)

Posted 01 October 2009 - 08:28 AM

No, the problem remains the same :(
I just updated the code from SVN and the problem persists.
Posted Image
My Blog: http://programmersnotes.info/ - tips, design patterns, client and server-side coding, yii articles and simply my experience.

Follow me on twitter: http://twitter.com/KonstantinMirin
Add me to your friends on facebook: http://www.facebook....hp?id=784832902
0

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 01 October 2009 - 08:42 AM

That's strange. It works fine here (also Windows).
As you may notice, there is a file demos/blog/protected/tests/bootstrap.php. This is the file that is automatically loaded when you run tests under that folder. In this file, yiit.php is included which further imports all necessary class files including CTestCase.php.
0

#7 User is offline   KJedi 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 381
  • Joined: 19-October 08
  • Location:Nikolaev, Ukraine (Europe)

Posted 01 October 2009 - 01:07 PM

Yes, I explored the file and found that. And I can't understand why it doesn't load CTestCase and does load CDbTestCase. Very strange...
Posted Image
My Blog: http://programmersnotes.info/ - tips, design patterns, client and server-side coding, yii articles and simply my experience.

Follow me on twitter: http://twitter.com/KonstantinMirin
Add me to your friends on facebook: http://www.facebook....hp?id=784832902
0

#8 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 515
  • Joined: 08-August 09

Posted 09 May 2011 - 06:15 AM

For those who maybe encountered the problem
PHP Fatal error:  Class 'CTestCase' not found in
 
For me the solution was: change current directory in your command line to a 'tests' folder, so you'll have
$ phpunit unit/SomeTest.php


instead of

$ phpunit tests/unit/SomeTest.php
,

for example.


Yuga
0

#9 User is offline   darklord 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 01-August 11

Posted 30 March 2012 - 01:00 AM

View PostSith I. Kong, on 30 March 2012 - 12:59 AM, said:

Recently, I have decided to get into TDD and BDD for real.
Thank you for the tip, its is a big help!
Somehow, maybe it is because of the folder permission that Yii is picky about the folder when we run phpunit file_name.php

Sith

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