Skip to content

Commit f555bc0

Browse files
committed
add stubs tests (VKCOM#69)
* add stub tests * add todo * update kphp-template test * use `KphpStormTestBase` as a base class for `StubTestBase` * Add missing tests * backport new approach to walt a stub tree
1 parent e405c0a commit f555bc0

File tree

13 files changed

+206
-0
lines changed

13 files changed

+206
-0
lines changed

src/main/kotlin/com/vk/kphpstorm/kphptags/psi/KphpDocTagStubImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import com.jetbrains.php.lang.psi.resolve.types.PhpType
1111
* When @kphp-... tags (regardless of elementType) are stored as stubs,
1212
* they hold only name and optional arbitrary string value.
1313
* Similar to [com.jetbrains.php.lang.documentation.phpdoc.psi.stubs.PhpDocTagStubImpl]
14+
*
15+
* TODO: make a research to check are we really need stubs?
1416
*/
1517
class KphpDocTagStubImpl(
1618
parent: StubElement<*>?,
@@ -22,4 +24,6 @@ class KphpDocTagStubImpl(
2224
override fun getType() = PhpType()
2325
override fun getName() = name
2426
override fun getValue() = value
27+
28+
override fun toString(): String = "$name${if (value != null) ": $value" else ""}"
2529
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
/**
4+
* @kphp-json rename_policy=camelCase
5+
*/
6+
class C {
7+
/**
8+
* @kphp-json float_precision=1
9+
* @kphp-json required
10+
*/
11+
public float $field;
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
PhpFileStubImpl
2+
DOC_COMMENT:PhpDocCommentStubImpl
3+
@kphp-json {name: @kphp-json}:@kphp-json
4+
CLASS:PhpClassStubImpl{C}
5+
DOC_COMMENT:PhpDocCommentStubImpl
6+
@kphp-json {name: @kphp-json}:@kphp-json
7+
@kphp-json {name: @kphp-json}:@kphp-json
8+
CLASS_FIELDS:PhpClassFieldListStubImpl
9+
CLASS_FIELD:PhpFieldStubImpl
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* @kphp-serializable
5+
* @kphp-reserved-fields [2]
6+
*/
7+
class C {
8+
/**
9+
* @kphp-serialized-float32 arg
10+
*/
11+
public float $field0;
12+
13+
/**
14+
* @kphp-serialized-field 1
15+
*/
16+
public float $field1;
17+
18+
/**
19+
* @kphp-serialized-field 3
20+
*/
21+
public int $field3;
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
PhpFileStubImpl
2+
DOC_COMMENT:PhpDocCommentStubImpl
3+
@kphp-... {name: @kphp-serializable}:@kphp-serializable
4+
@kphp-... {name: @kphp-reserved-fields}:@kphp-reserved-fields
5+
CLASS:PhpClassStubImpl{C}
6+
DOC_COMMENT:PhpDocCommentStubImpl
7+
@kphp-... {name: @kphp-serialized-float32}:@kphp-serialized-float32
8+
CLASS_FIELDS:PhpClassFieldListStubImpl
9+
CLASS_FIELD:PhpFieldStubImpl
10+
DOC_COMMENT:PhpDocCommentStubImpl
11+
@kphp-... {name: @kphp-serialized-field}:@kphp-serialized-field
12+
CLASS_FIELDS:PhpClassFieldListStubImpl
13+
CLASS_FIELD:PhpFieldStubImpl
14+
DOC_COMMENT:PhpDocCommentStubImpl
15+
@kphp-... {name: @kphp-serialized-field}:@kphp-serialized-field
16+
CLASS_FIELDS:PhpClassFieldListStubImpl
17+
CLASS_FIELD:PhpFieldStubImpl
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* @kphp-throws \Exception
4+
* @kphp-color red
5+
* @kphp-required
6+
* @kphp-inline
7+
* @kphp-profile
8+
*/
9+
function test($arg1, $arg2) { }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
PhpFileStubImpl
2+
DOC_COMMENT:PhpDocCommentStubImpl
3+
@kphp-... {name: @kphp-throws}:@kphp-throws
4+
@kphp-... {name: @kphp-color}:@kphp-color
5+
@kphp-... {name: @kphp-required}:@kphp-required
6+
@kphp-... {name: @kphp-inline}:@kphp-inline
7+
@kphp-... {name: @kphp-profile}:@kphp-profile
8+
FUNCTION:PhpFunctionStubImpl
9+
NOT_PROMOTED_PARAMETER:PhpParameterStubImpl
10+
NOT_PROMOTED_PARAMETER:PhpParameterStubImpl
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
/**
3+
* @kphp-template-class int,string
4+
*/
5+
class C { }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PhpFileStubImpl
2+
DOC_COMMENT:PhpDocCommentStubImpl
3+
@kphp-template-class {name: @kphp-template-class, value: int,string}:@kphp-template-class: int,string
4+
CLASS:PhpClassStubImpl{C}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
/** @kphp-warn-performance all */
4+
function test() { }

0 commit comments

Comments
 (0)