phpantom_lsp 0.7.0

Fast PHP language server with deep type intelligence. Generics, Laravel, PHPStan annotations. Ready in an instant.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
//! Integration tests for the "Implement missing methods" code action.
//!
//! These tests exercise the full pipeline: parsing PHP source, resolving
//! the class hierarchy, detecting missing methods, and generating the
//! `WorkspaceEdit` with method stubs.

use crate::common::{create_psr4_workspace, create_test_backend};
use tower_lsp::lsp_types::*;

/// Helper: send a code action request at the given line/character and
/// return the list of code actions.
fn get_code_actions(
    backend: &phpantom_lsp::Backend,
    uri: &str,
    content: &str,
    line: u32,
    character: u32,
) -> Vec<CodeActionOrCommand> {
    let params = CodeActionParams {
        text_document: TextDocumentIdentifier {
            uri: uri.parse().unwrap(),
        },
        range: Range {
            start: Position::new(line, character),
            end: Position::new(line, character),
        },
        context: CodeActionContext {
            diagnostics: vec![],
            only: None,
            trigger_kind: None,
        },
        work_done_progress_params: WorkDoneProgressParams {
            work_done_token: None,
        },
        partial_result_params: PartialResultParams {
            partial_result_token: None,
        },
    };

    backend.handle_code_action(uri, content, &params)
}

/// Extract the "Implement" code action from a list of actions.
fn find_implement_action(actions: &[CodeActionOrCommand]) -> Option<&CodeAction> {
    actions.iter().find_map(|a| match a {
        CodeActionOrCommand::CodeAction(ca) if ca.title.starts_with("Implement ") => Some(ca),
        _ => None,
    })
}

/// Extract the inserted text from a code action's workspace edit.
fn extract_edit_text(action: &CodeAction) -> String {
    let edit = action.edit.as_ref().expect("action should have an edit");
    let changes = edit.changes.as_ref().expect("edit should have changes");
    let edits: Vec<&TextEdit> = changes.values().flat_map(|v| v.iter()).collect();
    edits
        .iter()
        .map(|e| e.new_text.as_str())
        .collect::<Vec<_>>()
        .join("")
}

// ─── Basic interface implementation ─────────────────────────────────────────

#[test]
fn implements_single_interface_method() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Renderable {
    public function render(): string;
}

class Page implements Renderable {
}
"#;

    backend.update_ast(uri, content);

    // Cursor inside the Page class body (line 6, the closing brace line).
    let actions = get_code_actions(&backend, uri, content, 6, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer implement action");

    let action = action.unwrap();
    assert_eq!(action.title, "Implement `render`");

    let text = extract_edit_text(action);
    assert!(
        text.contains("public function render(): string"),
        "Stub should have correct signature. Got:\n{}",
        text
    );
}

#[test]
fn triggers_on_class_declaration_line() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Renderable {
    public function render(): string;
}

class Page implements Renderable {
}
"#;

    backend.update_ast(uri, content);

    // Cursor on the `class Page implements Renderable {` line (line 5),
    // before the opening brace.
    let actions = get_code_actions(&backend, uri, content, 5, 6);
    let action = find_implement_action(&actions);
    assert!(
        action.is_some(),
        "Should offer implement action when cursor is on the class declaration line"
    );
    assert_eq!(action.unwrap().title, "Implement `render`");
}

#[test]
fn implements_multiple_interface_methods() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Serializable {
    public function serialize(): string;
    public function unserialize(string $data): void;
}

class MyClass implements Serializable {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 7, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer implement action");

    let action = action.unwrap();
    assert!(
        action.title.contains("2 missing methods"),
        "Title should mention count. Got: {}",
        action.title
    );

    let text = extract_edit_text(action);
    assert!(
        text.contains("public function serialize(): string"),
        "Should contain serialize stub. Got:\n{}",
        text
    );
    assert!(
        text.contains("public function unserialize(string $data): void"),
        "Should contain unserialize stub. Got:\n{}",
        text
    );
}

// ─── Abstract parent class ──────────────────────────────────────────────────

#[test]
fn implements_abstract_parent_methods() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
abstract class Shape {
    abstract public function area(): float;
    abstract protected function perimeter(): float;

