From cb8ad9567a940db0434b9ca8991422ac9d2ce795 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Mon, 28 Apr 2025 17:53:19 +0800 Subject: region manager --- tests/RegionManagerTest.php | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/RegionManagerTest.php (limited to 'tests/RegionManagerTest.php') diff --git a/tests/RegionManagerTest.php b/tests/RegionManagerTest.php new file mode 100644 index 0000000..2536a7c --- /dev/null +++ b/tests/RegionManagerTest.php @@ -0,0 +1,52 @@ + '北京市'], + [], + [] + ); + $this->assertSame('北京市', $manager->getName(110000)); + } + + public function test_name_resolution_with_non_existent_code(): void + { + $this->expectException(RegionException::class); + $this->expectExceptionMessage('The region code does not exist.'); + $manager = new RegionManager([], [], []); + $manager->getName(110000); + } + + public function test_top_level_nodes_resolution(): void + { + $manager = new RegionManager([], [], [1, 2, 3]); + $this->assertSame([1, 2, 3], $manager->getTopLevelNodes()); + } + + public function test_nodes_resolution(): void + { + $manager = new RegionManager([], ['_1' => [2]], []); + $this->assertSame([2], $manager->getNodes(1)); + } + + public function test_nodes_resolution_with_non_existent_code(): void + { + $this->expectException(RegionException::class); + $this->expectExceptionMessage('Could not find any nodes under the region code.'); + $manager = new RegionManager([], [], []); + $manager->getNodes(1); + } +} -- cgit v1.2.3