/** * Set country filter * * @param string|\Magento\Directory\Model\Country $country * @return \Magento\Directory\Model\ResourceModel\Country\Format\Collection */ public function setCountryFilter($country) { if ($country instanceof \Magento\Directory\Model\Country) { $countryId = $country->getId(); } else { $countryId = $country; } return $this->addFieldToFilter('country_id', $countryId); }
public function getCountry() { if (is_null($this->country)) { $this->country = $this->countryFactory->create(); try { $this->country->loadByCode($this->getData('country_code')); } catch (\Exception $e) { } } return $this->country; }
protected function setUp() { $this->helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->scope = $this->getMockBuilder('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface')->disableOriginalConstructor()->getMock(); $this->scope->expects($this->any())->method('getValue')->will($this->returnCallback([$this, 'scopeConfiggetValue'])); $this->error = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote\\Address\\RateResult\\Error')->setMethods(['setCarrier', 'setCarrierTitle', 'setErrorMessage'])->getMock(); $this->errorFactory = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Address\\RateResult\\ErrorFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->errorFactory->expects($this->any())->method('create')->willReturn($this->error); $this->rate = $this->getMock('Magento\\Shipping\\Model\\Rate\\Result', ['getError'], [], '', false); $rateFactory = $this->getMock('Magento\\Shipping\\Model\\Rate\\ResultFactory', ['create'], [], '', false); $rateFactory->expects($this->any())->method('create')->willReturn($this->rate); $this->country = $this->getMockBuilder('\\Magento\\Directory\\Model\\Country')->disableOriginalConstructor()->setMethods(['load'])->getMock(); $this->abstractModel = $this->getMockBuilder('Magento\\Framework\\Model\\AbstractModel')->disableOriginalConstructor()->setMethods(['getData'])->getMock(); $this->country->expects($this->any())->method('load')->willReturn($this->abstractModel); $this->countryFactory = $this->getMockBuilder('\\Magento\\Directory\\Model\\CountryFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->countryFactory->expects($this->any())->method('create')->willReturn($this->country); $this->model = $this->helper->getObject('Magento\\Ups\\Model\\Carrier', ['scopeConfig' => $this->scope, 'rateErrorFactory' => $this->errorFactory, 'countryFactory' => $this->countryFactory, 'rateFactory' => $rateFactory]); }