1 #! /usr/bin/env python3
6 from common_tests
import CommonTestDriver
7 from test_case
import TestCase
10 class HierarchyTests(TestCase
[CommonTestDriver
]):
12 def get_template_repo(cls
) -> str:
13 return "hphp/hack/test/integration/data/hierarchy"
15 def test_inheritance(self
) -> None:
17 Test --inheritance-ancestors and --inheritance-children
19 self
.test_driver
.start_hh_server()
20 self
.test_driver
.check_cmd(
22 'File "{root}foo.php", line 3, characters 7-9: Foo',
23 ' inherited by File "{root}bar.php", line 3, characters 7-9: Bar',
24 'File "{root}foo.php", line 4, characters 19-19: Foo::f',
25 ' inherited by File "{root}bar.php", line 4, characters 19-19: Bar::f',
26 'File "{root}foo.php", line 3, characters 7-9: Foo',
27 ' inherited by File "{root}baz.php", line 3, characters 7-9: Baz',
28 'File "{root}foo.php", line 5, characters 19-19: Foo::g',
29 ' inherited by File "{root}baz.php", line 4, characters 19-19: Baz::g',
31 options
=["--inheritance-children", "Foo"],
33 self
.test_driver
.check_cmd(
35 'File "{root}baz.php", line 3, characters 7-9: Baz',
36 ' inherited from File "{root}foo.php", line 3, characters 7-9: Foo',
37 'File "{root}baz.php", line 4, characters 19-19: Baz::g',
38 ' inherited from File "{root}foo.php", line 5, characters 19-19: Foo::g',
39 'File "{root}baz.php", line 3, characters 7-9: Baz',
40 ' inherited from File "{root}bar.php", line 3, characters 7-9: Bar',
42 options
=["--inheritance-ancestors", "Baz"],
45 def test_inheritance_filter(self
) -> None:
46 self
.test_driver
.start_hh_server()
47 self
.test_driver
.check_cmd(
49 'File "{root}filter.php", line 15, characters 7-12: Filter',
50 ' inherited from File "{root}filter.php", line 3, characters 7-13: CFilter',
51 'File "{root}filter.php", line 18, characters 19-31: Filter::cfilterMethod',
52 ' inherited from File "{root}filter.php", line 4, characters 19-31: CFilter::cfilterMethod',
54 options
=["--inheritance-ancestor-classes", "Filter"],
56 self
.test_driver
.check_cmd(
58 'File "{root}filter.php", line 15, characters 7-12: Filter',
59 ' inherited from File "{root}filter.php", line 7, characters 11-17: IFilter',
60 'File "{root}filter.php", line 19, characters 19-31: Filter::ifilterMethod',
61 ' inherited from File "{root}filter.php", line 8, characters 19-31: IFilter::ifilterMethod',
63 options
=["--inheritance-ancestor-interfaces", "Filter"],
65 self
.test_driver
.check_cmd(
67 'File "{root}filter.php", line 15, characters 7-12: Filter',
68 ' inherited from File "{root}filter.php", line 11, characters 7-13: TFilter',
69 'File "{root}filter.php", line 20, characters 19-31: Filter::tfilterMethod',
70 ' inherited from File "{root}filter.php", line 12, characters 19-31: TFilter::tfilterMethod',
72 options
=["--inheritance-ancestor-traits", "Filter"],
75 def test_method_signature_change(self
) -> None:
76 with
open(os
.path
.join(self
.test_driver
.repo_dir
, "qux.php"), "w") as f
:
87 self
.test_driver
.start_hh_server(changed_files
=["qux.php"])
88 self
.test_driver
.check_cmd(["No errors!"])
89 debug_sub
= self
.test_driver
.subscribe_debug()
90 with
open(os
.path
.join(self
.test_driver
.repo_dir
, "foo.php"), "w") as f
:
94 public function f(): void {}
95 public final function g() {}
99 msgs
= debug_sub
.get_incremental_logs()
100 self
.assertEqual(set(msgs
["to_redecl_phase1"]["files"]), set(["foo.php"]))
101 # FIXME: redeclaring qux.php is unnecessary
103 set(msgs
["to_redecl_phase2"]["files"]),
104 set(["foo.php", "bar.php", "baz.php", "qux.php"]),
107 set(msgs
["to_recheck"]["files"]),
108 set(["foo.php", "bar.php", "baz.php", "qux.php"]),