IntelliJ IDEA won't run PHPUnit 4.0 tests - intellij-idea

Sometimes IntelliJ IDEA has problems running, debugging, or showing code-coverage for PHPUnit tests. This can occur when the classes it generates are not compatible with the version of PHPUnit you have.
In my case, it's IntelliJ IDEA 12.1.6 versus PHPUnit 4.0.14, which always fails with this message:
/usr/bin/php /tmp/ide-phpunit.php --configuration /home/username/Documents/stuff/phpunit.xml.dist
Testing started at 5:32 PM ...
PHP Fatal error: Class IDE_PHPUnit_Framework_TestListener contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (PHPUnit_Framework_TestListener::addRiskyTest) in /tmp/ide-phpunit.php on line 496
PHP Stack trace:
PHP 1. {main}() /tmp/ide-phpunit.php:0
Process finished with exit code 255
The code it is generating in /tmp/ide-phpunit.php does not contain a new method required by PHPUnit 4.x.
Things which I've tried that don't work:
Fixing the file manually and marking it read-only causes IntelliJ to stop and complain that it cannot replace the file.
Setting up a "run-before" command to automatically patch the file is insufficient, because it doesn't seem to work for debugging nor code-coverage, only regular runs.

The best solution I've found is to patch your IntelliJ installation with a manual fix. These instructions assume Linux paths, but the same basic process should be possible on Windows.
Find the JAR
First, find the php.jar file in your IntelliJ installation. JAR files are a kind of ZIP file, you can open (and modify) both of them with the same tools. On my system, it was present at:
/home/username/.IntelliJIdea12/config/plugins/php/lib/php.jar
Make a backup of php.jar, since we're going to edit it.
Extract the template
Using a popular ZIP-file tool (like 7-Zip) open php.jar, and find the compresesd file inside called:
scripts/phpunit.php
Extract this file to a temporary location where you can edit it.
Add the method to the template
Inside the file, we need to find the class IDE_PHPUnit_Framework_TestListener, which in my case is around line 303. On that class, we need to add a new method:
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time){}
Save the file when you are done.
Update the JAR with the new template
Now overwrite scripts/phpunit.php inside the JAR with your new version. Depending on your ZIP tool, this might have been as easy as double-clicking the file to open it, saving your changes, and clicking a confirmation prompt, but it depends on what you're using.
Restart IntelliJ
Now you should be done! Running, debugging, or generating code-coverage data with PHPUnit should be just a convenient click of a button.
Note that if you update your PHP plugin, it will probably overwrite the fix and you'll need to re-apply it again.

Related

Grails commands under Idea fail with a "NoSuchMethodError" for "getAndPut" in the "EvictableCache" class

I'm trying to get an existing project working on a new platform (MacOS, M1) with Idea as the IDE. (I'm extremely new to Idea, but I'm getting help from other project developers.)
For a particular module in the project, any attempt to run pretty much any Grails command fails with an exception:
org.codehaus.groovy.runtime.memoize.EvictableCache.getAndPut(Ljava/lang/Object;Lorg/codehaus/groovy/runtime/memoize/MemoizeCache$ValueProvider;)Ljava/lang/Object
I have verified (to the extent I know how) that there's only one Groovy installation on the machine, and it's version 2.4.14 installed by sdkman. (Grails is 2.5.6.) Running the grails command as part of the Idea build (ie, from clicking "Build" or whatever inside the IDE) and running the grails command in the module top-level directory from the command line have exactly the same results.
I don't have much (well, any) experience with grails or groovy, but to me a "NoSuchMethodError" means that some piece of code was compiled against a different version of that class (EvictableCache) than the version that's actually in the jar file when grails runs. There are groovy .jar files in the project directory, but their presence seems to make no difference; it always gets that exception.
I'm using the Azul zulu8 JDK, downloaded from Azul directly. Formerly I had been using a version installed with brew but that made no difference.
Any ideas as to how to locate the .class file with the attempted call to getAndPut() in EvictableCache would be welcome.
edit — as I was looking at the stack traces from running a command, I noticed something. Again, my groovy is 2.4.14, as I can verify with groovy -version. At the top of one of my stack traces (maybe more than one) I see that the attempted call to getAndPut() is coming from a class called AbstractExtensionMethodCache. Well, as far as I can tell, that class did not become part of Groovy until version 3. So clearly something is messed up.

where is com.intellij.rt.junit.junitstarter

