From 88e9f06ad150b4c6836c3ec24d285ac9726a6624 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 26 May 2022 11:16:41 +0200 Subject: [PATCH] Add inspection for checking if dataset exist --- CHANGELOG.md | 16 +- gradle.properties | 2 +- .../com/pestphp/pest/PestIconProvider.kt | 3 +- src/main/kotlin/com/pestphp/pest/PestIcons.kt | 1 - .../kotlin/com/pestphp/pest/PestNamingUtil.kt | 2 +- .../kotlin/com/pestphp/pest/PestSettings.kt | 7 +- .../com/pestphp/pest/PestTestFileUtil.kt | 9 +- src/main/kotlin/com/pestphp/pest/PestUtil.kt | 1 - .../ThisFieldsCompletionProvider.kt | 2 +- .../PestRunConfigurationHandler.kt | 3 +- .../PestRunConfigurationProducer.kt | 6 +- .../pest/coverage/PestCoverageEngine.kt | 2 +- .../CustomExpectationIndex.kt | 7 +- .../CustomExpectationListener.kt | 2 +- .../CustomExpectationNotifier.kt | 4 +- .../CustomExpectationStartupActivity.kt | 4 +- .../ExpectationFileService.kt | 1 - .../MethodDataExternalizer.kt | 4 +- .../customExpectations/expectationUtil.kt | 8 +- .../externalizers/MethodDataExternalizer.kt | 2 +- .../datasets/DataSetCompletionProvider.kt | 142 ++++++++++++++++++ .../datasets/DatasetCompletionContributor.kt | 125 ++------------- .../com/pestphp/pest/datasets/DatasetIndex.kt | 2 +- .../InvalidDatasetReferenceInspection.kt | 69 +++++++++ .../goto/PestTestGoToSymbolContributor.kt | 5 +- .../pestphp/pest/indexers/PestTestIndex.kt | 11 +- ...eMultipleExpectCallsToChainableQuickFix.kt | 2 +- .../ChangeTestNameCasingQuickFix.kt | 4 +- .../MultipleExpectChainableInspection.kt | 2 - .../SuppressUndefinedPropertyInspection.kt | 2 +- .../parser/PestConfigurationFileParser.kt | 10 +- .../SnapshotLineMarkerProvider.kt | 6 +- .../pest/snapshotTesting/SnapshotUtil.kt | 13 +- .../StatementSurroundDescriptor.kt | 4 +- .../pest/templates/PestItPostfixTemplate.kt | 2 +- .../templates/PestPostfixTemplateProvider.kt | 2 +- .../templates/PestRootTemplateContextType.kt | 2 +- .../types/HigherOrderExtendTypeProvider.kt | 6 +- .../pestphp/pest/types/ThisTypeProvider.kt | 3 - src/main/resources/META-INF/pest-coverage.xml | 4 +- src/main/resources/META-INF/plugin.xml | 14 +- src/main/resources/META-INF/pluginIcon.svg | 20 +-- src/main/resources/config@dark.svg | 9 +- src/main/resources/config@light.svg | 9 +- src/main/resources/dataset@dark.svg | 6 +- src/main/resources/dataset@light.svg | 6 +- src/main/resources/file@dark.svg | 6 +- src/main/resources/file@light.svg | 6 +- .../resources/library/Pest/.phpstorm.meta.php | 1 + src/main/resources/liveTemplates/PestPHP.xml | 26 ++-- src/main/resources/logo@dark.svg | 20 +-- src/main/resources/logo@light.svg | 6 +- .../pest/datasets/DatasetCompletionTest.kt | 13 +- .../pestphp/pest/datasets/DatasetGoToTest.kt | 15 +- .../InvalidDatasetReferenceInspectionTest.kt | 29 ++++ .../pest/datasets/AutocompleteDatasetTest.php | 12 ++ .../pest/datasets/DatasetOnNonPestTest.php | 5 + .../DatasetOnNonPestTestCompletion.php | 5 + .../com/pestphp/pest/datasets/DatasetTest.php | 2 +- .../com/pestphp/pest/datasets/Datasets.php | 7 - .../pest/datasets/InvalidDatasetTest.php | 12 ++ .../pest/datasets/SharedDatasetReference.php | 2 +- 62 files changed, 448 insertions(+), 285 deletions(-) create mode 100644 src/main/kotlin/com/pestphp/pest/datasets/DataSetCompletionProvider.kt create mode 100644 src/main/kotlin/com/pestphp/pest/datasets/InvalidDatasetReferenceInspection.kt create mode 100644 src/test/kotlin/com/pestphp/pest/datasets/InvalidDatasetReferenceInspectionTest.kt create mode 100644 src/test/resources/com/pestphp/pest/datasets/AutocompleteDatasetTest.php create mode 100644 src/test/resources/com/pestphp/pest/datasets/DatasetOnNonPestTest.php create mode 100644 src/test/resources/com/pestphp/pest/datasets/DatasetOnNonPestTestCompletion.php create mode 100644 src/test/resources/com/pestphp/pest/datasets/InvalidDatasetTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ab8f8c..e29686be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,14 +3,20 @@ # PEST IntelliJ Changelog ## [Unreleased] +### Added +- Added inspection for checking if dataset exists + +### Fixed +- Fixed dataset autocompletion triggering on all strings +- Fixed dataset goto triggering on all strings ## [1.6.0] -### Added -- Added converting multiple `expect` to `and` calls instead -- Added dataset completion -- Added dataset goto +### Added +- Added converting multiple `expect` to `and` calls instead +- Added dataset completion +- Added dataset goto -### Fixed +### Fixed - Fixed automatic case changing on multicased string ## [1.5.0] diff --git a/gradle.properties b/gradle.properties index 362a4606..f42c49ea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ pluginGroup = com.pestphp pluginName = PEST PHP -pluginVersion = 1.6.0 +pluginVersion = 1.6.1 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. diff --git a/src/main/kotlin/com/pestphp/pest/PestIconProvider.kt b/src/main/kotlin/com/pestphp/pest/PestIconProvider.kt index d75cb969..31e528a7 100644 --- a/src/main/kotlin/com/pestphp/pest/PestIconProvider.kt +++ b/src/main/kotlin/com/pestphp/pest/PestIconProvider.kt @@ -17,8 +17,7 @@ class PestIconProvider : IconProvider() { return runReadAction { findIconFromPsiFile(element) } } - private fun findIconFromPsiFile(file: PsiFile): Icon? - { + private fun findIconFromPsiFile(file: PsiFile): Icon? { if (file.isPestTestFile()) { return PestIcons.FILE } diff --git a/src/main/kotlin/com/pestphp/pest/PestIcons.kt b/src/main/kotlin/com/pestphp/pest/PestIcons.kt index 5fdc9d68..a76e3080 100644 --- a/src/main/kotlin/com/pestphp/pest/PestIcons.kt +++ b/src/main/kotlin/com/pestphp/pest/PestIcons.kt @@ -4,7 +4,6 @@ import com.intellij.icons.AllIcons import com.intellij.ide.ui.LafManager import com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo import com.intellij.openapi.util.IconLoader -import com.jetbrains.php.PhpIcons object PestIcons { val LOGO = IconLoader.getIcon("/logo@${getThemeString()}.svg", PestIcons.javaClass) diff --git a/src/main/kotlin/com/pestphp/pest/PestNamingUtil.kt b/src/main/kotlin/com/pestphp/pest/PestNamingUtil.kt index d154dabd..651d7fee 100644 --- a/src/main/kotlin/com/pestphp/pest/PestNamingUtil.kt +++ b/src/main/kotlin/com/pestphp/pest/PestNamingUtil.kt @@ -9,7 +9,7 @@ import com.jetbrains.php.lang.psi.elements.StringLiteralExpression import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl import com.jetbrains.php.run.remote.PhpRemoteInterpreterManager import com.jetbrains.php.util.pathmapper.PhpPathMapper -import java.util.Locale +import java.util.* fun FunctionReferenceImpl.getPestTestName(): String? { val testName = (getParameter(0) as? StringLiteralExpression)?.contents diff --git a/src/main/kotlin/com/pestphp/pest/PestSettings.kt b/src/main/kotlin/com/pestphp/pest/PestSettings.kt index 685916ba..2603c6fc 100644 --- a/src/main/kotlin/com/pestphp/pest/PestSettings.kt +++ b/src/main/kotlin/com/pestphp/pest/PestSettings.kt @@ -1,11 +1,6 @@ package com.pestphp.pest -import com.intellij.openapi.components.PersistentStateComponent -import com.intellij.openapi.components.Service -import com.intellij.openapi.components.ServiceManager -import com.intellij.openapi.components.State -import com.intellij.openapi.components.Storage -import com.intellij.openapi.components.service +import com.intellij.openapi.components.* import com.intellij.openapi.project.Project import com.intellij.util.xmlb.XmlSerializerUtil import com.pestphp.pest.parser.PestConfigurationFile diff --git a/src/main/kotlin/com/pestphp/pest/PestTestFileUtil.kt b/src/main/kotlin/com/pestphp/pest/PestTestFileUtil.kt index 8a293d84..f57fca77 100644 --- a/src/main/kotlin/com/pestphp/pest/PestTestFileUtil.kt +++ b/src/main/kotlin/com/pestphp/pest/PestTestFileUtil.kt @@ -7,15 +7,8 @@ import com.intellij.psi.util.CachedValue import com.intellij.psi.util.CachedValueProvider import com.intellij.psi.util.CachedValuesManager import com.intellij.psi.util.PsiTreeUtil -import com.jetbrains.php.lang.psi.elements.AssignmentExpression -import com.jetbrains.php.lang.psi.elements.ClassConstantReference -import com.jetbrains.php.lang.psi.elements.ClassReference -import com.jetbrains.php.lang.psi.elements.FieldReference +import com.jetbrains.php.lang.psi.elements.* import com.jetbrains.php.lang.psi.elements.Function -import com.jetbrains.php.lang.psi.elements.FunctionReference -import com.jetbrains.php.lang.psi.elements.ParameterList -import com.jetbrains.php.lang.psi.elements.Statement -import com.jetbrains.php.lang.psi.elements.Variable import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl import com.jetbrains.php.lang.psi.resolve.types.PhpType diff --git a/src/main/kotlin/com/pestphp/pest/PestUtil.kt b/src/main/kotlin/com/pestphp/pest/PestUtil.kt index 5e6b4bac..37cca8d3 100644 --- a/src/main/kotlin/com/pestphp/pest/PestUtil.kt +++ b/src/main/kotlin/com/pestphp/pest/PestUtil.kt @@ -9,7 +9,6 @@ import com.jetbrains.php.lang.psi.PhpFile import com.jetbrains.php.lang.psi.elements.PhpNamespace import com.jetbrains.php.lang.psi.elements.PhpPsiElement import com.jetbrains.php.lang.psi.elements.Statement -import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl import com.jetbrains.php.phpunit.PhpUnitUtil import com.jetbrains.php.testFramework.PhpTestFrameworkSettingsManager diff --git a/src/main/kotlin/com/pestphp/pest/completion/ThisFieldsCompletionProvider.kt b/src/main/kotlin/com/pestphp/pest/completion/ThisFieldsCompletionProvider.kt index c58ef6a1..450249f2 100644 --- a/src/main/kotlin/com/pestphp/pest/completion/ThisFieldsCompletionProvider.kt +++ b/src/main/kotlin/com/pestphp/pest/completion/ThisFieldsCompletionProvider.kt @@ -34,7 +34,7 @@ class ThisFieldsCompletionProvider : CompletionProvider(), if (!variable.isThisVariableInPest { it.isAnyPestFunction() }) return return (fieldReference.containingFile).getAllBeforeThisAssignments() - .filter { it.variable?.name !== null } + .filter { it.variable?.name !== null } .forEach { result.addElement( LookupElementBuilder.create(it.variable!!.name!!) diff --git a/src/main/kotlin/com/pestphp/pest/configuration/PestRunConfigurationHandler.kt b/src/main/kotlin/com/pestphp/pest/configuration/PestRunConfigurationHandler.kt index cac9c8d3..75893877 100644 --- a/src/main/kotlin/com/pestphp/pest/configuration/PestRunConfigurationHandler.kt +++ b/src/main/kotlin/com/pestphp/pest/configuration/PestRunConfigurationHandler.kt @@ -10,7 +10,8 @@ class PestRunConfigurationHandler : PhpTestRunConfigurationHandler { var rootPath: String? = null companion object { - @JvmField val instance = PestRunConfigurationHandler() + @JvmField + val instance = PestRunConfigurationHandler() } override fun getConfigFileOption(): String { diff --git a/src/main/kotlin/com/pestphp/pest/configuration/PestRunConfigurationProducer.kt b/src/main/kotlin/com/pestphp/pest/configuration/PestRunConfigurationProducer.kt index a1b6da34..344c0a7a 100644 --- a/src/main/kotlin/com/pestphp/pest/configuration/PestRunConfigurationProducer.kt +++ b/src/main/kotlin/com/pestphp/pest/configuration/PestRunConfigurationProducer.kt @@ -14,11 +14,7 @@ import com.intellij.util.Function import com.jetbrains.php.lang.PhpFileType import com.jetbrains.php.testFramework.run.PhpDefaultTestRunnerSettingsValidator import com.jetbrains.php.testFramework.run.PhpTestConfigurationProducer -import com.pestphp.pest.getPestTestName -import com.pestphp.pest.isPestConfigurationFile -import com.pestphp.pest.isPestEnabled -import com.pestphp.pest.isPestTestFile -import com.pestphp.pest.isPestTestReference +import com.pestphp.pest.* class PestRunConfigurationProducer : PhpTestConfigurationProducer( VALIDATOR, diff --git a/src/main/kotlin/com/pestphp/pest/coverage/PestCoverageEngine.kt b/src/main/kotlin/com/pestphp/pest/coverage/PestCoverageEngine.kt index bad84066..80d4b0ed 100644 --- a/src/main/kotlin/com/pestphp/pest/coverage/PestCoverageEngine.kt +++ b/src/main/kotlin/com/pestphp/pest/coverage/PestCoverageEngine.kt @@ -7,7 +7,7 @@ import com.intellij.execution.configurations.RunConfigurationBase import com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration import com.jetbrains.php.phpunit.coverage.PhpUnitCoverageEngine import com.pestphp.pest.configuration.PestRunConfiguration -import java.util.Date +import java.util.* class PestCoverageEngine : PhpUnitCoverageEngine() { override fun isApplicableTo(conf: RunConfigurationBase<*>): Boolean { diff --git a/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationIndex.kt b/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationIndex.kt index 1a87a222..8efa0ba0 100644 --- a/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationIndex.kt +++ b/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationIndex.kt @@ -2,12 +2,7 @@ package com.pestphp.pest.customExpectations import com.intellij.openapi.vfs.VirtualFile -import com.intellij.util.indexing.DataIndexer -import com.intellij.util.indexing.DefaultFileTypeSpecificInputFilter -import com.intellij.util.indexing.FileBasedIndex -import com.intellij.util.indexing.FileBasedIndexExtension -import com.intellij.util.indexing.FileContent -import com.intellij.util.indexing.ID +import com.intellij.util.indexing.* import com.intellij.util.io.DataExternalizer import com.intellij.util.io.EnumeratorStringDescriptor import com.intellij.util.io.KeyDescriptor diff --git a/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationListener.kt b/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationListener.kt index 3adc125d..09ee2555 100644 --- a/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationListener.kt +++ b/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationListener.kt @@ -7,7 +7,7 @@ import com.intellij.psi.PsiFile import com.jetbrains.php.lang.psi.PhpFile import com.pestphp.pest.customExpectations.generators.Method -class CustomExpectationListener(private val project: Project): CustomExpectationNotifier { +class CustomExpectationListener(private val project: Project) : CustomExpectationNotifier { override fun changedExpectation(file: PsiFile, customExpectations: List) { val expectationFileService = project.service() diff --git a/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationNotifier.kt b/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationNotifier.kt index 619c4d72..bd4eeb93 100644 --- a/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationNotifier.kt +++ b/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationNotifier.kt @@ -3,9 +3,9 @@ package com.pestphp.pest.customExpectations import com.intellij.psi.PsiFile import com.intellij.util.messages.Topic import com.pestphp.pest.customExpectations.generators.Method -import java.util.EventListener +import java.util.* -interface CustomExpectationNotifier: EventListener { +interface CustomExpectationNotifier : EventListener { companion object { @Topic.ProjectLevel val TOPIC = Topic.create("Custom expectation", CustomExpectationNotifier::class.java) diff --git a/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationStartupActivity.kt b/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationStartupActivity.kt index 1bd10fcb..7c80b25d 100644 --- a/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationStartupActivity.kt +++ b/src/main/kotlin/com/pestphp/pest/customExpectations/CustomExpectationStartupActivity.kt @@ -12,7 +12,7 @@ import com.jetbrains.php.lang.psi.PhpFile /** * Adds all methods to the expectation file service which has been indexed already. */ -class CustomExpectationStartupActivity: StartupActivity { +class CustomExpectationStartupActivity : StartupActivity { override fun runActivity(project: Project) { val fileBasedIndex = FileBasedIndex.getInstance() val expectationFileService = project.service() @@ -45,7 +45,7 @@ class CustomExpectationStartupActivity: StartupActivity { it.value ) } - expectationFileService.generateFile { } + expectationFileService.generateFile { } } } diff --git a/src/main/kotlin/com/pestphp/pest/customExpectations/ExpectationFileService.kt b/src/main/kotlin/com/pestphp/pest/customExpectations/ExpectationFileService.kt index f38cc7dc..1b34115c 100644 --- a/src/main/kotlin/com/pestphp/pest/customExpectations/ExpectationFileService.kt +++ b/src/main/kotlin/com/pestphp/pest/customExpectations/ExpectationFileService.kt @@ -10,7 +10,6 @@ import com.intellij.psi.PsiManager import com.intellij.util.SlowOperations import com.jetbrains.php.composer.lib.ComposerLibraryManager import com.jetbrains.php.lang.psi.PhpFile -import com.jetbrains.rd.util.first import com.pestphp.pest.customExpectations.generators.ExpectationGenerator import com.pestphp.pest.customExpectations.generators.Method import com.pestphp.pest.realPath diff --git a/src/main/kotlin/com/pestphp/pest/customExpectations/MethodDataExternalizer.kt b/src/main/kotlin/com/pestphp/pest/customExpectations/MethodDataExternalizer.kt index 89715bf3..cd1cd000 100644 --- a/src/main/kotlin/com/pestphp/pest/customExpectations/MethodDataExternalizer.kt +++ b/src/main/kotlin/com/pestphp/pest/customExpectations/MethodDataExternalizer.kt @@ -43,8 +43,8 @@ class MethodDataExternalizer : DataExternalizer { returnType = PhpType.builder() .add( Regex("returnType='(.*?)'") - .find(it)!! - .groupValues[1] + .find(it)!! + .groupValues[1] ).build(), defaultValue = Regex("defaultValue='(.*)'") .find(it)!! diff --git a/src/main/kotlin/com/pestphp/pest/customExpectations/expectationUtil.kt b/src/main/kotlin/com/pestphp/pest/customExpectations/expectationUtil.kt index 95901445..1b236020 100644 --- a/src/main/kotlin/com/pestphp/pest/customExpectations/expectationUtil.kt +++ b/src/main/kotlin/com/pestphp/pest/customExpectations/expectationUtil.kt @@ -6,14 +6,8 @@ import com.intellij.psi.PsiFile import com.intellij.psi.util.PsiTreeUtil import com.jetbrains.php.PhpIndex import com.jetbrains.php.lang.psi.PhpFile +import com.jetbrains.php.lang.psi.elements.* import com.jetbrains.php.lang.psi.elements.Function -import com.jetbrains.php.lang.psi.elements.MethodReference -import com.jetbrains.php.lang.psi.elements.ParameterList -import com.jetbrains.php.lang.psi.elements.PhpExpression -import com.jetbrains.php.lang.psi.elements.PhpNamespace -import com.jetbrains.php.lang.psi.elements.Statement -import com.jetbrains.php.lang.psi.elements.StringLiteralExpression -import com.jetbrains.php.lang.psi.elements.Variable import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl import com.jetbrains.php.lang.psi.elements.impl.MethodReferenceImpl import com.jetbrains.php.lang.psi.resolve.types.PhpType diff --git a/src/main/kotlin/com/pestphp/pest/customExpectations/externalizers/MethodDataExternalizer.kt b/src/main/kotlin/com/pestphp/pest/customExpectations/externalizers/MethodDataExternalizer.kt index aaafcddd..2de26891 100644 --- a/src/main/kotlin/com/pestphp/pest/customExpectations/externalizers/MethodDataExternalizer.kt +++ b/src/main/kotlin/com/pestphp/pest/customExpectations/externalizers/MethodDataExternalizer.kt @@ -13,7 +13,7 @@ class MethodDataExternalizer : DataExternalizer { override fun save(out: DataOutput, value: Method) { EnumeratorStringDescriptor.INSTANCE.save(out, value.name) - PhpTypeDataExternalizer.INSTANCE.save(out,value.returnType) + PhpTypeDataExternalizer.INSTANCE.save(out, value.returnType) ListDataExternalizer(ParameterDataExternalizer.INSTANCE).save( out, value.parameters diff --git a/src/main/kotlin/com/pestphp/pest/datasets/DataSetCompletionProvider.kt b/src/main/kotlin/com/pestphp/pest/datasets/DataSetCompletionProvider.kt new file mode 100644 index 00000000..482919fc --- /dev/null +++ b/src/main/kotlin/com/pestphp/pest/datasets/DataSetCompletionProvider.kt @@ -0,0 +1,142 @@ +package com.pestphp.pest.datasets + +import com.intellij.codeInsight.completion.CompletionParameters +import com.intellij.codeInsight.completion.CompletionProvider +import com.intellij.codeInsight.completion.CompletionResultSet +import com.intellij.codeInsight.lookup.LookupElementBuilder +import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler +import com.intellij.openapi.editor.Editor +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiManager +import com.intellij.psi.search.GlobalSearchScope +import com.intellij.psi.util.elementType +import com.intellij.util.ProcessingContext +import com.intellij.util.indexing.FileBasedIndex +import com.jetbrains.php.lang.lexer.PhpTokenTypes +import com.jetbrains.php.lang.psi.elements.StringLiteralExpression +import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl +import com.pestphp.pest.getRootPhpPsiElements +import com.pestphp.pest.isPestTestReference + +class DataSetCompletionProvider : CompletionProvider(), GotoDeclarationHandler { + override fun addCompletions( + parameters: CompletionParameters, + context: ProcessingContext, + result: CompletionResultSet + ) { + val isPestTest = parameters.position + // String literal (dataset name) + .parent + // Parameter list (with call parameters) + .parent + // Method reference (pest test call) + .parent + // Check if method reference is a pest test + .isPestTestReference() + if (!isPestTest) { + return + } + + val fileBasedIndex = FileBasedIndex.getInstance() + + // Get all shared datasets + val sharedDatasets = fileBasedIndex.getAllKeys(DatasetIndex.key, parameters.originalFile.project) + .map { + fileBasedIndex.getValues( + DatasetIndex.key, + it, + GlobalSearchScope.projectScope(parameters.originalFile.project) + ) + } + .flatten() + .flatten() + + // Get all datasets in the same file + val localDatasets = parameters.originalFile + .getRootPhpPsiElements() + .filter { it.isPestDataset() } + .filterIsInstance() + .mapNotNull { it.getPestDatasetName() } + + listOf( + *sharedDatasets.toTypedArray(), + *localDatasets.toTypedArray(), + ).forEach { + result.addElement( + LookupElementBuilder.create(it) + ) + } + } + + override fun getGotoDeclarationTargets( + sourceElement: PsiElement?, + offset: Int, + editor: Editor + ): Array { + if (sourceElement?.elementType !in listOf( + PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE, + PhpTokenTypes.STRING_LITERAL + ) + ) { + return PsiElement.EMPTY_ARRAY + } + + val parent = sourceElement?.parent + if (parent !is StringLiteralExpression) { + return PsiElement.EMPTY_ARRAY + } + + val isPestTest = parent + // Parameter list (with call parameters) + .parent + // Method reference (pest test call) + .parent + // Check if method reference is a pest test + .isPestTestReference() + if (!isPestTest) { + return PsiElement.EMPTY_ARRAY + } + + val fileBasedIndex = FileBasedIndex.getInstance() + val datasetName = parent.contents + + val foundDatasets = mutableListOf() + + fileBasedIndex.getAllKeys( + DatasetIndex.key, + parent.project + ).forEach { key -> + fileBasedIndex.processValues( + DatasetIndex.key, + key, + null, + { file, datasets -> + if (datasetName !in datasets) { + return@processValues true + } + + // Add all shared datasets which matches + PsiManager.getInstance(parent.project).findFile(file)!! + .getRootPhpPsiElements() + .filter { it.isPestDataset() } + .filterIsInstance() + .filter { it.getPestDatasetName() == datasetName } + .forEach { foundDatasets.add(it) } + + true + }, + GlobalSearchScope.projectScope(parent.project) + ) + } + + // Add all local datasets which matches + parent.containingFile + .getRootPhpPsiElements() + .filter { it.isPestDataset() } + .filterIsInstance() + .filter { it.getPestDatasetName() == datasetName } + .forEach { foundDatasets.add(it) } + + return foundDatasets.toTypedArray() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/pestphp/pest/datasets/DatasetCompletionContributor.kt b/src/main/kotlin/com/pestphp/pest/datasets/DatasetCompletionContributor.kt index 9e93b881..72dbc7ae 100644 --- a/src/main/kotlin/com/pestphp/pest/datasets/DatasetCompletionContributor.kt +++ b/src/main/kotlin/com/pestphp/pest/datasets/DatasetCompletionContributor.kt @@ -1,127 +1,22 @@ package com.pestphp.pest.datasets -import com.intellij.codeInsight.completion.* -import com.intellij.codeInsight.lookup.LookupElementBuilder -import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler -import com.intellij.openapi.editor.Editor +import com.intellij.codeInsight.completion.CompletionContributor +import com.intellij.codeInsight.completion.CompletionType import com.intellij.patterns.PlatformPatterns -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiManager -import com.intellij.psi.search.GlobalSearchScope -import com.intellij.psi.util.elementType -import com.intellij.util.ProcessingContext -import com.intellij.util.indexing.FileBasedIndex -import com.jetbrains.php.lang.lexer.PhpTokenTypes -import com.jetbrains.php.lang.psi.elements.FieldReference +import com.jetbrains.php.lang.psi.elements.ParameterList import com.jetbrains.php.lang.psi.elements.StringLiteralExpression -import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl -import com.pestphp.pest.getAllBeforeThisAssignments -import com.pestphp.pest.getRootPhpPsiElements -import com.pestphp.pest.isAnyPestFunction -import com.pestphp.pest.isThisVariableInPest +import com.jetbrains.php.lang.psi.elements.impl.MethodReferenceImpl - -class DatasetCompletionContributor: CompletionContributor() { +class DatasetCompletionContributor : CompletionContributor() { init { extend( CompletionType.BASIC, - PlatformPatterns.psiElement().withParent( - StringLiteralExpression::class.java + PlatformPatterns.psiElement().withParents( + StringLiteralExpression::class.java, + ParameterList::class.java, + MethodReferenceImpl::class.java, ), DataSetCompletionProvider() ) } - - class DataSetCompletionProvider: CompletionProvider(), GotoDeclarationHandler { - override fun addCompletions( - parameters: CompletionParameters, - context: ProcessingContext, - result: CompletionResultSet - ) { - val fileBasedIndex = FileBasedIndex.getInstance() - - // Get all shared datasets - val sharedDatasets = fileBasedIndex.getAllKeys(DatasetIndex.key, parameters.originalFile.project) - .map { fileBasedIndex.getValues( - DatasetIndex.key, - it, - GlobalSearchScope.projectScope(parameters.originalFile.project) - ) } - .flatten() - .flatten() - - // Get all datasets in the same file - val localDatasets = parameters.originalFile - .getRootPhpPsiElements() - .filter { it.isPestDataset() } - .filterIsInstance() - .mapNotNull { it.getPestDatasetName() } - - listOf( - *sharedDatasets.toTypedArray(), - *localDatasets.toTypedArray(), - ).forEach { - result.addElement( - LookupElementBuilder.create(it) - ) - } - } - - override fun getGotoDeclarationTargets( - sourceElement: PsiElement?, - offset: Int, - editor: Editor - ): Array { - if (sourceElement?.elementType !in listOf(PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE, PhpTokenTypes.STRING_LITERAL)) { - return PsiElement.EMPTY_ARRAY - } - - val parent = sourceElement?.parent - if (parent !is StringLiteralExpression) { - return PsiElement.EMPTY_ARRAY - } - - val fileBasedIndex = FileBasedIndex.getInstance() - val datasetName = parent.contents - - val foundDatasets = mutableListOf() - - fileBasedIndex.getAllKeys( - DatasetIndex.key, - parent.project - ).forEach { key -> - fileBasedIndex.processValues( - DatasetIndex.key, - key, - null, - { file, datasets -> - if (datasetName !in datasets) { - return@processValues true - } - - // Add all shared datasets which matches - PsiManager.getInstance(parent.project).findFile(file)!! - .getRootPhpPsiElements() - .filter { it.isPestDataset() } - .filterIsInstance() - .filter { it.getPestDatasetName() == datasetName } - .forEach { foundDatasets.add(it) } - - true - }, - GlobalSearchScope.projectScope(parent.project) - ) - } - - // Add all local datasets which matches - parent.containingFile - .getRootPhpPsiElements() - .filter { it.isPestDataset() } - .filterIsInstance() - .filter { it.getPestDatasetName() == datasetName } - .forEach { foundDatasets.add(it) } - - return foundDatasets.toTypedArray() - } - } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/pestphp/pest/datasets/DatasetIndex.kt b/src/main/kotlin/com/pestphp/pest/datasets/DatasetIndex.kt index 26a13e7d..c041b907 100644 --- a/src/main/kotlin/com/pestphp/pest/datasets/DatasetIndex.kt +++ b/src/main/kotlin/com/pestphp/pest/datasets/DatasetIndex.kt @@ -39,7 +39,7 @@ class DatasetIndex : FileBasedIndexExtension>() { .filterIsInstance() .mapNotNull { it.getPestDatasetName() } - if(datasets.isEmpty()) { + if (datasets.isEmpty()) { return@DataIndexer mapOf() } diff --git a/src/main/kotlin/com/pestphp/pest/datasets/InvalidDatasetReferenceInspection.kt b/src/main/kotlin/com/pestphp/pest/datasets/InvalidDatasetReferenceInspection.kt new file mode 100644 index 00000000..97d38c13 --- /dev/null +++ b/src/main/kotlin/com/pestphp/pest/datasets/InvalidDatasetReferenceInspection.kt @@ -0,0 +1,69 @@ +package com.pestphp.pest.datasets + +import com.intellij.codeInspection.LocalQuickFix +import com.intellij.codeInspection.ProblemHighlightType +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.psi.PsiElementVisitor +import com.intellij.psi.search.GlobalSearchScope +import com.intellij.util.indexing.FileBasedIndex +import com.jetbrains.php.lang.inspections.PhpInspection +import com.jetbrains.php.lang.psi.PhpFile +import com.jetbrains.php.lang.psi.elements.StringLiteralExpression +import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl +import com.jetbrains.php.lang.psi.elements.impl.MethodReferenceImpl +import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor +import com.pestphp.pest.getPestTests +import com.pestphp.pest.getRootPhpPsiElements + +class InvalidDatasetReferenceInspection : PhpInspection() { + companion object { + private const val DESCRIPTION = "The dataset does not exist." + } + + override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { + return object : PhpElementVisitor() { + override fun visitPhpFile(file: PhpFile) { + val localDatasets = file.getRootPhpPsiElements() + .filter { it.isPestDataset() } + .filterIsInstance() + .mapNotNull { it.getPestDatasetName() } + // Get all shared datasets + val fileBasedIndex = FileBasedIndex.getInstance() + val sharedDatasets = fileBasedIndex.getAllKeys(DatasetIndex.key, file.project) + .map { + fileBasedIndex.getValues( + DatasetIndex.key, + it, + GlobalSearchScope.projectScope(file.project) + ) + } + .flatten() + .flatten() + + file.getPestTests() + // Has to be a method reference, as else there is no dataset + .filterIsInstance() + .filter { it.name == "with" } + .mapNotNull { it.parameters[0] } + .filterIsInstance() + .filter { it.contents !in localDatasets && it.contents !in sharedDatasets } + .forEach { + declareProblemType( + holder, + it + ) + } + } + } + } + + @Suppress("SpreadOperator") + private fun declareProblemType(holder: ProblemsHolder, datasetName: StringLiteralExpression) { + holder.registerProblem( + datasetName, + DESCRIPTION, + ProblemHighlightType.ERROR, + *LocalQuickFix.EMPTY_ARRAY + ) + } +} diff --git a/src/main/kotlin/com/pestphp/pest/goto/PestTestGoToSymbolContributor.kt b/src/main/kotlin/com/pestphp/pest/goto/PestTestGoToSymbolContributor.kt index e226c878..e15a8ab5 100644 --- a/src/main/kotlin/com/pestphp/pest/goto/PestTestGoToSymbolContributor.kt +++ b/src/main/kotlin/com/pestphp/pest/goto/PestTestGoToSymbolContributor.kt @@ -14,12 +14,11 @@ import com.pestphp.pest.PestIcons import com.pestphp.pest.getPestTestName import com.pestphp.pest.getPestTests import com.pestphp.pest.indexers.PestTestIndex -import javax.swing.Icon /** * Adds support for navigating to pest tests via the symbol searching */ -class PestTestGoToSymbolContributor: ChooseByNameContributor { +class PestTestGoToSymbolContributor : ChooseByNameContributor { override fun getNames(project: Project, includeNonProjectItems: Boolean): Array { val index = FileBasedIndex.getInstance() @@ -81,7 +80,7 @@ class PestTestGoToSymbolContributor: ChooseByNameContributor { .toTypedArray() } - class PestTestFunctionReference(private val functionReference: FunctionReference): NavigationItem { + class PestTestFunctionReference(private val functionReference: FunctionReference) : NavigationItem { override fun getPresentation(): ItemPresentation { val location = PhpPresentationUtil.getPresentablePathForFile( functionReference.containingFile.virtualFile, diff --git a/src/main/kotlin/com/pestphp/pest/indexers/PestTestIndex.kt b/src/main/kotlin/com/pestphp/pest/indexers/PestTestIndex.kt index 4e7d449f..1e3c774e 100644 --- a/src/main/kotlin/com/pestphp/pest/indexers/PestTestIndex.kt +++ b/src/main/kotlin/com/pestphp/pest/indexers/PestTestIndex.kt @@ -1,18 +1,9 @@ package com.pestphp.pest.indexers -import com.intellij.openapi.project.ProjectManager -import com.intellij.openapi.roots.TestSourcesFilter -import com.intellij.openapi.vfs.VirtualFile -import com.intellij.util.indexing.DataIndexer -import com.intellij.util.indexing.DefaultFileTypeSpecificInputFilter -import com.intellij.util.indexing.FileBasedIndex -import com.intellij.util.indexing.FileBasedIndexExtension -import com.intellij.util.indexing.FileContent -import com.intellij.util.indexing.ID +import com.intellij.util.indexing.* import com.intellij.util.io.DataExternalizer import com.intellij.util.io.EnumeratorStringDescriptor import com.intellij.util.io.KeyDescriptor -import com.jetbrains.php.lang.PhpFileType import com.jetbrains.php.lang.psi.stubs.indexes.StringSetDataExternalizer import com.pestphp.pest.PhpTestFolderInputFilter import com.pestphp.pest.getPestTestName diff --git a/src/main/kotlin/com/pestphp/pest/inspections/ChangeMultipleExpectCallsToChainableQuickFix.kt b/src/main/kotlin/com/pestphp/pest/inspections/ChangeMultipleExpectCallsToChainableQuickFix.kt index 5b0c5930..abd82a47 100644 --- a/src/main/kotlin/com/pestphp/pest/inspections/ChangeMultipleExpectCallsToChainableQuickFix.kt +++ b/src/main/kotlin/com/pestphp/pest/inspections/ChangeMultipleExpectCallsToChainableQuickFix.kt @@ -8,7 +8,7 @@ import com.jetbrains.php.lang.psi.elements.MethodReference import com.jetbrains.php.lang.psi.elements.Statement import com.pestphp.pest.customExpectations.isExpectation -class ChangeMultipleExpectCallsToChainableQuickFix: LocalQuickFix { +class ChangeMultipleExpectCallsToChainableQuickFix : LocalQuickFix { companion object { const val QUICK_FIX_NAME = "Change multiple expect call into chain" } diff --git a/src/main/kotlin/com/pestphp/pest/inspections/ChangeTestNameCasingQuickFix.kt b/src/main/kotlin/com/pestphp/pest/inspections/ChangeTestNameCasingQuickFix.kt index 0ff8696c..0fea380d 100644 --- a/src/main/kotlin/com/pestphp/pest/inspections/ChangeTestNameCasingQuickFix.kt +++ b/src/main/kotlin/com/pestphp/pest/inspections/ChangeTestNameCasingQuickFix.kt @@ -4,12 +4,10 @@ import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemDescriptor import com.intellij.openapi.project.Project import com.jetbrains.php.lang.psi.PhpPsiElementFactory -import com.jetbrains.php.lang.psi.elements.FunctionReference import com.jetbrains.php.lang.psi.elements.StringLiteralExpression -import com.pestphp.pest.getPestTestName import net.pearx.kasechange.splitToWords -class ChangeTestNameCasingQuickFix: LocalQuickFix { +class ChangeTestNameCasingQuickFix : LocalQuickFix { companion object { const val QUICK_FIX_NAME = "Change test name casing to sentence case" } diff --git a/src/main/kotlin/com/pestphp/pest/inspections/MultipleExpectChainableInspection.kt b/src/main/kotlin/com/pestphp/pest/inspections/MultipleExpectChainableInspection.kt index edc81273..62864020 100644 --- a/src/main/kotlin/com/pestphp/pest/inspections/MultipleExpectChainableInspection.kt +++ b/src/main/kotlin/com/pestphp/pest/inspections/MultipleExpectChainableInspection.kt @@ -1,6 +1,5 @@ package com.pestphp.pest.inspections -import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ProblemsHolder import com.intellij.psi.PsiElementVisitor @@ -9,7 +8,6 @@ import com.jetbrains.php.lang.psi.elements.GroupStatement import com.jetbrains.php.lang.psi.elements.MethodReference import com.jetbrains.php.lang.psi.elements.Statement import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor -import com.jetbrains.rd.util.first import com.pestphp.pest.customExpectations.isExpectation class MultipleExpectChainableInspection : PhpInspection() { diff --git a/src/main/kotlin/com/pestphp/pest/inspections/SuppressUndefinedPropertyInspection.kt b/src/main/kotlin/com/pestphp/pest/inspections/SuppressUndefinedPropertyInspection.kt index b62f3589..72e08569 100644 --- a/src/main/kotlin/com/pestphp/pest/inspections/SuppressUndefinedPropertyInspection.kt +++ b/src/main/kotlin/com/pestphp/pest/inspections/SuppressUndefinedPropertyInspection.kt @@ -8,7 +8,7 @@ import com.jetbrains.php.lang.psi.elements.FieldReference import com.pestphp.pest.isAnyPestFunction import com.pestphp.pest.isThisVariableInPest -class SuppressUndefinedPropertyInspection: InspectionSuppressor { +class SuppressUndefinedPropertyInspection : InspectionSuppressor { companion object { private val SUPPRESSED_PHP_INSPECTIONS = listOf(PhpUndefinedFieldInspection().id) } diff --git a/src/main/kotlin/com/pestphp/pest/parser/PestConfigurationFileParser.kt b/src/main/kotlin/com/pestphp/pest/parser/PestConfigurationFileParser.kt index 7349079b..94cd228b 100644 --- a/src/main/kotlin/com/pestphp/pest/parser/PestConfigurationFileParser.kt +++ b/src/main/kotlin/com/pestphp/pest/parser/PestConfigurationFileParser.kt @@ -10,21 +10,14 @@ import com.intellij.psi.PsiRecursiveElementWalkingVisitor import com.intellij.psi.util.CachedValue import com.intellij.psi.util.CachedValueProvider import com.intellij.psi.util.CachedValuesManager -import com.intellij.util.PathUtil import com.jetbrains.php.lang.psi.PhpFile -import com.jetbrains.php.lang.psi.elements.ConcatenationExpression import com.jetbrains.php.lang.psi.elements.MethodReference import com.jetbrains.php.lang.psi.elements.PhpPsiElement -import com.jetbrains.php.lang.psi.elements.StringLiteralExpression import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl import com.jetbrains.php.lang.psi.elements.impl.PhpFilePathUtils -import com.jetbrains.php.lang.psi.elements.impl.PhpFileReferenceSet import com.jetbrains.php.lang.psi.resolve.types.PhpType import com.pestphp.pest.PestSettings import com.pestphp.pest.getUsesPhpType -import kotlin.io.path.Path -import kotlin.io.path.name -import kotlin.io.path.pathString class PestConfigurationFileParser(private val settings: PestSettings) { fun parse(project: Project): PestConfigurationFile { @@ -56,7 +49,8 @@ class PestConfigurationFileParser(private val settings: PestSettings) { } ?: defaultConfig } - private class Visitor(private val collect: (PhpType, String?, Boolean) -> Unit) : PsiRecursiveElementWalkingVisitor() { + private class Visitor(private val collect: (PhpType, String?, Boolean) -> Unit) : + PsiRecursiveElementWalkingVisitor() { override fun visitElement(element: PsiElement) { if (element is MethodReference) { visitInReference(element) diff --git a/src/main/kotlin/com/pestphp/pest/snapshotTesting/SnapshotLineMarkerProvider.kt b/src/main/kotlin/com/pestphp/pest/snapshotTesting/SnapshotLineMarkerProvider.kt index 799e68b2..404b4a96 100644 --- a/src/main/kotlin/com/pestphp/pest/snapshotTesting/SnapshotLineMarkerProvider.kt +++ b/src/main/kotlin/com/pestphp/pest/snapshotTesting/SnapshotLineMarkerProvider.kt @@ -10,18 +10,18 @@ import com.jetbrains.php.lang.psi.elements.PhpUse import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl import com.pestphp.pest.PestIcons -class SnapshotLineMarkerProvider: RelatedItemLineMarkerProvider() { +class SnapshotLineMarkerProvider : RelatedItemLineMarkerProvider() { override fun collectNavigationMarkers( element: PsiElement, result: MutableCollection>, ) { - if(! PhpPsiUtil.isOfType(element, PhpTokenTypes.IDENTIFIER)) { + if (!PhpPsiUtil.isOfType(element, PhpTokenTypes.IDENTIFIER)) { return } val functionReference = element.parent as? FunctionReferenceImpl ?: return - if (! functionReference.isSnapshotAssertionCall) { + if (!functionReference.isSnapshotAssertionCall) { return } diff --git a/src/main/kotlin/com/pestphp/pest/snapshotTesting/SnapshotUtil.kt b/src/main/kotlin/com/pestphp/pest/snapshotTesting/SnapshotUtil.kt index 98cd6de6..950b1ad5 100644 --- a/src/main/kotlin/com/pestphp/pest/snapshotTesting/SnapshotUtil.kt +++ b/src/main/kotlin/com/pestphp/pest/snapshotTesting/SnapshotUtil.kt @@ -37,7 +37,7 @@ val FunctionReferenceImpl.snapshotFiles: List // Make sure we are inside a pest test val pestTestReference = pestBody.parent?.parent?.parent ?: return emptyList() - if (! pestTestReference.isPestTestReference()) { + if (!pestTestReference.isPestTestReference()) { return emptyList() } @@ -58,11 +58,12 @@ val FunctionReferenceImpl.snapshotFiles: List val psiFile = PsiManager.getInstance(this.project) .findFile(it) ?: return@iterateContentUnderDirectory true - if (! psiFile.isSnapshotFile( + if (!psiFile.isSnapshotFile( testName, testFileName, snapshotCalls - )) { + ) + ) { return@iterateContentUnderDirectory true } @@ -73,17 +74,17 @@ val FunctionReferenceImpl.snapshotFiles: List return snapshotFiles } -private fun PsiFile.isSnapshotFile(testName: String, testFileName: String, snapshotCall: Int): Boolean { +private fun PsiFile.isSnapshotFile(testName: String, testFileName: String, snapshotCall: Int): Boolean { val snapshotFileName = this.virtualFile.nameWithoutExtension this.virtualFile.extension ?: return false val testNameUnderscore = testName.replace(' ', '_') - if (! snapshotFileName.startsWith("${testFileName}__$testNameUnderscore")) { + if (!snapshotFileName.startsWith("${testFileName}__$testNameUnderscore")) { return false } - if (! snapshotFileName.endsWith("__$snapshotCall")) { + if (!snapshotFileName.endsWith("__$snapshotCall")) { return false } diff --git a/src/main/kotlin/com/pestphp/pest/surrounders/StatementSurroundDescriptor.kt b/src/main/kotlin/com/pestphp/pest/surrounders/StatementSurroundDescriptor.kt index 17a16ef9..eebd2ccc 100644 --- a/src/main/kotlin/com/pestphp/pest/surrounders/StatementSurroundDescriptor.kt +++ b/src/main/kotlin/com/pestphp/pest/surrounders/StatementSurroundDescriptor.kt @@ -5,12 +5,10 @@ import com.intellij.lang.surroundWith.Surrounder import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile -import com.jetbrains.php.lang.psi.elements.impl.FunctionImpl -import com.jetbrains.php.lang.psi.elements.impl.PhpExpressionImpl import com.jetbrains.php.surroundWith.PhpStatementSurroundDescriptor import com.pestphp.pest.getPestTests -class StatementSurroundDescriptor: SurroundDescriptor { +class StatementSurroundDescriptor : SurroundDescriptor { override fun getElementsToSurround(file: PsiFile, startOffset: Int, endOffset: Int): Array { val range = TextRange(startOffset, endOffset) diff --git a/src/main/kotlin/com/pestphp/pest/templates/PestItPostfixTemplate.kt b/src/main/kotlin/com/pestphp/pest/templates/PestItPostfixTemplate.kt index 57ea3e58..c640b5c5 100644 --- a/src/main/kotlin/com/pestphp/pest/templates/PestItPostfixTemplate.kt +++ b/src/main/kotlin/com/pestphp/pest/templates/PestItPostfixTemplate.kt @@ -10,7 +10,7 @@ import com.pestphp.pest.isPestTestFile /** * Adds a postfix template for `it` tests. */ -class PestItPostfixTemplate: PhpStringBasedPostfixTemplate( +class PestItPostfixTemplate : PhpStringBasedPostfixTemplate( "it", "it(${EXPR}, function...)", PhpPostfixUtils.selectorTopmost() diff --git a/src/main/kotlin/com/pestphp/pest/templates/PestPostfixTemplateProvider.kt b/src/main/kotlin/com/pestphp/pest/templates/PestPostfixTemplateProvider.kt index 7bfe6ece..d4765675 100644 --- a/src/main/kotlin/com/pestphp/pest/templates/PestPostfixTemplateProvider.kt +++ b/src/main/kotlin/com/pestphp/pest/templates/PestPostfixTemplateProvider.kt @@ -8,7 +8,7 @@ import com.intellij.psi.PsiFile /** * Register postfix templates */ -class PestPostfixTemplateProvider: PostfixTemplateProvider { +class PestPostfixTemplateProvider : PostfixTemplateProvider { override fun getTemplates(): MutableSet { return mutableSetOf(PestItPostfixTemplate()) } diff --git a/src/main/kotlin/com/pestphp/pest/templates/PestRootTemplateContextType.kt b/src/main/kotlin/com/pestphp/pest/templates/PestRootTemplateContextType.kt index 787979b4..cdfeae8e 100644 --- a/src/main/kotlin/com/pestphp/pest/templates/PestRootTemplateContextType.kt +++ b/src/main/kotlin/com/pestphp/pest/templates/PestRootTemplateContextType.kt @@ -13,7 +13,7 @@ import com.pestphp.pest.isPestTestFile * This Pest root template checks if the context is the root of a * pest test file. */ -class PestRootTemplateContextType: TemplateContextType("ROOT_PESTPHP", "Pest root") { +class PestRootTemplateContextType : TemplateContextType("ROOT_PESTPHP", "Pest root") { override fun isInContext(templateActionContext: TemplateActionContext): Boolean { if (!templateActionContext.file.isPestTestFile()) { return false diff --git a/src/main/kotlin/com/pestphp/pest/types/HigherOrderExtendTypeProvider.kt b/src/main/kotlin/com/pestphp/pest/types/HigherOrderExtendTypeProvider.kt index 2e1798b3..f4dfc691 100644 --- a/src/main/kotlin/com/pestphp/pest/types/HigherOrderExtendTypeProvider.kt +++ b/src/main/kotlin/com/pestphp/pest/types/HigherOrderExtendTypeProvider.kt @@ -3,11 +3,7 @@ package com.pestphp.pest.types import com.intellij.openapi.project.DumbService import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement -import com.jetbrains.php.lang.psi.elements.FieldReference -import com.jetbrains.php.lang.psi.elements.MemberReference -import com.jetbrains.php.lang.psi.elements.MethodReference -import com.jetbrains.php.lang.psi.elements.PhpNamedElement -import com.jetbrains.php.lang.psi.elements.PhpTypedElement +import com.jetbrains.php.lang.psi.elements.* import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl import com.jetbrains.php.lang.psi.resolve.types.PhpType import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider4 diff --git a/src/main/kotlin/com/pestphp/pest/types/ThisTypeProvider.kt b/src/main/kotlin/com/pestphp/pest/types/ThisTypeProvider.kt index e6f20eb6..8c7ced78 100644 --- a/src/main/kotlin/com/pestphp/pest/types/ThisTypeProvider.kt +++ b/src/main/kotlin/com/pestphp/pest/types/ThisTypeProvider.kt @@ -6,8 +6,6 @@ import com.intellij.openapi.project.guessProjectDir import com.intellij.openapi.vfs.VfsUtil import com.intellij.psi.PsiElement import com.intellij.psi.util.PsiTreeUtil -import com.intellij.util.PathUtil -import com.intellij.util.PathUtilRt import com.jetbrains.php.lang.psi.elements.PhpNamedElement import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl import com.jetbrains.php.lang.psi.resolve.types.PhpType @@ -17,7 +15,6 @@ import com.pestphp.pest.getUsesPhpType import com.pestphp.pest.isAnyPestFunction import com.pestphp.pest.isThisVariableInPest import kotlin.io.path.Path -import kotlin.io.path.name import kotlin.io.path.pathString /** diff --git a/src/main/resources/META-INF/pest-coverage.xml b/src/main/resources/META-INF/pest-coverage.xml index 3980b6a4..78eedc54 100644 --- a/src/main/resources/META-INF/pest-coverage.xml +++ b/src/main/resources/META-INF/pest-coverage.xml @@ -3,7 +3,7 @@ - - + + diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index bd8f22b0..9d6a9ad9 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -71,7 +71,8 @@ implementationClass="com.pestphp.pest.inspections.MultipleExpectChainableInspection" /> - + - + + diff --git a/src/main/resources/META-INF/pluginIcon.svg b/src/main/resources/META-INF/pluginIcon.svg index a625a8e4..1645434e 100644 --- a/src/main/resources/META-INF/pluginIcon.svg +++ b/src/main/resources/META-INF/pluginIcon.svg @@ -1,11 +1,13 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/main/resources/config@dark.svg b/src/main/resources/config@dark.svg index d9a9f30d..e2f095b8 100644 --- a/src/main/resources/config@dark.svg +++ b/src/main/resources/config@dark.svg @@ -1,15 +1,18 @@ - + - + - + diff --git a/src/main/resources/config@light.svg b/src/main/resources/config@light.svg index 294db79f..81b819a7 100644 --- a/src/main/resources/config@light.svg +++ b/src/main/resources/config@light.svg @@ -1,12 +1,15 @@ - + - + - + diff --git a/src/main/resources/dataset@dark.svg b/src/main/resources/dataset@dark.svg index 07196090..0f5a2d32 100644 --- a/src/main/resources/dataset@dark.svg +++ b/src/main/resources/dataset@dark.svg @@ -1,12 +1,14 @@ - + - + diff --git a/src/main/resources/dataset@light.svg b/src/main/resources/dataset@light.svg index 1b07e235..4dac9a75 100644 --- a/src/main/resources/dataset@light.svg +++ b/src/main/resources/dataset@light.svg @@ -1,9 +1,11 @@ - + - + diff --git a/src/main/resources/file@dark.svg b/src/main/resources/file@dark.svg index 4f6e23f2..86bfb1b7 100644 --- a/src/main/resources/file@dark.svg +++ b/src/main/resources/file@dark.svg @@ -1,12 +1,14 @@ - + - + diff --git a/src/main/resources/file@light.svg b/src/main/resources/file@light.svg index 9ac5e8da..70fde10a 100644 --- a/src/main/resources/file@light.svg +++ b/src/main/resources/file@light.svg @@ -1,9 +1,11 @@ - + - + diff --git a/src/main/resources/library/Pest/.phpstorm.meta.php b/src/main/resources/library/Pest/.phpstorm.meta.php index 68e109e9..06031258 100644 --- a/src/main/resources/library/Pest/.phpstorm.meta.php +++ b/src/main/resources/library/Pest/.phpstorm.meta.php @@ -3,6 +3,7 @@ /** * The PHPStorm meta file for Pest. */ + namespace PHPSTORM_META { override(\expect(0), type(0)); } \ No newline at end of file diff --git a/src/main/resources/liveTemplates/PestPHP.xml b/src/main/resources/liveTemplates/PestPHP.xml index e87cabb4..66b77d99 100644 --- a/src/main/resources/liveTemplates/PestPHP.xml +++ b/src/main/resources/liveTemplates/PestPHP.xml @@ -1,14 +1,16 @@ - - + + \ No newline at end of file diff --git a/src/main/resources/logo@dark.svg b/src/main/resources/logo@dark.svg index a625a8e4..1645434e 100644 --- a/src/main/resources/logo@dark.svg +++ b/src/main/resources/logo@dark.svg @@ -1,11 +1,13 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/main/resources/logo@light.svg b/src/main/resources/logo@light.svg index 932fbceb..657dc524 100644 --- a/src/main/resources/logo@light.svg +++ b/src/main/resources/logo@light.svg @@ -1,7 +1,9 @@ - + - + diff --git a/src/test/kotlin/com/pestphp/pest/datasets/DatasetCompletionTest.kt b/src/test/kotlin/com/pestphp/pest/datasets/DatasetCompletionTest.kt index e75454c0..d06d0ea8 100644 --- a/src/test/kotlin/com/pestphp/pest/datasets/DatasetCompletionTest.kt +++ b/src/test/kotlin/com/pestphp/pest/datasets/DatasetCompletionTest.kt @@ -10,15 +10,22 @@ class DatasetCompletionTest : PestLightCodeFixture() { } fun testCanCompleteDatasetInSameFile() { - myFixture.configureByFile("DatasetTest.php") + myFixture.configureByFile("AutocompleteDatasetTest.php") assertCompletion("dojos") } fun testCanCompleteDatasetInOtherFile() { myFixture.copyFileToProject("Datasets.php", "tests/Datasets/stances.php") - myFixture.configureByFile("DatasetTest.php") + myFixture.configureByFile("AutocompleteDatasetTest.php") assertCompletion("dojos", "stances") } -} \ No newline at end of file + + fun testCannotCompleteDatasetOnNonPestTest() { + myFixture.copyFileToProject("Datasets.php", "tests/Datasets/stances.php") + myFixture.configureByFile("DatasetOnNonPestTestCompletion.php") + + assertNoCompletion() + } +} diff --git a/src/test/kotlin/com/pestphp/pest/datasets/DatasetGoToTest.kt b/src/test/kotlin/com/pestphp/pest/datasets/DatasetGoToTest.kt index 04fc68a4..12914645 100644 --- a/src/test/kotlin/com/pestphp/pest/datasets/DatasetGoToTest.kt +++ b/src/test/kotlin/com/pestphp/pest/datasets/DatasetGoToTest.kt @@ -39,4 +39,17 @@ class DatasetGoToTest : PestLightCodeFixture() { assertTrue(declarationElement.isPestDataset()) assertEquals("stances", declarationElement!!.getPestDatasetName()) } -} \ No newline at end of file + + fun testCannotGoToDatasetInNonPestTest() { + myFixture.copyFileToProject("Datasets.php", "tests/Datasets/stances.php") + myFixture.configureByFile("DatasetOnNonPestTest.php") + + val declarationElement = GotoDeclarationAction.findTargetElement( + project, + myFixture.editor, + myFixture.caretOffset + ) + + assertNull(declarationElement) + } +} diff --git a/src/test/kotlin/com/pestphp/pest/datasets/InvalidDatasetReferenceInspectionTest.kt b/src/test/kotlin/com/pestphp/pest/datasets/InvalidDatasetReferenceInspectionTest.kt new file mode 100644 index 00000000..0879da9f --- /dev/null +++ b/src/test/kotlin/com/pestphp/pest/datasets/InvalidDatasetReferenceInspectionTest.kt @@ -0,0 +1,29 @@ +package com.pestphp.pest.datasets + +import com.intellij.testFramework.TestDataPath +import com.pestphp.pest.PestLightCodeFixture + +@TestDataPath("\$CONTENT_ROOT/resources/com/pestphp/pest/datasets") +class InvalidDatasetReferenceInspectionTest : PestLightCodeFixture() { + override fun getTestDataPath(): String { + return "src/test/resources/com/pestphp/pest/datasets" + } + + override fun setUp() { + super.setUp() + + myFixture.enableInspections(InvalidDatasetReferenceInspection::class.java) + } + + fun testHasInvalidDatasetName() { + myFixture.configureByFile("InvalidDatasetTest.php") + + myFixture.checkHighlighting() + } + + fun testHasValidDataset() { + myFixture.configureByFile("DatasetTest.php") + + myFixture.checkHighlighting() + } +} diff --git a/src/test/resources/com/pestphp/pest/datasets/AutocompleteDatasetTest.php b/src/test/resources/com/pestphp/pest/datasets/AutocompleteDatasetTest.php new file mode 100644 index 00000000..d87a7ebb --- /dev/null +++ b/src/test/resources/com/pestphp/pest/datasets/AutocompleteDatasetTest.php @@ -0,0 +1,12 @@ +with(''); \ No newline at end of file diff --git a/src/test/resources/com/pestphp/pest/datasets/DatasetOnNonPestTest.php b/src/test/resources/com/pestphp/pest/datasets/DatasetOnNonPestTest.php new file mode 100644 index 00000000..a381c6a8 --- /dev/null +++ b/src/test/resources/com/pestphp/pest/datasets/DatasetOnNonPestTest.php @@ -0,0 +1,5 @@ +with('stances'); diff --git a/src/test/resources/com/pestphp/pest/datasets/DatasetOnNonPestTestCompletion.php b/src/test/resources/com/pestphp/pest/datasets/DatasetOnNonPestTestCompletion.php new file mode 100644 index 00000000..a82fdf2b --- /dev/null +++ b/src/test/resources/com/pestphp/pest/datasets/DatasetOnNonPestTestCompletion.php @@ -0,0 +1,5 @@ +with(''); diff --git a/src/test/resources/com/pestphp/pest/datasets/DatasetTest.php b/src/test/resources/com/pestphp/pest/datasets/DatasetTest.php index d87a7ebb..63e344b3 100644 --- a/src/test/resources/com/pestphp/pest/datasets/DatasetTest.php +++ b/src/test/resources/com/pestphp/pest/datasets/DatasetTest.php @@ -9,4 +9,4 @@ it('can check if in the valley', function (string $dojo) { -})->with(''); \ No newline at end of file +})->with('dojos'); diff --git a/src/test/resources/com/pestphp/pest/datasets/Datasets.php b/src/test/resources/com/pestphp/pest/datasets/Datasets.php index 33097cce..875e1863 100644 --- a/src/test/resources/com/pestphp/pest/datasets/Datasets.php +++ b/src/test/resources/com/pestphp/pest/datasets/Datasets.php @@ -9,10 +9,3 @@ 'Han Zenkutsu Dachi', 'Kokutsu Dachi', ]); - - - - - - - diff --git a/src/test/resources/com/pestphp/pest/datasets/InvalidDatasetTest.php b/src/test/resources/com/pestphp/pest/datasets/InvalidDatasetTest.php new file mode 100644 index 00000000..202159be --- /dev/null +++ b/src/test/resources/com/pestphp/pest/datasets/InvalidDatasetTest.php @@ -0,0 +1,12 @@ +with('dodos'); diff --git a/src/test/resources/com/pestphp/pest/datasets/SharedDatasetReference.php b/src/test/resources/com/pestphp/pest/datasets/SharedDatasetReference.php index 2f3d427d..d43a4ae8 100644 --- a/src/test/resources/com/pestphp/pest/datasets/SharedDatasetReference.php +++ b/src/test/resources/com/pestphp/pest/datasets/SharedDatasetReference.php @@ -2,4 +2,4 @@ it('can check if in the valley', function (string $dojo) { -})->with('stances'); \ No newline at end of file +})->with('stances');