    public function describe(): string {
        return "I am a shape";
    }
}

class Circle extends Shape {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 11, 0);
    let action = find_implement_action(&actions);
    assert!(
        action.is_some(),
        "Should offer implement action for abstract methods"
    );

    let action = action.unwrap();
    assert!(
        action.title.contains("2 missing methods"),
        "Title should mention 2 methods. Got: {}",
        action.title
    );

    let text = extract_edit_text(action);
    assert!(
        text.contains("public function area(): float"),
        "Should implement area(). Got:\n{}",
        text
    );
    assert!(
        text.contains("protected function perimeter(): float"),
        "Should keep protected visibility. Got:\n{}",
        text
    );
    // The concrete method describe() should NOT be in the stubs.
    assert!(
        !text.contains("describe"),
        "Should not stub concrete methods. Got:\n{}",
        text
    );
}

// ─── Already implemented methods are skipped ────────────────────────────────

#[test]
fn skips_already_implemented_methods() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Renderable {
    public function render(): string;
    public function toHtml(): string;
}

class Page implements Renderable {
    public function render(): string {
        return '<p>Page</p>';
    }
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 8, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer action for toHtml");

    let action = action.unwrap();
    assert_eq!(action.title, "Implement `toHtml`");

    let text = extract_edit_text(action);
    assert!(
        !text.contains("render"),
        "Should not re-implement render(). Got:\n{}",
        text
    );
    assert!(
        text.contains("public function toHtml(): string"),
        "Should implement toHtml(). Got:\n{}",
        text
    );
}

// ─── No action when all methods are implemented ─────────────────────────────

#[test]
fn no_action_when_fully_implemented() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Renderable {
    public function render(): string;
}

class Page implements Renderable {
    public function render(): string {
        return '<p>Page</p>';
    }
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 7, 0);
    let action = find_implement_action(&actions);
    assert!(
        action.is_none(),
        "Should not offer implement action when all methods are implemented"
    );
}

// ─── No action for abstract classes ─────────────────────────────────────────

#[test]
fn no_action_for_abstract_class() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Renderable {
    public function render(): string;
}

abstract class AbstractPage implements Renderable {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 6, 0);
    let action = find_implement_action(&actions);
    assert!(
        action.is_none(),
        "Should not offer implement action for abstract classes"
    );
}

// ─── No action for interfaces ───────────────────────────────────────────────

#[test]
fn no_action_for_interface() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Renderable {
    public function render(): string;
}

interface ExtendedRenderable extends Renderable {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 6, 0);
    let action = find_implement_action(&actions);
    assert!(
        action.is_none(),
        "Should not offer implement action for interfaces"
    );
}

// ─── No action for traits ───────────────────────────────────────────────────

#[test]
fn no_action_for_trait() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
trait MyTrait {
    abstract public function doWork(): void;
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 2, 0);
    let action = find_implement_action(&actions);
    assert!(
        action.is_none(),
        "Should not offer implement action for traits"
    );
}

// ─── Parameters with defaults and type hints ────────────────────────────────

#[test]
fn stub_includes_parameter_details() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Processor {
    public function process(string $name, array $options = [], bool $force = false): void;
}

class MyProcessor implements Processor {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 6, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer implement action");

    let text = extract_edit_text(action.unwrap());
    assert!(
        text.contains("string $name"),
        "Should include type hint. Got:\n{}",
        text
    );
    assert!(
        text.contains("array $options = []"),
        "Should include default value. Got:\n{}",
        text
    );
    assert!(
        text.contains("bool $force = false"),
        "Should include bool default. Got:\n{}",
        text
    );
}

// ─── Static methods ─────────────────────────────────────────────────────────

#[test]
fn stub_preserves_static_modifier() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Factory {
    public static function create(): static;
}

class UserFactory implements Factory {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 6, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer implement action");

    let text = extract_edit_text(action.unwrap());
    assert!(
        text.contains("public static function create(): static"),
        "Should preserve static modifier. Got:\n{}",
        text
    );
}

// ─── Multiple interfaces ────────────────────────────────────────────────────

#[test]
fn implements_methods_from_multiple_interfaces() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Renderable {
    public function render(): string;
}

interface Stringable {
    public function __toString(): string;
}