i use intellij with junit to run tests (new), when i debug my test code for practice, one of the very first lines of code that seems to run is some method called main from package called com.intellij.rt.junit. I've tried clicking on it as well as searching for it open that package or class to see what's inside but i can't find it all. anyone know what it is or where i could find it in intellij and why i can't just access it from the debugger like every other class? i have junit 5.8 installed in maven.
y.bedrov's analysis is quite right.
com.intellij.rt.junit.JUnitStarter is part of IDE. In your case, the IDE is IntelliJ IDEA. You may find the source code in this local path:
/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar
then import the jar package into your own project to read the source code conveniently.

Did something Change with Pycharm 2016.3.2 - UnitTests no longer auto discovered

I have upgraded my Community version of PyCharm to 2016.3.2, and I'm not positive it was this exact version, but when I went to run files that had unittests in them, only some of them are recognized as UnitTests that I can right click and run.
I have looked to make sure that my classes implement unittest.TestCase
class clWorkflowWebClientTest(unittest.TestCase):
all of my tests begin with test_blahblah()
If I go into Edit Configurations and add one manually, I can right click and run it from the project tree, and it runs as a UnitTest. But I don't get the "Run UnitTests in Blah' dialog when I right click the file.
This turned out to be an issue I caused myself. we had added a folder called 'UnitTest' and introducing this to the path caused issues with PyCharm knowing what was a true UnitTest file.
I still don't know exactly what caused some files to work, but there appears to be one method in those files that did work that was probably being imported from another file that had the proper pathing.

How to run Java scratch file in IntelliJ IDEA

I just start using IntelliJ-14 and I want to know about a scratch file. If I create a java scratch can I compile this as a normal Java class.
What I Have Already Tried
Create a Java class in a scratch file but unable to find any way to compile this.
What I am looking for rather than creating a new Java file in an existing project for running some test code I just want to use scratch file and write some test class with the main method and after complete running close the scratch file. Is that possible?
Executability for Java scratch files was added in IntelliJ 15, so you must upgrade for that feature.
You have several option how to run/debug the scratch file:
Click the icon next to the main method/class
Hit Control+Shift+R (Control+Shift+F10 on Linux/Windows) somewhere within the scratch file
Right click inside the method/class and select appropriate run/debug option

any way to run intellij community build from altered source?

I made changes to Intellij Community Edition (ce). I can compile and run those changes from within the IntelliJ editor. That launches a second instance of IntelliJ ce which is running from classes containing my changes. What I want to do is just run those changes without having to first load the source, compile and run from within IntelliJ.
Netbeans made this easy by just producing an executable as a result of the build. With Intellij, it's not at all clear what has to be done. I have tried the following-
using the Run configuration Intellij itself uses to run the altered classes- this includes setting the working directory , main class, vm options and classpath. Actually, this doesn't work for reasons unknown to me.
on someone's suggestion, running dist.gant in build. This blows up with very many errors which are not helpful (no class def found errors which indicate some confusion on Intellij's part on classpaths somewhere)
Running WinLauncher.exe under bin gives the error message that it can't find VM options file (although it's in bin, (and also for good measure under bin/win with the other files which are co-located with vmoptions in the intellij directory structure for Intellij proper. )
ALl this is just harder than it should be. The solution is to provide an executable as a result of the build and place it in a predictable location.
Has anyone ever actually DONE what I am trying to do- make changes to the community source then use the resultant editor not as a project you're working with in IntelliJ but as the Intellij editor you're working through?
FOLLOW UP
User60561 had the correct answer. Just to mop up the details, in artifacts, there is a compressed file (win.zip for Windows, mac.zip for Mac etc.). In order to run your snapshot, you have to unzip this archive (after which it will have the same name, minus the zip extension) then go into folder "bin". There you'll see two executables: idea.exe and idea64.exe, for 32 and 64 bit versions, respectively. Clicking on these runs your snapshot.
Adjusting contents of the files idea.exe.vmoptions and idea64.exe.vmoptions lets you set the VM parameters to suit yourself, typically people might want to give the VM more memory through the -Xmx value.
It seems straightforward:
To build the distribution archive of IntelliJ IDEA Community Edition, execute build.xml Ant build script in the root directory of the source code. The results of the build execution can be found at out/artifacts.
https://github.com/JetBrains/intellij-community#building
So download ant, and run ant in the directory that you have it stored in. Make sure to use the commandline to launch ant in order to make sure everything is working correctly.
Initially execute getPlugins.bat/sh, then:
Use update.bat/sh according to it's instructions
Or
Click on: Main Menu | Build | IntelliJ IDEA CE build
Copy content of intellij-community\out\deploy (lib, plugins folder) into existing IJ installation (sometimes it is better to delete existing folders if they contain older dependencies or when the installation was of Ultimate version)