/** * @covers Thelia\Coupon\CouponFactory::buildCouponFromModel */ public function testBuildCouponFromModel() { $stubFacade = $this->generateFacadeStub(); $stubContainer = $this->getMock('\\Symfony\\Component\\DependencyInjection\\Container'); $conditionFactory = new ConditionFactory($stubContainer); $couponModel = $this->generateCouponModel($stubFacade, $conditionFactory); $stubFacade->expects($this->any())->method('findOneCouponByCode')->will($this->returnValue($couponModel)); $couponManager = new RemoveXAmount($stubFacade); $condition1 = new MatchForTotalAmount($stubFacade); $operators = array(MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR, MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL); $values = array(MatchForTotalAmount::CART_TOTAL => 40.0, MatchForTotalAmount::CART_CURRENCY => 'EUR'); $condition1->setValidatorsFromForm($operators, $values); $condition2 = new MatchForTotalAmount($stubFacade); $operators = array(MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR, MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL); $values = array(MatchForTotalAmount::CART_TOTAL => 400.0, MatchForTotalAmount::CART_CURRENCY => 'EUR'); $condition2->setValidatorsFromForm($operators, $values); $conditions = new ConditionCollection(); $conditions[] = $condition1; $conditions[] = $condition2; $stubConditionFactory = $this->getMockBuilder('\\Thelia\\Condition\\ConditionFactory')->disableOriginalConstructor()->getMock(); $stubConditionFactory->expects($this->any())->method('unserializeConditionCollection')->will($this->returnValue($conditions)); $stubContainer->expects($this->any())->method('get')->will($this->onConsecutiveCalls($stubFacade, $couponManager, $stubConditionFactory)); $stubContainer->expects($this->any())->method('has')->will($this->returnValue(true)); $factory = new CouponFactory($stubContainer); $expected = $couponManager; $actual = $factory->buildCouponFromModel($couponModel); $this->assertEquals($expected, $actual); }
/** * @covers Thelia\Coupon\CouponManager::addAvailableCoupon * @covers Thelia\Coupon\CouponManager::getAvailableCoupons */ public function testGetAvailableCoupons() { $stubFacade = $this->generateFacadeStub(); $stubContainer = $this->getMock('\\Symfony\\Component\\DependencyInjection\\Container'); $conditionFactory = new ConditionFactory($stubContainer); $stubFacade->expects($this->any())->method('getCurrentCoupons')->will($this->returnValue(array())); $conditions = new ConditionCollection(); $stubConditionFactory = $this->getMockBuilder('\\Thelia\\Condition\\ConditionFactory')->disableOriginalConstructor()->getMock(); $stubConditionFactory->expects($this->any())->method('unserializeConditionCollection')->will($this->returnValue($conditions)); $couponManager = new RemoveXAmount($stubFacade); $stubContainer->expects($this->any())->method('get')->will($this->onConsecutiveCalls($stubFacade, $couponManager, $stubConditionFactory, $stubFacade)); $stubContainer->expects($this->any())->method('has')->will($this->returnValue(true)); $couponFactory = new CouponFactory($stubContainer); $model1 = $this->generateCouponModel($stubFacade, $conditionFactory); $coupon1 = $couponFactory->buildCouponFromModel($model1); $coupon2 = clone $coupon1; $couponManager = new CouponManager($stubContainer); $couponManager->addAvailableCoupon($coupon1); $couponManager->addAvailableCoupon($coupon2); $actual = $couponManager->getAvailableCoupons(); $expected = array($coupon1, $coupon2); $this->assertEquals($expected, $actual); }