@@ -61,9 +61,10 @@ public function testCachePurge()
61
61
->method ('post ' )
62
62
->with (
63
63
$ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache ' ),
64
- $ this ->equalTo (['files ' => [
65
- 'https://example.com/file.jpg ' ,
66
- ]
64
+ $ this ->equalTo ([
65
+ 'files ' => [
66
+ 'https://example.com/file.jpg ' ,
67
+ ]
67
68
])
68
69
);
69
70
@@ -75,4 +76,106 @@ public function testCachePurge()
75
76
$ this ->assertTrue ($ result );
76
77
$ this ->assertEquals ('023e105f4ecef8ad9ca31a8372d0c353 ' , $ zones ->getBody ()->result ->id );
77
78
}
79
+
80
+ public function testCachePurgeIncludingEnvironments ()
81
+ {
82
+ $ envResp = $ this ->getPsr7JsonResponseForFixture ('Endpoints/getEnvironments.json ' );
83
+ $ cacheResp = $ this ->getPsr7JsonResponseForFixture ('Endpoints/cachePurge.json ' );
84
+ $ mock = $ this ->getMockBuilder (\Cloudflare \API \Adapter \Adapter::class)->getMock ();
85
+
86
+ $ mock ->expects ($ this ->once ())
87
+ ->method ('get ' )
88
+ ->willReturn ($ envResp )
89
+ ->with (
90
+ $ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/environments ' )
91
+ );
92
+
93
+ $ mock ->expects ($ this ->exactly (4 ))
94
+ ->method ('post ' )
95
+ ->willReturn ($ cacheResp )
96
+ ->withConsecutive (
97
+ [
98
+ $ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/environments/first/purge_cache ' ),
99
+ $ this ->equalTo ([
100
+ 'files ' => [
101
+ 'https://example.com/file.jpg ' ,
102
+ ]
103
+ ])
104
+ ],
105
+ [
106
+ $ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/environments/second/purge_cache ' ),
107
+ $ this ->equalTo ([
108
+ 'files ' => [
109
+ 'https://example.com/file.jpg ' ,
110
+ ]
111
+ ])
112
+ ],
113
+ [
114
+ $ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/environments/third/purge_cache ' ),
115
+ $ this ->equalTo ([
116
+ 'files ' => [
117
+ 'https://example.com/file.jpg ' ,
118
+ ]
119
+ ])
120
+ ],
121
+ [
122
+ $ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache ' ),
123
+ $ this ->equalTo ([
124
+ 'files ' => [
125
+ 'https://example.com/file.jpg ' ,
126
+ ]
127
+ ])
128
+ ]
129
+ );
130
+
131
+ $ zones = new \Cloudflare \API \Endpoints \Zones ($ mock );
132
+ $ result = $ zones ->cachePurge ('c2547eb745079dac9320b638f5e225cf483cc5cfdda41 ' , [
133
+ 'https://example.com/file.jpg ' ,
134
+ ], null , null , true );
135
+
136
+ $ this ->assertTrue ($ result );
137
+ $ this ->assertEquals ('023e105f4ecef8ad9ca31a8372d0c353 ' , $ zones ->getBody ()->result ->id );
138
+ }
139
+
140
+ public function testCachePurgeEverythingIncludingEnvironments ()
141
+ {
142
+ $ envResp = $ this ->getPsr7JsonResponseForFixture ('Endpoints/getEnvironments.json ' );
143
+ $ cacheResp = $ this ->getPsr7JsonResponseForFixture ('Endpoints/cachePurgeEverything.json ' );
144
+ $ mock = $ this ->getMockBuilder (\Cloudflare \API \Adapter \Adapter::class)->getMock ();
145
+
146
+ $ mock ->expects ($ this ->once ())
147
+ ->method ('get ' )
148
+ ->willReturn ($ envResp )
149
+ ->with (
150
+ $ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/environments ' )
151
+ );
152
+
153
+ $ mock ->expects ($ this ->exactly (4 ))
154
+ ->method ('post ' )
155
+ ->willReturn ($ cacheResp )
156
+ ->withConsecutive (
157
+ [
158
+ $ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/environments/first/purge_cache ' ),
159
+ $ this ->equalTo (['purge_everything ' => true ])
160
+ ],
161
+ [
162
+ $ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/environments/second/purge_cache ' ),
163
+ $ this ->equalTo (['purge_everything ' => true ])
164
+ ],
165
+ [
166
+ $ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/environments/third/purge_cache ' ),
167
+ $ this ->equalTo (['purge_everything ' => true ])
168
+ ],
169
+ [
170
+ $ this ->equalTo ('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache ' ),
171
+ $ this ->equalTo (['purge_everything ' => true ])
172
+ ]
173
+ );
174
+
175
+ $ zones = new \Cloudflare \API \Endpoints \Zones ($ mock );
176
+ $ result = $ zones ->cachePurgeEverything ('c2547eb745079dac9320b638f5e225cf483cc5cfdda41 ' , true );
177
+
178
+ $ this ->assertTrue ($ result );
179
+ $ this ->assertEquals ('023e105f4ecef8ad9ca31a8372d0c353 ' , $ zones ->getBody ()->result ->id );
180
+ }
78
181
}
0 commit comments