/** * @dataProvider sourceDataProvider * * @param mixed $source * @param bool $foundInDatabase * @param array $expectedResult * @param string $exception */ public function testToMagentoData($source, $foundInDatabase, $expectedResult, $exception = null) { if ($exception) { $this->setExpectedException($exception); } if ($foundInDatabase === true) { $region = new Region(); $region->setRegionId(self::TEST_MAGENTO_REGION_ID); $this->repository->expects($this->once())->method('findOneBy')->will($this->returnValue($region)); } elseif ($foundInDatabase === false) { $this->repository->expects($this->once())->method('findOneBy')->will($this->returnValue(null)); } // more than one call should not provoke expectation errors $this->assertSame($expectedResult, $this->converter->toMagentoData($source)); $this->assertSame($expectedResult, $this->converter->toMagentoData($source)); }
/** * @param array $regionData * * @return null|Region */ protected function getRegion(array $regionData) { if (strpos($regionData['code'], $regionData['country_id'] . BAPRegion::SEPARATOR) === 0) { $combinedCode = $regionData['code']; } else { $combinedCode = BAPRegion::getRegionCombinedCode($regionData['country_id'], $regionData['code']); } /** @var $region Region */ $region = $this->regionRepository->findOneBy(array('combinedCode' => $combinedCode)); if (!$region) { $region = new Region($combinedCode); $region->setCode($regionData['code'])->setRegionId($regionData['region_id'])->setCombinedCode($combinedCode)->setCountryCode($regionData['country_id']); } $region->setName($regionData['default_name']); return $region; }