Skip to content

Commit 7599885

Browse files
committed
add tests for files
1 parent 7062100 commit 7599885

File tree

3 files changed

+76
-4
lines changed

3 files changed

+76
-4
lines changed

examples/FilesTest.php

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Examples;
4+
5+
use RestControl\TestCase\AbstractTestCase;
6+
7+
class FilesTest extends AbstractTestCase
8+
{
9+
/**
10+
* @test(
11+
* title="Download png file.",
12+
* tags="files png"
13+
* )
14+
*/
15+
public function exampleGetPng()
16+
{
17+
return send()
18+
->get($this->getVar('training') . '/plain/files/png')
19+
->expectedResponse()
20+
->contentTypeImagePng()
21+
->size(66796);
22+
}
23+
24+
/**
25+
* @test(
26+
* title="Download png file.",
27+
* tags="files css"
28+
* )
29+
*/
30+
public function exampleGetCss()
31+
{
32+
return send()
33+
->get($this->getVar('training') . '/plain/files/css')
34+
->expectedResponse()
35+
->contentTypeTextCss()
36+
->size(31);
37+
}
38+
39+
/**
40+
* @test(
41+
* title="Download png file.",
42+
* tags="files javascript"
43+
* )
44+
*/
45+
public function exampleGetJavascript()
46+
{
47+
return send()
48+
->get($this->getVar('training') . '/plain/files/js')
49+
->expectedResponse()
50+
->contentTypeTextJavascript()
51+
->size(28);
52+
}
53+
54+
/**
55+
* @test(
56+
* title="Download png file.",
57+
* tags="files csv"
58+
* )
59+
*/
60+
public function exampleGetCsv()
61+
{
62+
return send()
63+
->get($this->getVar('training') . '/plain/files/csv')
64+
->expectedResponse()
65+
->contentTypeTextCsv()
66+
->size(69);
67+
}
68+
}

examples/ServerResponses/GetUser.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function getUrl()
109109
public function getApiClientResponse(ApiClientRequest $request, array $routeParams)
110110
{
111111
if(!isset($routeParams['id'])) {
112-
return new ApiClientResponse(404, [], '');
112+
return new ApiClientResponse(404, [], '', 0);
113113
}
114114

115115
return $this->getUser($request, $routeParams['id']);
@@ -124,11 +124,13 @@ public function getApiClientResponse(ApiClientRequest $request, array $routePara
124124
protected function getUser(ApiClientRequest $request, $userId)
125125
{
126126
if(!isset($this->users[$userId])) {
127-
return new ApiClientResponse(404, '');
127+
return new ApiClientResponse(404, '', 0);
128128
}
129129

130+
$body = json_encode($this->users[$userId]);
131+
130132
return new ApiClientResponse(200, [
131133
'Content-Type' => 'application/json'
132-
], json_encode($this->users[$userId]));
134+
], $body, strlen($body));
133135
}
134136
}

examples/ServerResponses/GetUsers.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ public function getUrl()
2929
*/
3030
public function getApiClientResponse(ApiClientRequest $request, array $routeParams)
3131
{
32+
$body = json_encode($this->users);
33+
3234
return new ApiClientResponse(200, [
3335
'Content-Type' => 'application/json'
34-
], json_encode($this->users));
36+
], $body, strlen($body));
3537
}
3638
}

0 commit comments

Comments
 (0)