Skip to content

Commit 40c1659

Browse files
committed
bodyparam test
1 parent 560ade1 commit 40c1659

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace Mtrajano\LaravelSwagger\Tests\Parameters;
4+
5+
use Mtrajano\LaravelSwagger\Tests\TestCase;
6+
use Mtrajano\LaravelSwagger\Parameters\BodyParameterGenerator;
7+
8+
class BodyParameterGeneratorTest extends TestCase
9+
{
10+
public function testStructure()
11+
{
12+
$bodyParameters = $this->getBodyParameters([]);
13+
14+
$this->assertArrayHasKey('in', $bodyParameters);
15+
$this->assertArrayHasKey('name', $bodyParameters);
16+
$this->assertArrayHasKey('schema', $bodyParameters);
17+
$this->assertArraySubset(['type' => 'object'], $bodyParameters['schema']);
18+
}
19+
20+
public function testRequiredParameters()
21+
{
22+
$bodyParameters = $this->getBodyParameters([
23+
'id' => 'integer|required',
24+
'email' => 'email|required',
25+
'address' => 'string|required',
26+
'dob' => 'date|required',
27+
'picture' => 'file',
28+
'is_validated' => 'boolean',
29+
'score' => 'numeric',
30+
]);
31+
32+
$this->assertEquals([
33+
'id',
34+
'email',
35+
'address',
36+
'dob',
37+
], $bodyParameters['schema']['required']);
38+
39+
return $bodyParameters;
40+
}
41+
42+
/**
43+
* @depends testRequiredParameters
44+
*/
45+
public function testDataTypes($bodyParameters)
46+
{
47+
$this->assertEquals([
48+
'id' => ['type' => 'integer'],
49+
'email' => ['type' => 'string'],
50+
'address' => ['type' => 'string'],
51+
'dob' => ['type' => 'string'],
52+
'picture' => ['type' => 'string'],
53+
'is_validated' => ['type' => 'boolean'],
54+
'score' => ['type' => 'number'],
55+
], $bodyParameters['schema']['properties']);
56+
}
57+
58+
public function testNoRequiredParameters()
59+
{
60+
$bodyParameters = $this->getBodyParameters([]);
61+
62+
$this->assertArrayNotHasKey('required', $bodyParameters['schema']);
63+
}
64+
65+
private function getBodyParameters(array $rules)
66+
{
67+
$bodyParameters = (new BodyParameterGenerator('post', '/', $rules))->getParameters();
68+
69+
return current($bodyParameters);
70+
}
71+
}

0 commit comments

Comments
 (0)