|
1 | 1 | import { datasetExpander } from '../../TestParser/DatasetExpander'; |
2 | | -import type { AstNode, CallNode, ExpressionStatementNode } from '../AstParser/AstNode'; |
| 2 | +import type { |
| 3 | + AstNode, |
| 4 | + CallNode, |
| 5 | + ClassConstantAccessNode, |
| 6 | + ExpressionStatementNode, |
| 7 | +} from '../AstParser/AstNode'; |
3 | 8 | import { evaluate } from '../Expressions/PhpExpression'; |
4 | 9 | import type { PHP } from '../PHP'; |
5 | 10 | import type { FileInfo, PestCallDescriptor, Resolver } from '../types'; |
6 | 11 | import { CallVisitor } from '../Visitors/CallVisitor'; |
| 12 | +import { FQNResolver } from './FQNResolver'; |
7 | 13 |
|
8 | 14 | const pestFunctionNames = new Set(['test', 'it', 'describe', 'arch']); |
9 | 15 |
|
@@ -34,14 +40,26 @@ export class PestResolver implements Resolver { |
34 | 40 | } |
35 | 41 | } |
36 | 42 |
|
37 | | -function extractDescription(args: AstNode[]): string | undefined { |
| 43 | +function extractDescription(args: AstNode[], php: PHP): string | undefined { |
38 | 44 | const firstArg = args[0]; |
39 | 45 | if (firstArg?.kind === 'string') { |
40 | 46 | return firstArg.value; |
41 | 47 | } |
42 | 48 | if (firstArg?.kind === 'argument' && firstArg.value?.kind === 'string') { |
43 | 49 | return firstArg.value.value; |
44 | 50 | } |
| 51 | + if (firstArg?.kind === 'class_constant_access') { |
| 52 | + const node = firstArg as ClassConstantAccessNode; |
| 53 | + if (node.name === 'class') { |
| 54 | + return php.getResolver(FQNResolver).resolveFQN(node.scope); |
| 55 | + } |
| 56 | + } |
| 57 | + if (firstArg?.kind === 'argument' && firstArg.value?.kind === 'class_constant_access') { |
| 58 | + const node = firstArg.value as ClassConstantAccessNode; |
| 59 | + if (node.name === 'class') { |
| 60 | + return php.getResolver(FQNResolver).resolveFQN(node.scope); |
| 61 | + } |
| 62 | + } |
45 | 63 | return undefined; |
46 | 64 | } |
47 | 65 |
|
@@ -101,7 +119,7 @@ function buildPestCallDescriptor(call: CallNode, php: PHP): PestCallDescriptor | |
101 | 119 |
|
102 | 120 | return { |
103 | 121 | fnName: rootCall.name, |
104 | | - description: extractDescription(rootCall.arguments), |
| 122 | + description: extractDescription(rootCall.arguments, php), |
105 | 123 | range: rootCall.loc, |
106 | 124 | datasets: resolveDatasets(withSources), |
107 | 125 | children: rootCall.name === 'describe' ? collectDescribeChildren(rootCall, php) : [], |
|
0 commit comments