Issues (3641)

DecisionRule/DayOfTheWeekDecisionRuleTest.php (2 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerTest\Zed\Discount\Business\DecisionRule;
9
10
use DateTime;
11
use Generated\Shared\Transfer\ClauseTransfer;
12
use Spryker\Zed\Discount\Business\DecisionRule\DayOfWeekDecisionRule;
13
use Spryker\Zed\Discount\Business\QueryString\ComparatorOperatorsInterface;
14
use SprykerTest\Zed\Discount\Business\BaseRuleTester;
15
16
/**
17
 * Auto-generated group annotations
18
 *
19
 * @group SprykerTest
20
 * @group Zed
21
 * @group Discount
22
 * @group Business
23
 * @group DecisionRule
24
 * @group DayOfTheWeekDecisionRuleTest
25
 * Add your own group annotations below this line
26
 */
27
class DayOfTheWeekDecisionRuleTest extends BaseRuleTester
28
{
29
    /**
30
     * @return void
31
     */
32
    public function testDecisionRuleShouldReturnTrueIfGivenDateMatchesClause(): void
33
    {
34
        $dateTime = new DateTime();
35
36
        $comparatorMock = $this->createComparatorMock();
37
        $comparatorMock->method('compare')->willReturnCallback(function (ClauseTransfer $clauseTransfer, $calendarWeek) {
0 ignored issues
show
The method method() does not exist on Spryker\Zed\Discount\Bus...ratorOperatorsInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        $comparatorMock->/** @scrutinizer ignore-call */ 
38
                         method('compare')->willReturnCallback(function (ClauseTransfer $clauseTransfer, $calendarWeek) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
            return $clauseTransfer->getValue() === $calendarWeek;
39
        });
40
41
        $calendarWeekDecisionRule = $this->createDateOfTheWeekDecisionRule($comparatorMock, $dateTime);
42
        $isSatisfied = $calendarWeekDecisionRule->isSatisfiedBy(
43
            $this->createQuoteTransfer(),
44
            $this->createItemTransfer(),
45
            $this->createClauseTransfer($dateTime->format(DayOfWeekDecisionRule::DATE_FORMAT)),
46
        );
47
48
        $this->assertTrue($isSatisfied);
49
    }
50
51
    /**
52
     * @param \Spryker\Zed\Discount\Business\QueryString\ComparatorOperatorsInterface $comparatorMock
53
     * @param \DateTime $currentDateTime
54
     *
55
     * @return \Spryker\Zed\Discount\Business\DecisionRule\DayOfWeekDecisionRule|\PHPUnit\Framework\MockObject\MockObject
56
     */
57
    protected function createDateOfTheWeekDecisionRule(
58
        ComparatorOperatorsInterface $comparatorMock,
59
        DateTime $currentDateTime
60
    ): DayOfWeekDecisionRule {
61
        /** @var \Spryker\Zed\Discount\Business\DecisionRule\DayOfWeekDecisionRule|\PHPUnit\Framework\MockObject\MockObject $dayOfWeekDecisionRule */
62
        $dayOfWeekDecisionRule = $this->getMockBuilder(DayOfWeekDecisionRule::class)
63
            ->setMethods(['getCurrentDateTime'])
64
            ->setConstructorArgs([$comparatorMock])
65
            ->getMock();
66
        $dayOfWeekDecisionRule->method('getCurrentDateTime')->willReturn($currentDateTime);
0 ignored issues
show
The method method() does not exist on Spryker\Zed\Discount\Bus...e\DayOfWeekDecisionRule. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        $dayOfWeekDecisionRule->/** @scrutinizer ignore-call */ 
67
                                method('getCurrentDateTime')->willReturn($currentDateTime);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
68
        return $dayOfWeekDecisionRule;
69
    }
70
}
71