[ 'country_code' => 'BR', 'locale' => 'pt', 'subdivisions' => [ 'SC' => [ 'name' => 'Santa Catarina', 'iso_code' => 'BR-SC', 'postal_code_pattern' => '8[89]', 'postal_code_pattern_type' => 'full', 'has_children' => true, ], 'SP' => [ 'name' => 'São Paulo', 'iso_code' => 'BR-SP', 'postal_code_pattern' => '[01][1-9]', 'has_children' => true, ], ], ], 'BR-249a39f10ac434b1fcd4d51516266b8e' => [ 'country_code' => 'BR', 'parents' => ['BR', 'SC'], 'locale' => 'pt', 'subdivisions' => [ 'Abelardo Luz' => [], ], ], 'BR-8ef7a36db3f5d47d46566f851be5f610' => [ 'country_code' => 'BR', 'parents' => ['BR', 'SP'], 'locale' => 'pt', 'subdivisions' => [ 'Anhumas' => [], ] ], ]; /** * @covers ::__construct */ public function testConstructor() { $root = vfsStream::setup('resources'); $directory = vfsStream::newDirectory('subdivision')->at($root); foreach ($this->subdivisions as $parent => $data) { $filename = $parent . '.json'; vfsStream::newFile($filename)->at($directory)->setContent(json_encode($data)); } // Instantiate the subdivision repository and confirm that the // definition path was properly set. $subdivisionRepository = new SubdivisionRepository(null, 'vfs://resources/subdivision/'); $reflected_constraint = (new \ReflectionObject($subdivisionRepository))->getProperty('definitionPath'); $reflected_constraint->setAccessible(TRUE); $definitionPath = $reflected_constraint->getValue($subdivisionRepository); $this->assertEquals('vfs://resources/subdivision/', $definitionPath); return $subdivisionRepository; } /** * @covers ::get * @covers ::hasData * @covers ::loadDefinitions * @covers ::processDefinitions * @covers ::buildGroup * @covers ::createSubdivisionFromDefinitions * * @depends testConstructor */ public function testGet($subdivisionRepository) { $subdivision = $subdivisionRepository->get('SC', ['BR']); $subdivisionChild = $subdivisionRepository->get('Abelardo Luz', ['BR', 'SC']); $this->assertInstanceOf(Subdivision::class, $subdivision); $this->assertEquals(null, $subdivision->getParent()); $this->assertEquals('BR', $subdivision->getCountryCode()); $this->assertEquals('pt', $subdivision->getLocale()); $this->assertEquals('SC', $subdivision->getCode()); $this->assertEquals('Santa Catarina', $subdivision->getName()); $this->assertEquals('BR-SC', $subdivision->getIsoCode()); $this->assertEquals('8[89]', $subdivision->getPostalCodePattern()); $this->assertEquals('full', $subdivision->getPostalCodePatternType()); $children = $subdivision->getChildren(); $this->assertEquals($subdivisionChild, $children['Abelardo Luz']); $this->assertInstanceOf(Subdivision::class, $subdivisionChild); $this->assertEquals('Abelardo Luz', $subdivisionChild->getCode()); // $subdivision contains the loaded children while $parent doesn't, // so they can't be compared directly. $parent = $subdivisionChild->getParent(); $this->assertInstanceOf(Subdivision::class, $parent); $this->assertEquals($subdivision->getCode(), $parent->getCode()); } /** * @covers ::get * @covers ::hasData * @covers ::loadDefinitions * @covers ::processDefinitions * @covers ::buildGroup * @covers ::createSubdivisionFromDefinitions * * @depends testConstructor */ public function testGetInvalidSubdivision($subdivisionRepository) { $subdivision = $subdivisionRepository->get('FAKE', ['BR']); $this->assertNull($subdivision); } /** * @covers ::getAll * @covers ::hasData * @covers ::loadDefinitions * @covers ::processDefinitions * @covers ::buildGroup * @covers ::createSubdivisionFromDefinitions * * @depends testConstructor */ public function testGetAll($subdivisionRepository) { $subdivisions = $subdivisionRepository->getAll(['RS']); $this->assertEquals([], $subdivisions); $subdivisions = $subdivisionRepository->getAll(['BR']); $this->assertCount(2, $subdivisions); $this->assertArrayHasKey('SC', $subdivisions); $this->assertArrayHasKey('SP', $subdivisions); $this->assertEquals('SC', $subdivisions['SC']->getCode()); $this->assertEquals('SP', $subdivisions['SP']->getCode()); $subdivisions = $subdivisionRepository->getAll(['BR', 'SC']); $this->assertCount(1, $subdivisions); $this->assertArrayHasKey('Abelardo Luz', $subdivisions); $this->assertEquals('Abelardo Luz', $subdivisions['Abelardo Luz']->getCode()); } /** * @covers ::getList * @covers ::hasData * @covers ::loadDefinitions * @covers ::processDefinitions * @covers ::buildGroup * * @depends testConstructor */ public function testGetList($subdivisionRepository) { $list = $subdivisionRepository->getList(['RS']); $this->assertEquals([], $list); $list = $subdivisionRepository->getList(['BR']); $expectedList = ['SC' => 'Santa Catarina', 'SP' => 'São Paulo']; $this->assertEquals($expectedList, $list); $list = $subdivisionRepository->getList(['BR', 'SC']); $expectedList = ['Abelardo Luz' => 'Abelardo Luz']; $this->assertEquals($expectedList, $list); } } __halt_compiler();----SIGNATURE:----Sa28scr+2P6SVMq/cbVibHPoFsDWaBrSgNuuyhCAIhT7LjG9Lp8mXYlYnxm+/5fBJidGEA1V3d68ryywByhyY1c0BPtotreR6ijDiU8J9CaclhpAJlPJt1vIKUvMCcH9p8oKhVpcSqV6cf9cc52eEHqIfkwamJQI5M5AK/FArafIqOQdnJwGUH5I7GjTwPNhp/rUTsfptkBXJlHdrruBlIT+jfBJOtj8GdXKtVD/pd06xeVzr3nyDnfBQzpgYKv5NHAHX55jtLBXdfy/0oc3081QcFZVgnQGNHW8GTZdYtAr13OMDTnNNWmJ87k36YvizPShFGhD5i3NOVKwBBGtzvML6tP7dGG2dEgubUoEw6r2E/xRZUahg5BwDqrVPhi+sQ/AYa+lmjDSamssu+3+yLZBYU4R4FRbDOQrPZsMtkw1AzCjDVhMYSAkffHeifzp9nKFMkI0mJ6zP4dgAw2H/7i3UgN9RXSAr3aO6OLw9ATb2kRJb+tqypl0FPpnFDfQ4A4SsZPU9DVdlxGCuoqlC7YCto8Ao6X7Y2D+IsT9ru26sSG91jl3S+gMMIVz+QAzelo6lZUw/g4X9RcJs5bJFX0yRsHiArd4bEZIUheDtJj2lkgLhHkLMtOY1NsVk+3bPAP6GryPvABbZFCQOP0eZEZNBGKHd0CnX2eh/6/MVCQ=----ATTACHMENT:----OTk1MDI2OTE2MzEzMDY3NCAzNTU5ODE4MTUyMzYyNTIyIDk3MDUwNzU5NjgxMDM3MzU=