Passed
Branch master (6a00e9)
by David
02:22
created

AbstractTestCaseBase   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 89
rs 10
c 0
b 0
f 0
wmc 1
1
<?php
2
3
namespace Terox\SubscriptionBundle\Tests;
4
5
use Monolog\Logger;
6
use PHPUnit\Framework\TestCase;
7
use Terox\SubscriptionBundle\Exception\PermanentSubscriptionException;
8
use Terox\SubscriptionBundle\Model\ProductInterface;
9
use Terox\SubscriptionBundle\Model\SubscriptionInterface;
10
use Terox\SubscriptionBundle\Repository\ProductRepositoryInterface;
11
use Terox\SubscriptionBundle\Repository\SubscriptionRepositoryInterface;
12
use Terox\SubscriptionBundle\Strategy\ProductDefaultStrategy;
13
use Terox\SubscriptionBundle\Strategy\ProductStrategyInterface;
14
use Terox\SubscriptionBundle\Strategy\SubscriptionEndLastStrategy;
15
use Terox\SubscriptionBundle\Registry\SubscriptionRegistry;
16
use Terox\SubscriptionBundle\Tests\Mock\SubscriptionMock;
17
use Terox\SubscriptionBundle\Tests\Mock\UserMock;
18
19
abstract class AbstractTestCaseBase extends TestCase
20
{
21
    const MONTH_SECONDS = 2592000;
22
23
    /**
24
     * @var Logger
25
     */
26
    protected $logger;
27
    
28
    protected $productRepository;
29
    
30
    /**
31
     * @var SubscriptionRepositoryInterface
32
     */
33
    protected $subscriptionRepository;
34
35
    /**
36
     * @var \DateTimeImmutable
37
     */
38
    protected $subscription1EndDate;
39
40
    /**
41
     * @var SubscriptionInterface
42
     */
43
    protected $currentSubscription1;
44
45
    /**
46
     * @var SubscriptionInterface
47
     */
48
    protected $currentSubscription2;
49
50
    /**
51
     * @var SubscriptionInterface
52
     */
53
    protected $currentSubscription3;
54
55
    /**
56
     * @var SubscriptionInterface
57
     */
58
    protected $permanentSubscription;
59
    
60
    protected $defaultProductStrategy;
61
    
62
    protected $product;
63
    
64
    public function setUp()
65
    {
66
        // Logger
67
        $this->logger = \Mockery::mock(Logger::class);
68
        $this->logger->shouldReceive('error');
69
        
70
        // Product repository
71
        $this->productRepository = \Mockery::mock(ProductRepositoryInterface::class); 
72
        
73
        // Subscription repository
74
        $this->subscriptionRepository = \Mockery::mock(SubscriptionRepositoryInterface::class);
75
76
        // Subscriptions
77
        $this->subscription1EndDate = new \DateTimeImmutable('+10 days');
78
        $this->currentSubscription1 = \Mockery::mock(SubscriptionInterface::class);
79
        $this->currentSubscription1->shouldReceive('getEndDate')->andReturn($this->subscription1EndDate);
80
        $this->currentSubscription1->shouldReceive('getUser')->andReturn(new UserMock());
81
        $this->currentSubscription1->shouldReceive('setStrategy');
82
83
        $this->currentSubscription2 = \Mockery::mock(SubscriptionInterface::class);
84
        $this->currentSubscription2->shouldReceive('getEndDate')->andReturn($this->subscription1EndDate->modify('+5 days'));
85
        $this->currentSubscription2->shouldReceive('getUser')->andReturn(new UserMock());
86
        $this->currentSubscription2->shouldReceive('setStrategy');
87
88
        $this->currentSubscription3 = \Mockery::mock(SubscriptionInterface::class);
89
        $this->currentSubscription3->shouldReceive('getEndDate')->andReturn($this->subscription1EndDate->modify('+10 days'));
90
        $this->currentSubscription3->shouldReceive('getUser')->andReturn(new UserMock());
91
        $this->currentSubscription3->shouldReceive('setStrategy');
92
93
        $this->permanentSubscription = \Mockery::mock(SubscriptionInterface::class);
94
        $this->permanentSubscription->shouldReceive('getEndDate')->andReturn(null);
95
        $this->permanentSubscription->shouldReceive('getUser')->andReturn(new UserMock());
96
        $this->permanentSubscription->shouldReceive('setStrategy');
97
98
        // Default Product Strategy
99
        $this->defaultProductStrategy = new ProductDefaultStrategy(
100
            $this->productRepository,
101
            $this->subscriptionRepository,
102
            $this->logger
103
        );
104
105
        // Product Base
106
        $this->product = \Mockery::mock(ProductInterface::class);
107
        $this->product->shouldReceive('getName')->andReturn('Product A');
108
    }
109
}