Skip to content

Commit 5acb2c5

Browse files
committed
fix: correct the data-provider index FQN and the test-method generator tail
- TestoDataProvidersIndex matched the non-existent \Testo\Sample\DataProvider, so it indexed nothing real. Point it at TestoClasses.DATA_PROVIDER (\Testo\Data\DataProvider) and bump getVersion() (1->2) so stale on-disk indexes rebuild on upgrade. - TestoGenerateTestMethodAction.fillVariablesSegments used substring(min(from, length-1)), which re-emitted the final char when a placeholder ended the template and threw StringIndexOutOfBounds on empty text. Emit the tail only when from < length.
1 parent 62e3411 commit 5acb2c5

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/main/kotlin/com/github/xepozz/testo/actions/TestoGenerateTestMethodAction.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import com.intellij.psi.PsiFile
1010
import com.jetbrains.php.lang.psi.elements.PhpClass
1111
import com.jetbrains.php.phpunit.PhpUnitTestDescriptor
1212
import java.util.*
13-
import kotlin.math.min
1413

1514
class TestoGenerateTestMethodAction : TestoGenerateMethodActionBase("Testo Test Method") {
1615
override fun isValidForFile(project: Project, editor: Editor, file: PsiFile) = file.isTestoFile()
@@ -32,7 +31,9 @@ class TestoGenerateTestMethodAction : TestoGenerateMethodActionBase("Testo Test
3231
while (true) {
3332
val index = methodText.indexOf("\${CAPITALIZED_NAME}", from)
3433
if (index < 0) {
35-
methodTemplate.addTextSegment(methodText.substring(min(from, methodText.length - 1)))
34+
// Emit only the remaining tail. The old min(from, length-1) re-emitted the final char when the
35+
// placeholder ended the template, and threw StringIndexOutOfBounds on empty input.
36+
if (from < methodText.length) methodTemplate.addTextSegment(methodText.substring(from))
3637
return
3738
}
3839

src/main/kotlin/com/github/xepozz/testo/index/TestoDataProvidersIndex.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.xepozz.testo.index
22

3+
import com.github.xepozz.testo.TestoClasses
34
import com.github.xepozz.testo.isTestoClass
45
import com.intellij.openapi.util.Pair
56
import com.intellij.openapi.util.text.StringUtil
@@ -51,7 +52,8 @@ class TestoDataProvidersIndex : FileBasedIndexExtension<String, TestoDataProvide
5152
override fun getValueExternalizer(): DataExternalizer<TestoDataProvidersIndexType> =
5253
DataProviderUsageExternalizer.INSTANCE
5354

54-
override fun getVersion() = 1
55+
// Bumped to 2 when DATA_PROVIDER_ATTRIBUTE was corrected, so stale (empty) on-disk indexes rebuild on upgrade.
56+
override fun getVersion() = 2
5557

5658
override fun getInputFilter() = FileBasedIndex.InputFilter { it.fileType is PhpFileType }
5759

@@ -104,14 +106,15 @@ class TestoDataProvidersIndex : FileBasedIndexExtension<String, TestoDataProvide
104106

105107
companion object Companion {
106108
val KEY = ID.create<String, TestoDataProvidersIndexType>("Testo.DataProviders")
107-
private const val PHPUNIT_DATA_PROVIDER_ATTRIBUTE = "\\Testo\\Sample\\DataProvider"
109+
// The real Testo data-provider attribute; the previous "\Testo\Sample\DataProvider" matched nothing.
110+
private const val DATA_PROVIDER_ATTRIBUTE = TestoClasses.DATA_PROVIDER
108111

109112
fun getDataProvidersFromAttributes(function: Function): MutableSet<Pair<String, String>> {
110113
val result = mutableSetOf<Pair<String, String>>()
111114

112115
val targetFQN = function.asSafely<Method>()?.containingClass?.fqn ?: function.fqn
113116

114-
for (dataProvider in function.getAttributes(PHPUNIT_DATA_PROVIDER_ATTRIBUTE)) {
117+
for (dataProvider in function.getAttributes(DATA_PROVIDER_ATTRIBUTE)) {
115118
val argument = getAttributeArgument(dataProvider, "provider", 0) ?: continue
116119
val methodNameArg = argument as? PhpExpectedFunctionScalarArgument ?: continue
117120
val attributeValue = methodNameArg.value

0 commit comments

Comments
 (0)