Skip to content

Commit

Permalink
Fix DuplicateCustomExpectation
Browse files Browse the repository at this point in the history
  • Loading branch information
olivernybroe committed Aug 19, 2022
1 parent 21407a5 commit 9e79a75
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## [Unreleased]
### Fixed
- Fixed originalFile in iconProvider sometimes being null
- Fixed DuplicateCustomExpectation testing crashing on unfinished inspections

## [1.8.0]
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ val PsiFile.customExpects: List<MethodReferenceImpl>
fun MethodReferenceImpl.toMethod(): Method? {
val extendName = this.extendName ?: return null

// Custom expectations should always have two parameters.
if(this.parameters.count() != 2) {
return null
}

val closure = (this.parameters[1] as? PhpExpression)?.firstChild as? Function

if (closure === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.pestphp.pest.customExpectations
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiManager
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.testFramework.TestDataPath
import com.intellij.util.indexing.FileBasedIndex
import com.pestphp.pest.PestLightCodeFixture
import com.pestphp.pest.features.customExpectations.generators.Method
Expand All @@ -11,6 +12,7 @@ import com.pestphp.pest.features.customExpectations.CustomExpectationNotifier
import com.pestphp.pest.features.customExpectations.customExpects
import com.pestphp.pest.features.customExpectations.toMethod

@TestDataPath("\$CONTENT_ROOT/resources/com/pestphp/pest/customExpectations")
class CustomExpectationIndexTest : PestLightCodeFixture() {
override fun getTestDataPath(): String {
return "src/test/resources/com/pestphp/pest/customExpectations"
Expand Down Expand Up @@ -133,4 +135,18 @@ class CustomExpectationIndexTest : PestLightCodeFixture() {
"/src/subFolder/CustomExpectation.php"
)
}

fun testUnfinishedCustomExpectationIsNotIndexed() {
val virtualFile = myFixture.copyFileToProject("UnfinishedCustomExpectation.php")

val fileBasedIndex = FileBasedIndex.getInstance()

val values = fileBasedIndex.getValues(
CustomExpectationIndex.key,
"UnfinishedCustomExpectation.php",
GlobalSearchScope.projectScope(project)
).flatten()

assertSize(0, values)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

expect()->extend('toBeOne');

0 comments on commit 9e79a75

Please sign in to comment.