Closed fmalk closed 10 years ago
get_instance
is only available after routing a Controller, and after the pre_controller
hook. Usually, the default controller in your config is loaded while bootstraping, and then you call whatever controller you want to test.As of running PHPUnit on PhpStorm, I use Aptana 3, and that's an auxiliary script I use to run tests inside it (I'm on a WAMP dev server):
#!C:\localhost\wamp\php\php546x130204135542\php.exe
<?php
/* PHPUnit
*/
define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main');
if (strpos('C:\localhost\wamp\php\php546x130204135542\php.exe', '@php_bin') === 0) {
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PHPUnit' . DIRECTORY_SEPARATOR . 'Autoload.php';
} else {
require 'C:\localhost\wamp\php\php546x130204135542\pear' . DIRECTORY_SEPARATOR . 'PHPUnit' . DIRECTORY_SEPARATOR . 'Autoload.php';
}
PHPUnit_TextUI_Command::main();
Save this as phpunit.php
and have your IDE run this script, it'll serve as an $> phpunit
from the command line.
hello and thanks for you replay and opening this issue,
i'll start with 3. i have my default controller set up and working, but my guess is that PHPStorm is just running this test file and not going through the bootsraping process because i can't even use the CI DEFINE Constants. when i'm running the test without any CI function it looks fine but the CI stuff doesn't work.
the steps that i did was:
about that script that you use in the Aptana 3.. where should i put it and what is its purpose ?
Hi @GiladGr! I'm not sure if I can help, because PHPStorm is not my primary IDE and I don't really know how to work with it. but let me try:
phpunit
from it:
bigger imageEDIT: I found this video on youtube and I hope it's useful http://www.youtube.com/watch?v=wPVXgTl6f7w
i haven't tried the PHPSTORM console but i was able to run it successfully using putty, my guess is that is the same, using the PHPSTORM and CI i had problems but i'm not sure it's the same as yours, in your case it says "Could not open input file: phpunit" what is this file ? it's the script you use on the aptana ? you added it to the run-configuration?
i've watched that video and many others but no help from that..
if so can you please add pictures of you run-configuration and i'll try to match them to mine ?
This is my project settings, I've try to use 3 difference option there, but no luck at all..
and as you said above:
2 patched the phpstorm v7.1 to work with is PHPUnit (they fixed it only on v8)
I found this.
Then I tryed this hack, but still no luck. :sweat_smile:
And finally I try to revert back my php.jar
and downgrade phpunit to 3.7 (using local composer installation) and ... :sweat:
Wooo!! I get it!!
autoload.php
file as your custom loader on your project setting like this: (I'm using global composer installation)
<your-project-dir>/phpunit.xml
, like this:
php.jar
file using this solution. In my case, it located in ~/.local/share/php-storm/plugins/php/lib/
(it should be based on your phpstorm installation directory, maybe):smile:
i'll try your solution tomorrow, i already patched the PHPSTORM but i think i might need help with the first two steps becasue i tried all kind of set ups with no luck but i'll double check your solution again and let you know.
maybe it has something to do with that my dev server is on a remote redhat machine and my IDE is on my local windows machine (project is on a network folder on the Redhat) so when i need to write the configuration and bootstrap paths it looks like it asks for the windows paths, but the files are on the remote Redhat machine, anyway i tried both paths without luck, guess i mixed some stuff.
and no i haven't tried using the compser autoload, i just checked the "path to phpunit.phar" but it worked only with a file path in windows.
as i mentioned i'm working on a remote machine, when using Putty i can see that the phpunit is installed from anywhere, but when using the PHPStorm now i get the following error : can't find PHPUnit in the include path:
@GiladGr by now I take the issue has been resolved?
actually no.. couldn't figure it out and it took to much time so i left it for now. i'll get back to it soon and let you know if i'll have any success with it.
thanks for your help anyway.
On behalf of Gilad, who sent me this email, I'm posting it here as an issue
Hey,
First of all I’d like to say thanks for the codeigniter-phpunit that you did.
I’m using CI 2.2.0 and I saw in the Changelog that it should work and you make less hacks in the core files and ect. But this project still has 3 hack to the system files and not 1, and also I have problem running it on my CI 2.2.0 version.
Any change you can help me with it ? Right now I’m trying your examples and get error that the get_instance() is not defined (I’m also using HMVC but have tried testing modules yet)
P.s. I don’t know if it matters but I’m trying to run the PHPUNIT from my IDE ( PHPSTORM ), but I’m able to run a simple phpunit tests.
Appreciate any help you can give me.
Thanks, Gilad.