class Widget implements Renderable, Stringable {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 10, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer implement action");

    let action = action.unwrap();
    assert!(
        action.title.contains("2 missing methods"),
        "Title should mention 2. Got: {}",
        action.title
    );

    let text = extract_edit_text(action);
    assert!(text.contains("function render()"), "Got:\n{}", text);
    assert!(text.contains("function __toString()"), "Got:\n{}", text);
}

// ─── Interface extends interface ────────────────────────────────────────────

#[test]
fn implements_methods_from_parent_interface() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Base {
    public function baseMethod(): void;
}

interface Child extends Base {
    public function childMethod(): string;
}

class MyClass implements Child {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 10, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer implement action");

    let text = extract_edit_text(action.unwrap());
    assert!(
        text.contains("function childMethod()"),
        "Should implement childMethod. Got:\n{}",
        text
    );
    assert!(
        text.contains("function baseMethod()"),
        "Should implement inherited baseMethod. Got:\n{}",
        text
    );
}

// ─── Case-insensitive method matching ───────────────────────────────────────

#[test]
fn case_insensitive_method_check() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Logger {
    public function Log(string $message): void;
}

class FileLogger implements Logger {
    public function log(string $message): void {
        // PHP method names are case-insensitive
    }
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 7, 0);
    let action = find_implement_action(&actions);
    assert!(
        action.is_none(),
        "Should recognize log/Log as the same method (case-insensitive)"
    );
}

// ─── No action when cursor is outside class ─────────────────────────────────

#[test]
fn no_action_outside_class() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Renderable {
    public function render(): string;
}

class Page implements Renderable {
}

$x = 1;
"#;

    backend.update_ast(uri, content);

    // Cursor on the $x = 1 line, outside any class.
    let actions = get_code_actions(&backend, uri, content, 8, 0);
    let action = find_implement_action(&actions);
    assert!(
        action.is_none(),
        "Should not offer action when cursor is outside a class"
    );
}

// ─── Indentation detection ──────────────────────────────────────────────────

#[test]
fn respects_tab_indentation() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = "<?php\ninterface Renderable {\n\tpublic function render(): string;\n}\n\nclass Page implements Renderable {\n\tpublic $name = 'test';\n}\n";

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 6, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer implement action");

    let text = extract_edit_text(action.unwrap());
    // The stub should use tab indentation to match the class body.
    assert!(
        text.contains("\tpublic function render(): string"),
        "Should use tab indentation. Got:\n{}",
        text
    );
}

// ─── Cross-file with PSR-4 ──────────────────────────────────────────────────

#[test]
fn implements_interface_from_another_file() {
    let composer = r#"{
        "autoload": {
            "psr-4": {
                "App\\": "src/"
            }
        }
    }"#;

    let interface_file = "<?php\nnamespace App\\Contracts;\n\ninterface Renderable {\n    public function render(): string;\n    public function toHtml(): string;\n}\n";

    let class_file = "<?php\nnamespace App\\Views;\n\nuse App\\Contracts\\Renderable;\n\nclass Page implements Renderable {\n}\n";

    let (backend, dir) = create_psr4_workspace(
        composer,
        &[
            ("src/Contracts/Renderable.php", interface_file),
            ("src/Views/Page.php", class_file),
        ],
    );

    // Build URIs from the actual temp-directory paths.
    let iface_uri = Url::from_file_path(dir.path().join("src/Contracts/Renderable.php"))
        .unwrap()
        .to_string();
    let class_uri = Url::from_file_path(dir.path().join("src/Views/Page.php"))
        .unwrap()
        .to_string();

    // Load the interface file first so it's in the AST map.
    backend.update_ast(&iface_uri, interface_file);

    // Load the class file.
    backend.update_ast(&class_uri, class_file);

    let actions = get_code_actions(&backend, &class_uri, class_file, 6, 0);
    let action = find_implement_action(&actions);
    assert!(
        action.is_some(),
        "Should offer implement action for cross-file interface"
    );

    let action = action.unwrap();
    assert!(
        action.title.contains("2 missing methods"),
        "Title should mention 2 methods. Got: {}",
        action.title
    );

    let text = extract_edit_text(action);
    assert!(
        text.contains("function render()"),
        "Should contain render stub. Got:\n{}",
        text
    );
    assert!(
        text.contains("function toHtml()"),
        "Should contain toHtml stub. Got:\n{}",
        text
    );
}

