1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Storgman - Student Organizations Management |
5
|
|
|
* Copyright (C) 2014-2015, Dejan Angelov <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This file is part of Storgman. |
8
|
|
|
* |
9
|
|
|
* Storgman is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU General Public License as published by |
11
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
12
|
|
|
* (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* Storgman is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with Storgman. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
* @package Storgman |
23
|
|
|
* @copyright Copyright (C) 2014-2015, Dejan Angelov <[email protected]> |
24
|
|
|
* @license https://github.com/angelov/storgman/blob/master/LICENSE |
25
|
|
|
* @author Dejan Angelov <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
namespace Angelov\Storgman\Tests\Meetings; |
29
|
|
|
|
30
|
|
|
use Angelov\Storgman\Core\DateTime; |
31
|
|
|
use Angelov\Storgman\Members\Member; |
32
|
|
|
use Angelov\Storgman\Members\Repositories\MembersRepositoryInterface; |
33
|
|
|
use Angelov\Storgman\Membership\MembershipService; |
34
|
|
|
use Angelov\Storgman\Membership\Reports\ExpectedAndPaidFeesPerMonthReport; |
35
|
|
|
use Angelov\Storgman\Membership\Reports\ExpectedFeesPerMonthReport; |
36
|
|
|
use Angelov\Storgman\Membership\Reports\PaidFeesPerMonthReport; |
37
|
|
|
use Angelov\Storgman\Membership\Repositories\FeesRepositoryInterface; |
38
|
|
|
use Angelov\Storgman\Tests\TestCase; |
39
|
|
|
use Carbon\Carbon; |
40
|
|
|
use Mockery; |
41
|
|
|
|
42
|
|
|
class MembershipServiceTest extends TestCase |
43
|
|
|
{ |
44
|
|
|
/** @var $members Mockery\MockInterface */ |
45
|
|
|
protected $members; |
46
|
|
|
|
47
|
|
|
/** @var $fees Mockery\MockInterface */ |
48
|
|
|
protected $fees; |
49
|
|
|
|
50
|
|
|
public function setUp() |
51
|
|
|
{ |
52
|
|
|
parent::setUp(); |
53
|
|
|
|
54
|
|
|
$this->members = Mockery::mock(MembersRepositoryInterface::class); |
55
|
|
|
$this->fees = Mockery::mock(FeesRepositoryInterface::class); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testCanGenerateExpectedAndPaidFeesPerMonthLastYearReport() |
59
|
|
|
{ |
60
|
|
|
$membershipService = new MembershipService($this->members, $this->fees); |
61
|
|
|
|
62
|
|
|
$expectedFeesPerMonthReport = Mockery::mock(ExpectedFeesPerMonthReport::class); |
63
|
|
|
$paidFeesPerMonthReport = Mockery::mock(PaidFeesPerMonthReport::class); |
64
|
|
|
|
65
|
|
|
$this->fees->shouldReceive('calculateExpectedFeesPerMonth')->andReturn($expectedFeesPerMonthReport); |
66
|
|
|
$this->fees->shouldReceive('calculatePaidFeesPerMonth')->andReturn($paidFeesPerMonthReport); |
67
|
|
|
|
68
|
|
|
$expected = [10, 15, 20]; |
69
|
|
|
$paid = [5, 20, 15]; |
70
|
|
|
|
71
|
|
|
$expectedFeesPerMonthReport->shouldReceive('getMonthsValues')->andReturn($expected); |
72
|
|
|
$paidFeesPerMonthReport->shouldReceive('getMonthsValues')->andReturn($paid); |
73
|
|
|
|
74
|
|
|
$this->fees->shouldReceive('calculateExpectedFeesPerMonth'); |
75
|
|
|
$this->fees->shouldReceive('calculatePaidFeesPerMonth'); |
76
|
|
|
|
77
|
|
|
$report = $membershipService->getExpectedAndPaidFeesPerMonthLastYear(); |
78
|
|
|
|
79
|
|
|
$this->assertInstanceOf(ExpectedAndPaidFeesPerMonthReport::class, $report); |
80
|
|
|
|
81
|
|
|
$this->assertEquals($paid, $report->getPaidFees()); |
82
|
|
|
$this->assertEquals($expected, $report->getExpectedFees()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testCanGenerateSuggestionDatesForExistingMember() |
86
|
|
|
{ |
87
|
|
|
$member = Mockery::mock(Member::class); |
88
|
|
|
$expirationDate = new Carbon('2015-10-22'); |
89
|
|
|
$member->shouldReceive('getExpirationDate')->andReturn($expirationDate); |
90
|
|
|
|
91
|
|
|
$membershipService = new MembershipService($this->members, $this->fees); |
92
|
|
|
|
93
|
|
|
$suggestedDates = $membershipService->suggestDates($member); |
94
|
|
|
|
95
|
|
|
$this->assertTrue(is_array($suggestedDates)); |
96
|
|
|
$this->assertEquals('2015-10-23', $suggestedDates['from']); |
97
|
|
|
$this->assertEquals('2016-10-23', $suggestedDates['to']); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testCanGenerateSuggestionDatesForNewMember() |
101
|
|
|
{ |
102
|
|
|
$member = Mockery::mock(Member::class); |
103
|
|
|
$member->shouldReceive('getExpirationDate')->andReturnNull(); |
|
|
|
|
104
|
|
|
|
105
|
|
|
$membershipService = new MembershipService($this->members, $this->fees); |
106
|
|
|
|
107
|
|
|
$suggestedDates = $membershipService->suggestDates($member); |
108
|
|
|
|
109
|
|
|
$now = new Carbon(); |
110
|
|
|
$nextYear = (new Carbon())->addYear(); |
111
|
|
|
|
112
|
|
|
$this->assertTrue(is_array($suggestedDates)); |
113
|
|
|
$this->assertEquals($now->format('Y-m-d'), $suggestedDates['from']); |
114
|
|
|
$this->assertEquals($nextYear->format('Y-m-d'), $suggestedDates['to']); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: