Skip to content

Commit

Permalink
Merge pull request #65 from pestphp/fix-namespace-test
Browse files Browse the repository at this point in the history
fix(runner): Fix finding tests in namespace
  • Loading branch information
olivernybroe authored Sep 6, 2020
2 parents d3fddcd + 59f7034 commit 9a8e9f9
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### Fixed
- Fixed duplicate test name error when no test name is given yet. ([#61](https://github.com/pestphp/pest-intellij/pull/61))
- Fixed finding tests with namespace at the top. ([#65](https://github.com/pestphp/pest-intellij/pull/65))

### Security
## [0.3.3]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = com.pestphp
pluginName = PEST PHP
pluginVersion = 0.4.0-alpha.3
pluginVersion = 0.4.0-alpha.4
pluginSinceBuild = 201
pluginUntilBuild = null

Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/com/pestphp/pest/PestUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.jetbrains.php.lang.psi.PhpFile
import com.jetbrains.php.lang.psi.elements.PhpNamespace
import com.jetbrains.php.lang.psi.elements.Statement
import com.jetbrains.php.phpunit.PhpUnitUtil
import com.jetbrains.php.testFramework.PhpTestFrameworkSettingsManager

fun PsiFile.isPestTestFile(): Boolean {
if (this !is PhpFile) return false

return this.firstChild.children
val element = this.firstChild

return element.children.filterIsInstance<PhpNamespace>()
.mapNotNull { it.statements }
.getOrElse(
0
) { element }
.children
.filterIsInstance<Statement>()
.mapNotNull { it.firstChild }
.any(PsiElement::isPestTestReference)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.pestphp.pest.PestUtil

import com.pestphp.pest.isPestTestFile
import com.pestphp.pest.isPestTestReference
import com.pestphp.pest.tests.PestLightCodeFixture

class IsPestTestFileTest : PestLightCodeFixture() {
Expand Down Expand Up @@ -44,4 +43,10 @@ class IsPestTestFileTest : PestLightCodeFixture() {

assertFalse(file.isPestTestFile())
}

fun testPestTestWithNamespaceIsPestTest() {
val file = myFixture.configureByFile("PestTestFunctionCallWithNamesapce.php")

assertTrue(file.isPestTestFile())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.pestphp.pest.inspections

import com.pestphp.pest.tests.PestLightCodeFixture


class DuplicateTestNameInspectionTest : PestLightCodeFixture() {
override fun getTestDataPath(): String? {
return "src/test/resources/com/pestphp/pest/inspections"
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/com/pestphp/pest/tests/types/BaseTypeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.pestphp.pest.tests.types

import com.pestphp.pest.tests.PestLightCodeFixture

abstract class BaseTypeTest: PestLightCodeFixture() {
abstract class BaseTypeTest : PestLightCodeFixture() {
override fun setUp() {
super.setUp()

Expand All @@ -12,4 +12,4 @@ abstract class BaseTypeTest: PestLightCodeFixture() {
override fun getTestDataPath(): String? {
return basePath + "types/fixtures"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pestphp.pest.tests.types

class FunctionTypeTest: BaseTypeTest() {
class FunctionTypeTest : BaseTypeTest() {
override fun setUp() {
super.setUp()

Expand All @@ -15,4 +15,4 @@ class FunctionTypeTest: BaseTypeTest() {
private fun assertFunctionCompletion() {
assertCompletion("expectException", "expectExceptionCode")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pestphp.pest.tests.types

class ThisFieldTypeTest: BaseTypeTest() {
class ThisFieldTypeTest : BaseTypeTest() {
override fun setUp() {
super.setUp()

Expand All @@ -18,4 +18,4 @@ class ThisFieldTypeTest: BaseTypeTest() {

assertCompletion("a", "b")
}
}
}
4 changes: 2 additions & 2 deletions src/test/kotlin/com/pestphp/pest/tests/types/ThisTypeTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pestphp.pest.tests.types

class ThisTypeTest: BaseTypeTest() {
class ThisTypeTest : BaseTypeTest() {
override fun setUp() {
super.setUp()

Expand Down Expand Up @@ -30,4 +30,4 @@ class ThisTypeTest: BaseTypeTest() {
private fun assertThisCompletion() {
assertCompletion("expectException", "expectExceptionCode")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Unit;

it('basic', function () {
$this->assertTrue(true);
});

0 comments on commit 9a8e9f9

Please sign in to comment.