/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage WrongClassName doesn't implement \Tobai\GeoStoreSwitcher\Model\Store\Switcher\RuleInterface */ public function testCreateWrongClass() { $className = 'WrongClassName'; $rule = $this->getMockBuilder('WrongClassName')->disableOriginalConstructor()->getMock(); $this->objectManager->expects($this->once())->method('create')->with($className)->willReturn($rule); $this->ruleFactory->create($className); }
/** * @param string $countryCode * @return int|bool */ public function getStoreId($countryCode) { foreach ($this->rules as $ruleClass) { $rule = $this->ruleFactory->create($ruleClass); $storeId = $rule->getStoreId($countryCode); if ($storeId) { return $storeId; } } return false; }
public function testGetStoreIdNoRuleSuccess() { $countryCode = 'UA'; $storeRule1 = false; $storeRule2 = false; $rule1 = $this->getMock('Tobai\\GeoStoreSwitcher\\Model\\GeoStore\\Switcher\\RuleInterface'); $rule1->expects($this->once())->method('getStoreId')->with($countryCode)->willReturn($storeRule1); $rule2 = $this->getMock('Tobai\\GeoStoreSwitcher\\Model\\GeoStore\\Switcher\\RuleInterface'); $rule2->expects($this->once())->method('getStoreId')->with($countryCode)->willReturn($storeRule2); $this->ruleFactory->expects($this->exactly(2))->method('create')->willReturnMap([['Rule Class 1', [], $rule1], ['Rule Class 2', [], $rule2]]); $this->assertFalse($this->rulePool->getStoreId($countryCode)); }