Skip to content

Commit

Permalink
Added support for run configuration in Docker and support for Nette T…
Browse files Browse the repository at this point in the history
…ester 2.0 (#31, #42)
  • Loading branch information
mesour committed Feb 19, 2020
1 parent 4fba284 commit a9c2d71
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 49 deletions.
2 changes: 1 addition & 1 deletion intellij-nette-tester.iml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/out" />
<excludeFolder url="file://$MODULE_DIR$/out" isTestSource="false" generated="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
Binary file modified intellij-nette-tester.jar
Binary file not shown.
14 changes: 9 additions & 5 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>cz.jiripudil.intellij.nette.tester</id>
<name>Nette Tester</name>
<version>2.0.0-beta.4</version>
<version>2.1.0</version>
<vendor email="[email protected]" url="https://jiripudil.cz">Jiří Pudil</vendor>
<resource-bundle>messages.TesterBundle</resource-bundle>

Expand All @@ -13,9 +13,11 @@
]]></description>

<change-notes><![CDATA[
<h2>2.0.0-beta.4</h2>
<h2>2.1.0</h2>
<ul>
<li>Added support for run line markers</li>
<li>Added run line markers to run TestCase or test methods</li>
<li>Added support for run configuration in Docker</li>
<li>Added support for Nette Tester 2.0</li>
<li>Fixed Compatibility with PHPStorm 2019.2 (<a href="https://github.com/jiripudil/intellij-nette-tester/issues/43">#43</a>)</li>
<li>Fixed bug java.lang.NullPointerException on phpstorm startup (<a href="https://github.com/jiripudil/intellij-nette-tester/issues/45">#45</a>)</li>
</ul>
Expand Down Expand Up @@ -85,14 +87,15 @@
<extensions defaultExtensionNs="com.intellij">
<configurationType implementation="cz.jiripudil.intellij.nette.tester.configuration.TesterRunConfigurationType"/>
<runConfigurationProducer implementation="cz.jiripudil.intellij.nette.tester.configuration.TesterRunConfigurationProducer"/>
<runLineMarkerContributor language="PHP" implementationClass="cz.jiripudil.intellij.nette.tester.lineMarker.TesterRunLineMarkerProvider"/>

<configurationType implementation="cz.jiripudil.intellij.nette.tester.configuration.TesterTestMethodRunConfigurationType"/>
<runConfigurationProducer implementation="cz.jiripudil.intellij.nette.tester.configuration.TesterTestMethodRunConfigurationProducer"/>
<runLineMarkerContributor language="PHP" implementationClass="cz.jiripudil.intellij.nette.tester.lineMarker.TesterMethodRunLineMarkerProvider"/>

<analyzeStacktraceFilter implementation="cz.jiripudil.intellij.nette.tester.execution.TesterStackTraceFilter"/>

<runLineMarkerContributor language="PHP" implementationClass="cz.jiripudil.intellij.nette.tester.lineMarker.TesterRunLineMarkerProvider"/>
<runLineMarkerContributor language="PHP" implementationClass="cz.jiripudil.intellij.nette.tester.lineMarker.TesterMethodRunLineMarkerProvider"/>

<testFinder implementation="cz.jiripudil.intellij.nette.tester.TesterTestFinder"/>
<testCreator language="PHP" implementationClass="cz.jiripudil.intellij.nette.tester.codeGeneration.TesterTestCreator"/>
<internalFileTemplate name="Tester TestCase"/>
Expand All @@ -105,6 +108,7 @@
id="cz.jiripudil.intellij.nette.tester.projectSettings.TesterConfigurable"
parentId="reference.webide.settings.project.settings.php"
groupWeight="25"
nonDefaultProject="true"
/>

<localInspection
Expand Down
1 change: 1 addition & 0 deletions resources/messages/TesterBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ runConfiguration.mainConfiguration.created.description=Run configuration was suc

settings.defaultExtension=Default extension:
settings.bootstrapFile=Bootstrap file:
settings.testerVersion=Tester version:
settings.namespaceMappings.title=Namespace mappings
settings.namespaceMappings.noMappings=No mappings
settings.namespaceMappings.sourceNamespace=Source namespace
Expand Down
122 changes: 122 additions & 0 deletions resources/setup2-0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

use Tester\Runner\OutputHandler;
use Tester\Runner\Runner;


$userSetupScript = \getenv('INTELLIJ_NETTE_TESTER_USER_SETUP');
if ($userSetupScript) {
require_once $userSetupScript;
}


final class TeamCityOutputHandler implements OutputHandler
{

/**
* @var resource
*/
private $file;


public function __construct($output = 'php://output')
{
$this->file = \fopen($output, 'w');
}


public function begin(): void
{
// \fwrite($this->file, $this->message('testCount', array('count' => 0)));
}

function prepare(\Tester\Runner\Test $test): void
{
// TODO: Implement prepare() method.
}

function finish(\Tester\Runner\Test $test): void
{
$testName = $test->title ?: $test->getFile();
$result = $test->getResult();
$message = $test->message;

$flowId = \md5($testName);
\fwrite($this->file, $this->message('testStarted', array('name' => $testName, 'flowId' => $flowId)));

if ($result === \Tester\Runner\Test::SKIPPED) { // Runner::SKIPPED, Test::SKIPPED
\fwrite($this->file, $this->message('testIgnored', array('name' => $testName, 'flowId' => $flowId, 'message' => 'Test skipped', 'details' => $message)));

} elseif ($result === \Tester\Runner\Test::FAILED) { // Runner::FAILED, Test::FAILED
$extraArguments = array();
if (\preg_match("/^diff \"(.*)\" \"(.*)\"$/m", $message, $matches)) { // Windows build
$expectedFile = \str_replace('""', '"', $matches[1]);
$actualFile = \str_replace('""', '"', $matches[2]);
$extraArguments = array('type' => 'comparisonFailure', 'expectedFile' => $expectedFile, 'actualFile' => $actualFile);

} elseif (\preg_match("/^diff '?(.*)'? '?(.*)'?$/m", $message, $matches)) {
$expectedFile = \trim($matches[1], "'");
$actualFile = \trim($matches[2], "'");
$extraArguments = array('type' => 'comparisonFailure', 'expectedFile' => $expectedFile, 'actualFile' => $actualFile);

} elseif (\preg_match("/Failed: (.*) should be( equal to)?\s+\.*\s*(.*) in/is", $message, $matches)) {
$expected = $matches[3];
$actual = $matches[1];
$extraArguments = array('type' => 'comparisonFailure', 'expected' => $expected, 'actual' => $actual);
}

$args = \array_merge(array(
'name' => $testName,
'flowId' => $flowId,
'message' => 'Test failed',
'details' => $message,
), $extraArguments);

\fwrite($this->file, $this->message('testFailed', $args));
}

\fwrite($this->file, $this->message('testFinished', array('name' => $testName, 'flowId' => $flowId)));
}


public function end(): void
{
}


private function message($messageName, $args): string
{
$argsPairs = array();
foreach ($args as $arg => $value) {
$argsPairs[] = \sprintf("%s='%s'", $arg, $this->escape($value));
}

return \sprintf(
"##teamcity[%s %s]\n\n",
$messageName,
\implode(' ', $argsPairs)
);
}


private function escape($value): string
{
$replace = array(
"|" => "||",
"'" => "|'",
"\n" => "|n",
"\r" => "|r",
"]" => "|]",
"[" => "|[",
);

return \strtr($value, $replace);
}

}


/** @var Runner $runner */
// replace registered output handlers with TC
$runner->outputHandlers = array();
$runner->outputHandlers[] = new TeamCityOutputHandler();
6 changes: 6 additions & 0 deletions src/cz/jiripudil/intellij/nette/tester/TesterUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import cz.jiripudil.intellij.nette.tester.configuration.TesterRunConfigurationType;
import cz.jiripudil.intellij.nette.tester.configuration.TesterTestMethodRunConfiguration;
import cz.jiripudil.intellij.nette.tester.configuration.TesterTestMethodRunConfigurationType;
import cz.jiripudil.intellij.nette.tester.projectSettings.TesterProjectSettings;
import cz.jiripudil.intellij.nette.tester.projectSettings.TesterProjectSettingsManager;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -48,6 +50,10 @@ public static boolean isTestClass(@NotNull PhpClass phpClass) {
return isTestCase.get();
}

public static TesterProjectSettings getTesterSettings(@NotNull Project project) {
return TesterProjectSettingsManager.getInstance(project).getState();
}

public static boolean isTestMethod(@NotNull Method method) {
return method.getContainingClass() != null
&& isTestClass(method.getContainingClass())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TesterMethodRunTestAction extends TesterCreateMethodRunTestAction {
public TesterMethodRunTestAction(@NotNull PsiElement element, @NotNull String testName, @NotNull String testMethod) {
super(element, testName, testMethod);

getTemplatePresentation().setText(TesterBundle.message("action.runTestAction.name") + " '" + testMethod + "()'");getTemplatePresentation().setIcon(TesterIcons.TESTER_CONFIG);
getTemplatePresentation().setText(TesterBundle.message("action.runTestAction.name") + " '" + testMethod + "()'");
getTemplatePresentation().setIcon(TesterIcons.RUN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TesterRunTestAction extends TesterCreateRunTestAction {
public TesterRunTestAction(@NotNull PsiElement element, @NotNull String testName) {
super(element, testName);

getTemplatePresentation().setText(TesterBundle.message("action.runTestAction.name") + " '" + testName + "'");getTemplatePresentation().setIcon(TesterIcons.TESTER_CONFIG);
getTemplatePresentation().setText(TesterBundle.message("action.runTestAction.name") + " '" + testName + "'");
getTemplatePresentation().setIcon(TesterIcons.RUN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import cz.jiripudil.intellij.nette.tester.TesterUtil;
import cz.jiripudil.intellij.nette.tester.projectSettings.TesterNamespaceMapping;
import cz.jiripudil.intellij.nette.tester.projectSettings.TesterProjectSettings;
import cz.jiripudil.intellij.nette.tester.projectSettings.TesterProjectSettingsManager;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand All @@ -23,7 +23,7 @@ public static TesterNamespaceMapper getInstance(@NotNull final Project project)

@NotNull
String mapSourceNamespaceToTestNamespace(@NotNull PhpClass sourceClass) {
TesterProjectSettings settings = TesterProjectSettingsManager.getInstance(project).getState();
TesterProjectSettings settings = TesterUtil.getTesterSettings(project);
String namespaceName = trimNamespaceSeparators(sourceClass.getNamespaceName());
if (settings == null) {
return namespaceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.jetbrains.php.roots.ui.PhpPsrDirectoryComboBox;
import com.jetbrains.php.ui.PhpUiUtil;
import cz.jiripudil.intellij.nette.tester.TesterBundle;
import cz.jiripudil.intellij.nette.tester.TesterUtil;
import cz.jiripudil.intellij.nette.tester.projectSettings.TesterProjectSettings;
import cz.jiripudil.intellij.nette.tester.projectSettings.TesterProjectSettingsManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -133,7 +133,7 @@ public String getTemplateName() {
@NotNull
@Override
protected String getExtension() {
TesterProjectSettings settings = TesterProjectSettingsManager.getInstance(getProject()).getState();
TesterProjectSettings settings = TesterUtil.getTesterSettings(getProject());
return settings != null ? settings.getDefaultExtension() : "phpt";
}

Expand All @@ -154,7 +154,7 @@ public Properties getProperties(@NotNull PsiDirectory directory) {
}

// bootstrap
TesterProjectSettings settings = TesterProjectSettingsManager.getInstance(getProject()).getState();
TesterProjectSettings settings = TesterUtil.getTesterSettings(getProject());
if (settings != null && settings.getBootstrapFile() != null) {
VirtualFile bootstrapFile = LocalFileSystem.getInstance().findFileByPath(settings.getBootstrapFile());
if (bootstrapFile != null && getDirectory() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import com.intellij.util.PathUtil;
import com.intellij.util.xmlb.annotations.Attribute;
import com.jetbrains.php.config.PhpProjectConfigurationFacade;
import com.jetbrains.php.config.commandLine.PhpCommandLinePathProcessor;
import com.jetbrains.php.config.commandLine.PhpCommandSettings;
import com.jetbrains.php.config.commandLine.PhpCommandSettingsBuilder;
import com.jetbrains.php.config.interpreters.PhpInterpreter;
import com.jetbrains.php.run.PhpCommandLineSettings;
import com.jetbrains.php.run.PhpExecutionUtil;
import com.jetbrains.php.run.PhpRefactoringListenerRunConfiguration;
import com.jetbrains.php.run.PhpRunUtil;
Expand Down Expand Up @@ -102,7 +104,11 @@ public void checkConfiguration() throws RuntimeConfigurationException {
@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) throws ExecutionException {
return this.getState(executionEnvironment, this.createCommand(Collections.emptyMap(), Collections.emptyList(), false));
try {
return this.getState(executionEnvironment, this.createCommand(Collections.emptyMap(), Collections.emptyList(), false));
} catch (CloneNotSupportedException e) {
return null;
}
}

@NotNull
Expand Down Expand Up @@ -137,24 +143,30 @@ public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunne
}

@NotNull
private PhpCommandSettings createCommand(Map<String, String> envParameters, List<String> arguments, boolean withDebuggerOptions) throws ExecutionException {
private PhpCommandSettings createCommand(Map<String, String> envParameters, List<String> arguments, boolean withDebuggerOptions) throws ExecutionException, CloneNotSupportedException {
PhpInterpreter interpreter = PhpProjectConfigurationFacade.getInstance(getProject()).getInterpreter();
if (interpreter == null) {
throw new ExecutionException(TesterBundle.message("runConfiguration.errors.phpInterpreterNotSet"));

} else {
TesterSettings settings = getSettings().clone();

PhpCommandSettings command = PhpCommandSettingsBuilder.create(getProject(), interpreter, withDebuggerOptions);
command.setScript(getSettings().getTesterExecutable(), false);

command.importCommandLineSettings(getSettings().getPhpCommandLineSettings(), null);
processSettings(command.getPathProcessor(), settings);

command.setScript(settings.getTesterExecutable());

PhpCommandLineSettings commandLineSettings = settings.getPhpCommandLineSettings();
command.importCommandLineSettings(commandLineSettings, null);
command.addEnvs(envParameters);

// support for user setup
if (getSettings().getSetupScriptPath() != null) {
command.addEnv("INTELLIJ_NETTE_TESTER_USER_SETUP", getSettings().getSetupScriptPath());
if (settings.getSetupScriptPath() != null) {
command.addEnv("INTELLIJ_NETTE_TESTER_USER_SETUP", command.getPathProcessor().process(settings.getSetupScriptPath()));
}

TesterExecutionUtil.addCommandArguments(getProject(), command, getSettings(), arguments);
TesterExecutionUtil.addCommandArguments(getProject(), command, settings, arguments);

return command;
}
Expand All @@ -166,6 +178,12 @@ protected TesterSettings createSettings() {
return new TesterSettings();
}

protected void processSettings(@NotNull PhpCommandLinePathProcessor processor, @NotNull TesterSettings settings) {
settings.setTestScope(processor.process(settings.getTestScope()));
settings.setPhpIniPath(processor.process(StringUtil.notNullize(settings.getPhpIniPath())));
settings.setSetupScriptPath(processor.process(StringUtil.notNullize(settings.getSetupScriptPath())));
}

@Override
protected void fixSettingsAfterDeserialization(@NotNull TesterSettings settings) {
settings.setTesterExecutable(PhpConfigurationUtil.deserializePath(settings.getTesterExecutable()));
Expand Down
Loading

0 comments on commit a9c2d71

Please sign in to comment.