3
3
namespace Coding \Tests ;
4
4
5
5
use Coding \Core ;
6
+ use Coding \Exceptions \ValidationException ;
6
7
use Coding \Iteration ;
7
8
8
9
class IterationTest extends TestCase
9
10
{
10
- public function testCreateSuccess ()
11
+ public function testCreateSuccessWithOnlyRequiredParams ()
11
12
{
12
13
$ coreMock = \Mockery::mock (Core::class, [])->makePartial ();
13
14
@@ -28,4 +29,58 @@ public function testCreateSuccess()
28
29
$ result = $ iteration ->create ($ data );
29
30
$ this ->assertEquals ($ response ['Iteration ' ], $ result );
30
31
}
32
+
33
+ public function testCreateSuccessWithAllParams ()
34
+ {
35
+ $ coreMock = \Mockery::mock (Core::class, [])->makePartial ();
36
+
37
+ $ response = json_decode (
38
+ file_get_contents ($ this ->dataPath ('CreateIterationResponse.json ' )),
39
+ true
40
+ )['Response ' ];
41
+ $ startAt = $ this ->faker ->date ();
42
+ $ data = [
43
+ 'ProjectName ' => $ this ->projectName ,
44
+ 'Name ' => $ this ->faker ->title ,
45
+ 'Goal ' => $ this ->faker ->sentence ,
46
+ 'Assignee ' => $ this ->faker ->randomNumber (),
47
+ 'StartAt ' => $ startAt ,
48
+ 'EndAt ' => date ('Y-m-d ' , strtotime ($ startAt ) + $ this ->faker ->randomDigitNotZero () * 86400 ),
49
+ ];
50
+ $ coreMock ->shouldReceive ('request ' )->times (1 )->withArgs ([
51
+ 'CreateIteration ' ,
52
+ $ data
53
+ ])->andReturn ($ response );
54
+
55
+ $ iteration = new Iteration ($ this ->token , $ coreMock );
56
+ $ result = $ iteration ->create ($ data );
57
+ $ this ->assertEquals ($ response ['Iteration ' ], $ result );
58
+ }
59
+
60
+ public function testCreateFailedRequired ()
61
+ {
62
+ $ data = [
63
+ 'ProjectName ' => $ this ->projectName ,
64
+ ];
65
+
66
+ $ iteration = new Iteration ($ this ->token );
67
+ $ this ->expectException (ValidationException::class);
68
+ $ this ->expectExceptionMessage ('The name field is required. ' );
69
+ $ iteration ->create ($ data );
70
+ }
71
+
72
+ public function testCreateFailedBefore ()
73
+ {
74
+ $ data = [
75
+ 'ProjectName ' => $ this ->projectName ,
76
+ 'Name ' => $ this ->faker ->title ,
77
+ 'StartAt ' => '2021-10-23 ' ,
78
+ 'EndAt ' => '2021-10-22 ' ,
79
+ ];
80
+
81
+ $ iteration = new Iteration ($ this ->token );
82
+ $ this ->expectException (ValidationException::class);
83
+ $ this ->expectExceptionMessage ('The end at must be a date after start at. ' );
84
+ $ iteration ->create ($ data );
85
+ }
31
86
}
0 commit comments