Skip to content

Commit b53d5ce

Browse files
authored
fix: Intellij gradle plugin update (#66)
* chore: autoformat * docs: reflect naming change * chore: upgrade plugin and actions * fix: add necessary parameter
1 parent 16b9abb commit b53d5ce

File tree

12 files changed

+103
-45
lines changed

12 files changed

+103
-45
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ jobs:
1414
- name: install fonts
1515
run: sudo apt-get update -y && sudo apt-get install -y fonts-dejavu fontconfig
1616
- name: setup java
17-
uses: actions/setup-java@v1
17+
uses: actions/setup-java@v2
1818
with:
19-
java-version: '8'
19+
distribution: temurin
20+
java-version: '11'
2021
- name: build asset
21-
uses: eskatos/gradle-command-action@v2.0.1
22+
uses: gradle/gradle-build-action@v2
2223
with:
2324
arguments: build
2425
- name: fetch latest release

.github/workflows/test.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ jobs:
1313
- name: install fonts
1414
run: sudo apt-get update -y && sudo apt-get install -y fonts-dejavu fontconfig
1515
- name: setup java
16-
uses: actions/setup-java@v1
16+
uses: actions/setup-java@v2
1717
with:
18-
java-version: '8'
18+
distribution: temurin
19+
java-version: '11'
1920
- name: test plugin
20-
uses: eskatos/gradle-command-action@v2.0.1
21+
uses: gradle/gradle-build-action@v2
2122
with:
2223
arguments: :cleanTest :test check verifyPlugin

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Quick Mock
2-
[![Build Status](https://travis-ci.com/cawolf/phpstorm-quick-mock.svg?branch=master)](https://travis-ci.com/cawolf/phpstorm-quick-mock)
2+
[![Tests](https://github.com/cawolf/phpstorm-quick-mock/actions/workflows/test.yml/badge.svg)](https://github.com/cawolf/phpstorm-quick-mock/actions/workflows/test.yml)
33
[![Version](https://img.shields.io/jetbrains/plugin/v/11165?label=version)](https://plugins.jetbrains.com/plugin/11165-quick-mock)
44
[![Downloads](https://img.shields.io/jetbrains/plugin/d/11165)](https://plugins.jetbrains.com/plugin/11165-quick-mock)
55

@@ -13,7 +13,7 @@ Now, you can use this PHPStorm plugin to automatically generate mocks for these
1313
constructor argument list, trigger code intentions (default: `ALT + ENTER`) and select `Quick Mock: add constructor prophecies` - done!
1414

1515
## Install
16-
Install the plugin by going to `Settings -> Plugins -> Browse repositories` and then search for `Quick Mock`
16+
Install the plugin by going to `Settings -> Plugins -> Marketplace` and then search for `Quick Mock`
1717

1818
## Options
1919
You can configure the plugin under `Languages and Frameworks -> PHP -> Quick Mock`. Available options:

build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
33

44
plugins {
55
id 'java'
6-
id 'org.jetbrains.intellij' version '0.7.3'
6+
id 'org.jetbrains.intellij' version '1.3.0'
77
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.1'
88
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
99
}
@@ -72,10 +72,10 @@ tasks.withType(Test) {
7272
}
7373

7474
intellij {
75-
type 'IU'
76-
version ideaVersion
77-
updateSinceUntilBuild false
78-
plugins = [
75+
type.set('IU')
76+
version.set(ideaVersion)
77+
updateSinceUntilBuild.set(false)
78+
plugins.set([
7979
"com.jetbrains.php:${phpPluginVersion}",
8080
'coverage',
8181
'webDeployment',
@@ -84,7 +84,7 @@ intellij {
8484
'java-i18n',
8585
'properties',
8686
'xpath'
87-
]
87+
])
8888

89-
pluginName 'Quick Mock'
89+
pluginName.set('Quick Mock')
9090
}

src/main/kotlin/de/cawolf/quickmock/intention/Constants.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const val GENERATED_SUFFIX = "QuickMocked"
66

77
@JvmField
88
val PRIMITIVES = arrayOf(
9-
"string",
10-
"int",
11-
"float",
12-
"bool",
13-
"array",
14-
"", // mixed
15-
"object"
9+
"string",
10+
"int",
11+
"float",
12+
"bool",
13+
"array",
14+
"", // mixed
15+
"object"
1616
)

src/main/kotlin/de/cawolf/quickmock/intention/QuickMockCreator.kt

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,28 @@ class QuickMockCreator : PsiElementBaseIntentionAction(), IntentionAction {
2525
val newExpression = PsiTreeUtil.getParentOfType(psiElement, NewExpression::class.java)
2626
return newExpression is NewExpression
2727
&& newExpression.let { constructor.get(it) } != null
28-
&& constructorParameters.get(psiElement, project).count() != newExpression.parameterList!!.children.count()
28+
&& constructorParameters.get(psiElement, project)
29+
.count() != newExpression.parameterList!!.children.count()
2930
}
3031

3132
@Throws(IncorrectOperationException::class)
3233
override fun invoke(project: Project, editor: Editor, psiElement: PsiElement) {
3334
// init and safeguards: do not proceed if the current edited test class is not parsing correctly
3435
val namespace = PsiTreeUtil.getParentOfType(psiElement, PhpNamespace::class.java)
35-
?: return
36+
?: return
3637
val clazz = PsiTreeUtil.getParentOfType(psiElement, PhpClass::class.java)
37-
?: return
38-
val beginningOfClass = PsiTreeUtil.getParentOfType(psiElement, PhpClass::class.java)?.children?.find { it -> it is ImplementsList }?.nextSibling?.nextSibling
39-
?: return
38+
?: return
39+
val beginningOfClass = PsiTreeUtil.getParentOfType(
40+
psiElement,
41+
PhpClass::class.java
42+
)?.children?.find { it -> it is ImplementsList }?.nextSibling?.nextSibling
43+
?: return
4044
val constructStatement = PsiTreeUtil.getParentOfType(psiElement, AssignmentExpression::class.java)
41-
?: return
45+
?: return
4246
val newExpression = PsiTreeUtil.getParentOfType(psiElement, NewExpression::class.java)
43-
?: return
47+
?: return
4448
val parameterList = newExpression.parameterList
45-
?: return
49+
?: return
4650

4751
// get helper services
4852
val addArguments = ServiceManager.getService(project, AddArguments::class.java)
@@ -54,7 +58,8 @@ class QuickMockCreator : PsiElementBaseIntentionAction(), IntentionAction {
5458
val removeSurroundingWhitespaces = ServiceManager.getService(project, RemoveSurroundingWhitespaces::class.java)
5559
val constructorParameters = ServiceManager.getService(project, ConstructorParameters::class.java)
5660
val addNewlineBefore = ServiceManager.getService(project, AddNewlineBefore::class.java)
57-
val removeWhitespaceBeforeConstruct = ServiceManager.getService(project, RemoveWhitespaceBeforeConstruct::class.java)
61+
val removeWhitespaceBeforeConstruct =
62+
ServiceManager.getService(project, RemoveWhitespaceBeforeConstruct::class.java)
5863
val existingMocks = ServiceManager.getService(project, ExistingMocks::class.java)
5964
val settings = ServiceManager.getService(Settings::class.java)
6065

@@ -73,10 +78,22 @@ class QuickMockCreator : PsiElementBaseIntentionAction(), IntentionAction {
7378
if (parametersWithoutMocks.contains(parameter)) {
7479
val parameterClassName = parameter.type.toString().removeSuffix("[]")
7580
parameterName = determineParameterName(clazz, parameter)
76-
nonPrimitiveMocked = addMissingUseStatements.invoke(project, namespace, parameterClassName, aliasedUseStatementList[parameterClassName]) || nonPrimitiveMocked
81+
nonPrimitiveMocked = addMissingUseStatements.invoke(
82+
project,
83+
namespace,
84+
parameterClassName,
85+
aliasedUseStatementList[parameterClassName]
86+
) || nonPrimitiveMocked
7787
addMockAssignment.invoke(project, constructStatement, parameter, parameterName)
7888

79-
currentAnchor = addProperty.invoke(project, parameter, parameterName, currentAnchor, clazz, settings.addDocBlockForMembers)
89+
currentAnchor = addProperty.invoke(
90+
project,
91+
parameter,
92+
parameterName,
93+
currentAnchor,
94+
clazz,
95+
settings.addDocBlockForMembers
96+
)
8097
}
8198

8299
parameterMapByName.add(Pair(parameterName, parameter))
@@ -93,6 +110,10 @@ class QuickMockCreator : PsiElementBaseIntentionAction(), IntentionAction {
93110
}
94111

95112
private fun determineParameterName(clazz: PhpClass, parameter: Parameter): String {
96-
return if (clazz.findOwnFieldByName(parameter.name, false) == null && clazz.findFieldByName(parameter.name, false) != null) parameter.name + GENERATED_SUFFIX else parameter.name
113+
return if (clazz.findOwnFieldByName(parameter.name, false) == null && clazz.findFieldByName(
114+
parameter.name,
115+
false
116+
) != null
117+
) parameter.name + GENERATED_SUFFIX else parameter.name
97118
}
98119
}

src/main/kotlin/de/cawolf/quickmock/intention/service/AddArguments.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class AddArguments {
4040
}
4141

4242
private fun createDummyFile(p: Project, fileText: String): PsiFile =
43-
PsiFileFactory.getInstance(p).createFileFromText("DUMMY__.${PhpFileType.INSTANCE.defaultExtension}", PhpFileType.INSTANCE, "<?php\n$fileText", System.currentTimeMillis(), false)
43+
PsiFileFactory.getInstance(p).createFileFromText(
44+
"DUMMY__.${PhpFileType.INSTANCE.defaultExtension}",
45+
PhpFileType.INSTANCE,
46+
"<?php\n$fileText",
47+
System.currentTimeMillis(),
48+
false
49+
)
4450

4551
}

src/main/kotlin/de/cawolf/quickmock/intention/service/AddMissingUseStatements.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ class AddMissingUseStatements {
1515
if (PRIMITIVES.contains(foldDocBlockTypeHintedArray.invoke(fqcn))) return false
1616

1717
val scopeHolder = PhpCodeInsightUtil.findScopeForUseOperator(namespace)
18-
if (scopeHolder != null && PhpCodeInsightUtil.findImportedName(scopeHolder, fqcn, PhpUseKeyword.CLASS) == null && PhpCodeInsightUtil.canImport(scopeHolder, fqcn, PhpUseKeyword.CLASS)) {
18+
if (scopeHolder != null && PhpCodeInsightUtil.findImportedName(
19+
scopeHolder,
20+
fqcn,
21+
PhpUseKeyword.CLASS
22+
) == null && PhpCodeInsightUtil.canImport(scopeHolder, fqcn, PhpUseKeyword.CLASS)
23+
) {
1924
PhpAliasImporter.insertUseStatement(fqcn, alias, scopeHolder)
2025
}
2126
return true

src/main/kotlin/de/cawolf/quickmock/intention/service/AddMockAssignment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class AddMockAssignment {
1111
fun invoke(project: Project, constructStatement: PsiElement, parameter: Parameter, parameterName: String) {
1212
val whitespaceType = IElementType.enumerate { it.toString() == "WHITE_SPACE" }.first()
1313
val mockAssignment = PhpPsiElementFactory.createStatement(
14-
project,
15-
"\$this->$parameterName = ${mockValueFromType(parameter, project)};"
14+
project,
15+
"\$this->$parameterName = ${mockValueFromType(parameter, project)};"
1616
)
1717

1818
val currentMethod = constructStatement.parent

src/main/kotlin/de/cawolf/quickmock/intention/service/AddNewlineBefore.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import com.jetbrains.php.lang.psi.PhpPsiElementFactory
88
class AddNewlineBefore {
99
fun invoke(psiElement: PsiElement, project: Project) {
1010
val currentMethod = psiElement.parent
11-
currentMethod.addBefore(PhpPsiElementFactory.createFromText(project, PsiWhiteSpace::class.java, "\n")!!, psiElement)
11+
currentMethod.addBefore(
12+
PhpPsiElementFactory.createFromText(project, PsiWhiteSpace::class.java, "\n")!!,
13+
psiElement
14+
)
1215
}
1316
}

0 commit comments

Comments
 (0)