emb
(Minnov)
September 6, 2010, 4:57am
1
Hello
I have been using Yii unittest implementation and it works great without changing any of the defaults. Recently I started writing some modules within my application. But so far I cannot access any of the module’s models within the unit test framework.
I am fairly certain that my config/main.php which is included in config/test.php imports my module. It works when you access the controller actions from a browser.
Given the above two claims, what am I missing. Can some one point me in the right direction?
Note: I have also noticed that none of the logging (trace/log) functions work when you are running in unit test mode for a normal non-module based application. Could this be related?
balrok
(Der Coole Carl)
September 6, 2010, 11:12am
2
hello - i think your problem is, that you haven’t defined the include-path of that modules
either you need to specify it inside:
protected/config/main.php and set the import-path
(note: that is something different, than specifying the existance of your module inside modules…
return array('import'=>array('application.modules.hello.models.*'))
or (so did i) set the import in the beginning of your test with:
Yii::import(‘application.modules.hello.models.*’);
the reason why it works for non-module models is, cause the config already imports them with:
application.models.*
emb
(Minnov)
September 6, 2010, 11:44pm
3
You are right. Thanks for the explanation. For some reason I had the believe that the ‘module’ config option took care of that.
sumwai
(Sumwai Low)
September 13, 2010, 9:29am
4
If I am unit testing my modules, is it a good idea to place the testing scripts inside the related module?
If I were to place the testing scripts together inside related module, is it possible to run both module test and non-module test together?
redguy
(Maciej Lizewski)
January 3, 2011, 2:48pm
5
sumwai:
If I am unit testing my modules, is it a good idea to place the testing scripts inside the related module?
If I were to place the testing scripts together inside related module, is it possible to run both module test and non-module test together?
I am also interested in solution that allows me to place unit tests for module inside module directory and test everything together (app + all modules that have tests).
Does anybody have an idea or such solution already working?
Eliovir
(Eliovir)
January 3, 2011, 6:17pm
6
I’m using phing for “manual continuous-integration” .
For each module, I put tests/phpunit.xml and tests/bootstrap.php in the module and write there the unit test files.
In my /build.xml, I put
<target name="test" description="Launch the unittests">
<phpunit bootstrap="protected/tests/bootstrap.php" printsummary="false">
<formatter type="plain" usefile="false"/>
<batchtest>
<fileset dir="protected/tests/">
<include name="unit/*Test.php"/>
</fileset>
<fileset dir="protected/modules/">
<include name="*/tests/unit/*Test.php"/>
</fileset>
</batchtest>
</phpunit>
</target>
So, I just have to type phing test to test the modules and the main application.
But now, the update to PHPUnit-3.5.0 broke the integration in Phing, I’ll have to return to the previous PHPUnit.
redguy
(Maciej Lizewski)
January 5, 2011, 3:51pm
7
@Eliovir : nice example - will give it a chance
thanks.
Eliovir
(Eliovir)
January 5, 2011, 5:07pm
8
Eliovir:
So, I just have to type phing test to test the modules and the main application.
But now, the update to PHPUnit-3.5.0 broke the integration in Phing, I’ll have to return to the previous PHPUnit.
Updating from phing-2.4.1 to phing-2.4.4 solved the problem.
Hindol
(Hindol Adhya)
April 3, 2011, 7:17am
9
Is it possible to test whether a module’s properties are set correctly?
Because while running unit tests, Yii::app()->controller->module is not available.
Eliovir
(Eliovir)
April 3, 2011, 11:16am
10
Hindol:
Is it possible to test whether a module’s properties are set correctly?
Because while running unit tests, Yii::app()->controller->module is not available.
Yii::app()->controller is available in a controller.
Did you try
Yii::app()->getModule('moduleName')
?
Hindol
(Hindol Adhya)
April 3, 2011, 3:47pm
11
Yes it worked. Thank you.
logity
(Logity)
December 23, 2011, 10:04am
12
ronyaja
(Ronypurwita)
March 26, 2012, 5:20am
13
Thanks logity, it work fine…