| 8 | |
| 9 | |
| 10 | class Test_PhpParser(unittest.TestCase): |
| 11 | def setUp(self) -> None: |
| 12 | with open('tests/test_parser/test_sample/php_test_sample.php', 'r') as file: |
| 13 | self.code_sample = file.read() |
| 14 | |
| 15 | tree = parse_code(self.code_sample, 'php') |
| 16 | self.root_node = tree.root_node |
| 17 | |
| 18 | return super().setUp() |
| 19 | |
| 20 | def test_get_function_list(self): |
| 21 | root = self.root_node |
| 22 | |
| 23 | function_list = PhpParser.get_function_list(root) |
| 24 | |
| 25 | self.assertEqual(len(function_list), 5) |
| 26 | |
| 27 | def test_get_class_list(self): |
| 28 | root = self.root_node |
| 29 | |
| 30 | class_list = PhpParser.get_class_list(root) |
| 31 | |
| 32 | self.assertEqual(len(class_list), 3) |
| 33 | |
| 34 | def test_get_docstring(self): |
| 35 | code_sample = """ |
| 36 | <?php |
| 37 | /** |
| 38 | * Get all image nodes. |
| 39 | * |
| 40 | * @param \DOMNode $node The \DOMDocument instance |
| 41 | * @param boolean $strict If the document has to be valid |
| 42 | * |
| 43 | * @return \DOMNode |
| 44 | */ |
| 45 | function getImageNodes(\DOMNode $node, $strict = true): \DOMNode |
| 46 | { |
| 47 | // ... |
| 48 | return $node; |
| 49 | } |
| 50 | ?> |
| 51 | """ |
| 52 | |
| 53 | tree = parse_code(code_sample, 'php') |
| 54 | root = tree.root_node |
| 55 | |
| 56 | fn = PhpParser.get_function_list(root)[0] |
| 57 | |
| 58 | docs = PhpParser.get_docstring(fn) |
| 59 | |
| 60 | self.assertEqual(docs, '/**\n * Get all image nodes.\n *\n * @param \\DOMNode $node The \\DOMDocument instance\n * @param boolean $strict If the document has to be valid\n *\n * @return \\DOMNode\n */') |
| 61 | |
| 62 | |
| 63 | def test_get_function_metadata(self): |
| 64 | root = self.root_node |
| 65 | |
| 66 | function = list(PhpParser.get_function_list(root))[1] |
| 67 | metadata = PhpParser.get_function_metadata(function) |
nothing calls this directly
no outgoing calls
no test coverage detected