Skip to content

Commit

Permalink
Merge pull request #3340 from PWalkow/add-missing-spec-for-contains-p…
Browse files Browse the repository at this point in the history
…roduct-rule-checker

[Core] Add missing spec for ContainsProductRuleChecker
  • Loading branch information
Paweł Jędrzejewski committed Oct 21, 2015
2 parents 1197b3e + abe6d7a commit 7a04c6e
Showing 1 changed file with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\Sylius\Component\Core\Promotion\Checker;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItem;
use Sylius\Component\Core\Model\ProductVariant;
use Sylius\Component\Promotion\Exception\UnsupportedTypeException;
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;

/**
* @author Piotr Walków <[email protected]>
*/
class ContainsProductRuleCheckerSpec extends ObjectBehavior
{
function it_is_initialibable()
{
$this->shouldHaveType('Sylius\Component\Core\Promotion\Checker\ContainsProductRuleChecker');
}

function it_is_sylius_rule_checker()
{
$this->shouldImplement('Sylius\Component\Promotion\Checker\RuleCheckerInterface');
}

function it_throws_exception_on_invalid_subject(PromotionSubjectInterface $subject)
{
$this->shouldThrow(UnsupportedTypeException::class)->duringIsEligible($subject, []);
}

function it_returns_true_if_variant_is_right_and_exclude_is_not_set(
OrderInterface $subject,
OrderItem $orderItem,
ProductVariant $variant
) {
$subject->getItems()->willReturn([$orderItem]);
$orderItem->getVariant()->willReturn($variant);
$variant->getId()->willReturn(1);

$this->isEligible($subject, ['variant' => 1, 'exclude' => false])->shouldReturn(true);
}

function it_returns_false_if_variant_is_right_and_exclude_is_set(
OrderInterface $subject,
OrderItem $orderItem,
ProductVariant $variant
) {
$subject->getItems()->willReturn([$orderItem]);
$orderItem->getVariant()->willReturn($variant);
$variant->getId()->willReturn(1);

$this->isEligible($subject, ['variant' => 1, 'exclude' => true])->shouldReturn(false);
}

function it_returns_true_if_variant_is_not_included_and_exclude_is_not_set(
OrderInterface $subject,
OrderItem $orderItem,
ProductVariant $variant
) {
$subject->getItems()->willReturn([$orderItem]);
$orderItem->getVariant()->willReturn($variant);
$variant->getId()->willReturn(2);

$this->isEligible($subject, ['variant' => 1, 'exclude' => true])->shouldReturn(true);
}

function it_returns_false_if_variant_is_not_included_and_exclude_is_not_set(
OrderInterface $subject,
OrderItem $orderItem,
ProductVariant $variant
) {
$subject->getItems()->willReturn([$orderItem]);
$orderItem->getVariant()->willReturn($variant);
$variant->getId()->willReturn(2);

$this->isEligible($subject, ['variant' => 1, 'exclude' => false])->shouldReturn(false);
}
}

0 comments on commit 7a04c6e

Please sign in to comment.