1
+ <?php namespace Gitlab \Tests \Api ;
2
+
3
+ use Gitlab \Api \AbstractApi ;
4
+
5
+ class SnippetsTest extends TestCase
6
+ {
7
+ /**
8
+ * @test
9
+ */
10
+ public function shouldGetAllSnippets ()
11
+ {
12
+ $ expectedArray = array (
13
+ array ('id ' => 1 , 'title ' => 'A snippet ' ),
14
+ array ('id ' => 2 , 'title ' => 'Another snippet ' ),
15
+ );
16
+
17
+ $ api = $ this ->getApiMock ();
18
+ $ api ->expects ($ this ->once ())
19
+ ->method ('get ' )
20
+ ->with ('projects/1/snippets ' )
21
+ ->will ($ this ->returnValue ($ expectedArray ))
22
+ ;
23
+
24
+ $ this ->assertEquals ($ expectedArray , $ api ->all (1 ));
25
+ }
26
+
27
+ /**
28
+ * @test
29
+ */
30
+ public function shouldShowSnippet ()
31
+ {
32
+ $ expectedArray = array ('id ' => 2 , 'title ' => 'Another snippet ' );
33
+
34
+ $ api = $ this ->getApiMock ();
35
+ $ api ->expects ($ this ->once ())
36
+ ->method ('get ' )
37
+ ->with ('projects/1/snippets/2 ' )
38
+ ->will ($ this ->returnValue ($ expectedArray ))
39
+ ;
40
+
41
+ $ this ->assertEquals ($ expectedArray , $ api ->show (1 , 2 ));
42
+ }
43
+
44
+ /**
45
+ * @test
46
+ */
47
+ public function shouldCreateSnippet ()
48
+ {
49
+ $ expectedArray = array ('id ' => 3 , 'title ' => 'A new snippet ' );
50
+
51
+ $ api = $ this ->getApiMock ();
52
+ $ api ->expects ($ this ->once ())
53
+ ->method ('post ' )
54
+ ->with ('projects/1/snippets ' , array ('title ' => 'A new snippet ' , 'code ' => 'A file ' , 'file_name ' => 'file.txt ' ))
55
+ ->will ($ this ->returnValue ($ expectedArray ))
56
+ ;
57
+
58
+ $ this ->assertEquals ($ expectedArray , $ api ->create (1 , 'A new snippet ' , 'file.txt ' , 'A file ' ));
59
+ }
60
+
61
+ /**
62
+ * @test
63
+ */
64
+ public function shouldUpdateSnippet ()
65
+ {
66
+ $ expectedArray = array ('id ' => 3 , 'title ' => 'Updated snippet ' );
67
+
68
+ $ api = $ this ->getApiMock ();
69
+ $ api ->expects ($ this ->once ())
70
+ ->method ('put ' )
71
+ ->with ('projects/1/snippets/3 ' , array ('title ' => 'Updated snippet ' , 'code ' => 'New content ' , 'file_name ' => 'new_file.txt ' ))
72
+ ->will ($ this ->returnValue ($ expectedArray ))
73
+ ;
74
+
75
+ $ this ->assertEquals ($ expectedArray , $ api ->update (1 , 3 , array ('file_name ' => 'new_file.txt ' , 'code ' => 'New content ' , 'title ' => 'Updated snippet ' )));
76
+ }
77
+
78
+ /**
79
+ * @test
80
+ */
81
+ public function shouldShowContent ()
82
+ {
83
+ $ expectedString = 'New content ' ;
84
+
85
+ $ api = $ this ->getApiMock ();
86
+ $ api ->expects ($ this ->once ())
87
+ ->method ('get ' )
88
+ ->with ('projects/1/snippets/3/raw ' )
89
+ ->will ($ this ->returnValue ($ expectedString ))
90
+ ;
91
+
92
+ $ this ->assertEquals ($ expectedString , $ api ->content (1 , 3 ));
93
+ }
94
+
95
+ /**
96
+ * @test
97
+ */
98
+ public function shouldRemoveSnippet ()
99
+ {
100
+ $ expectedBool = true ;
101
+
102
+ $ api = $ this ->getApiMock ();
103
+ $ api ->expects ($ this ->once ())
104
+ ->method ('delete ' )
105
+ ->with ('projects/1/snippets/3 ' )
106
+ ->will ($ this ->returnValue ($ expectedBool ))
107
+ ;
108
+
109
+ $ this ->assertEquals ($ expectedBool , $ api ->remove (1 , 3 ));
110
+ }
111
+
112
+ protected function getApiClass ()
113
+ {
114
+ return 'Gitlab\Api\Snippets ' ;
115
+ }
116
+ }
0 commit comments