// ─── Variadic and reference parameters ──────────────────────────────────────

#[test]
fn stub_handles_variadic_and_reference_params() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Collector {
    public function collect(string ...$items): array;
    public function fill(array &$target): void;
}

class MyCollector implements Collector {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 7, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer implement action");

    let text = extract_edit_text(action.unwrap());
    assert!(
        text.contains("string ...$items"),
        "Should preserve variadic. Got:\n{}",
        text
    );
    assert!(
        text.contains("array &$target"),
        "Should preserve reference. Got:\n{}",
        text
    );
}

// ─── Nullable return types ──────────────────────────────────────────────────

#[test]
fn stub_preserves_nullable_return_type() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Repository {
    public function find(int $id): ?string;
}

class UserRepository implements Repository {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 6, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some());

    let text = extract_edit_text(action.unwrap());
    assert!(
        text.contains("?string"),
        "Should preserve nullable return type. Got:\n{}",
        text
    );
}

// ─── Union return types ─────────────────────────────────────────────────────

#[test]
fn stub_preserves_union_return_type() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Parser {
    public function parse(string $input): int|false;
}

class MyParser implements Parser {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 6, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some());

    let text = extract_edit_text(action.unwrap());
    assert!(
        text.contains("int|false"),
        "Should preserve union return type. Got:\n{}",
        text
    );
}

// ─── No return type ─────────────────────────────────────────────────────────

#[test]
fn stub_without_return_type() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Handler {
    public function handle();
}

class MyHandler implements Handler {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 6, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some());

    let text = extract_edit_text(action.unwrap());
    // No `: type` after the parentheses.
    assert!(
        text.contains("public function handle()\n"),
        "Should have no return type. Got:\n{}",
        text
    );
}

// ─── Mixed abstract + interface ─────────────────────────────────────────────

#[test]
fn implements_both_abstract_and_interface_methods() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface Renderable {
    public function render(): string;
}

abstract class Component implements Renderable {
    abstract protected function setup(): void;
}

class Button extends Component {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 10, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer action");

    let text = extract_edit_text(action.unwrap());
    assert!(
        text.contains("function render()"),
        "Should implement interface method. Got:\n{}",
        text
    );
    assert!(
        text.contains("protected function setup(): void"),
        "Should implement abstract method. Got:\n{}",
        text
    );
}

// ─── Deep inheritance chain ─────────────────────────────────────────────────

#[test]
fn implements_methods_from_deep_chain() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
abstract class GrandParent {
    abstract public function grandParentMethod(): void;
}

abstract class ParentClass extends GrandParent {
    abstract public function parentMethod(): string;
}

class Child extends ParentClass {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 10, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer action for deep chain");

    let text = extract_edit_text(action.unwrap());
    assert!(
        text.contains("function parentMethod()"),
        "Should implement parentMethod. Got:\n{}",
        text
    );
    assert!(
        text.contains("function grandParentMethod()"),
        "Should implement grandParentMethod. Got:\n{}",
        text
    );
}

// ─── Already partially implemented from parent ──────────────────────────────

#[test]
fn skips_methods_implemented_by_parent() {
    let backend = create_test_backend();
    let uri = "file:///test.php";
    let content = r#"<?php
interface FullService {
    public function methodA(): void;
    public function methodB(): string;
}

abstract class BaseService implements FullService {
    public function methodA(): void {
        // implemented
    }
}

class ConcreteService extends BaseService {
}
"#;

    backend.update_ast(uri, content);

    let actions = get_code_actions(&backend, uri, content, 13, 0);
    let action = find_implement_action(&actions);
    assert!(action.is_some(), "Should offer action for methodB only");

    let action = action.unwrap();
    assert_eq!(
        action.title, "Implement `methodB`",
        "Should only need to implement methodB"
    );

    let text = extract_edit_text(action);
    assert!(
        !text.contains("methodA"),
        "Should not re-implement methodA. Got:\n{}",
        text
    );
    assert!(
        text.contains("function methodB()"),
        "Should implement methodB. Got:\n{}",
        text
    );
}