Skip to content

Commit b05a8fd

Browse files
committed
🎨
1 parent ce96ad3 commit b05a8fd

11 files changed

Lines changed: 106 additions & 42 deletions

tests/Unit/Concerns/BuildsArrayTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,13 @@ public function assemble(array $fields): array
167167

168168
// If the instanceof check were mutated to true, this would fatal-error
169169
// because BuildsArrayNoExtensionsFixture has no getExtensions() method.
170-
$out = $fixture->assemble(['title' => 'Test']);
170+
$out = $fixture->assemble([
171+
'title' => 'Test',
172+
]);
171173

172-
expect($out)->toBe(['title' => 'Test']);
174+
expect($out)->toBe([
175+
'title' => 'Test',
176+
]);
173177
});
174178

175179
it('unwraps a Cortex JsonSchema stripping $schema and title', function (): void {

tests/Unit/Objects/EncodingTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@
4040
});
4141

4242
it('explode() defaults to true', function (): void {
43-
expect(Encoding::create()->explode()->toArray())->toBe(['explode' => true]);
43+
expect(Encoding::create()->explode()->toArray())->toBe([
44+
'explode' => true,
45+
]);
4446
});
4547

4648
it('allowReserved() defaults to true', function (): void {
47-
expect(Encoding::create()->allowReserved()->toArray())->toBe(['allowReserved' => true]);
49+
expect(Encoding::create()->allowReserved()->toArray())->toBe([
50+
'allowReserved' => true,
51+
]);
4852
});

tests/Unit/Objects/HeaderTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@
3939
});
4040

4141
it('required() defaults to true', function (): void {
42-
expect(Header::create()->required()->toArray())->toBe(['required' => true]);
42+
expect(Header::create()->required()->toArray())->toBe([
43+
'required' => true,
44+
]);
4345
});
4446

4547
it('deprecated() defaults to true', function (): void {
46-
expect(Header::create()->deprecated()->toArray())->toBe(['deprecated' => true]);
48+
expect(Header::create()->deprecated()->toArray())->toBe([
49+
'deprecated' => true,
50+
]);
4751
});
4852

4953
it('emits all optional fields when set', function (): void {
@@ -59,14 +63,20 @@
5963
'style' => 'simple',
6064
'explode' => true,
6165
'allowReserved' => true,
62-
'schema' => ['type' => 'string'],
66+
'schema' => [
67+
'type' => 'string',
68+
],
6369
]);
6470
});
6571

6672
it('explode() defaults to true', function (): void {
67-
expect(Header::create()->explode()->toArray())->toBe(['explode' => true]);
73+
expect(Header::create()->explode()->toArray())->toBe([
74+
'explode' => true,
75+
]);
6876
});
6977

7078
it('allowReserved() defaults to true', function (): void {
71-
expect(Header::create()->allowReserved()->toArray())->toBe(['allowReserved' => true]);
79+
expect(Header::create()->allowReserved()->toArray())->toBe([
80+
'allowReserved' => true,
81+
]);
7282
});

tests/Unit/Objects/LinkTest.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,22 @@
5656
it('inserts requestBody after parameters when parameters are present', function (): void {
5757
$link = Link::create()
5858
->operationId('users.create')
59-
->parameters(['id' => '$response.body#/id'])
60-
->requestBody(['key' => 'value']);
59+
->parameters([
60+
'id' => '$response.body#/id',
61+
])
62+
->requestBody([
63+
'key' => 'value',
64+
]);
6165

6266
$array = $link->toArray();
6367

6468
expect($array)->toHaveKey('requestBody');
65-
expect($array['requestBody'])->toBe(['key' => 'value']);
69+
expect($array['requestBody'])->toBe([
70+
'key' => 'value',
71+
]);
72+
6673
$keys = array_keys($array);
67-
expect(array_search('requestBody', $keys))->toBeGreaterThan(array_search('parameters', $keys));
74+
expect(array_search('requestBody', $keys, true))->toBeGreaterThan(array_search('parameters', $keys, true));
6875
});
6976

7077
it('inserts requestBody before description when no parameters present', function (): void {
@@ -77,26 +84,30 @@
7784

7885
expect($array)->toHaveKey('requestBody');
7986
$keys = array_keys($array);
80-
expect(array_search('requestBody', $keys))->toBeLessThan(array_search('description', $keys));
87+
expect(array_search('requestBody', $keys, true))->toBeLessThan(array_search('description', $keys, true));
8188
});
8289

8390
it('inserts requestBody before server when no parameters or description', function (): void {
8491
$link = Link::create()
8592
->operationId('users.show')
86-
->requestBody(['body' => 'data'])
93+
->requestBody([
94+
'body' => 'data',
95+
])
8796
->server(Server::create('https://api.example.com'));
8897

8998
$array = $link->toArray();
9099

91100
expect($array)->toHaveKey('requestBody');
92101
$keys = array_keys($array);
93-
expect(array_search('requestBody', $keys))->toBeLessThan(array_search('server', $keys));
102+
expect(array_search('requestBody', $keys, true))->toBeLessThan(array_search('server', $keys, true));
94103
});
95104

96105
it('appends requestBody at end when no parameters, description, or server', function (): void {
97106
$link = Link::create()
98107
->operationId('users.show')
99-
->requestBody(['body' => 'data']);
108+
->requestBody([
109+
'body' => 'data',
110+
]);
100111

101112
$array = $link->toArray();
102113

tests/Unit/Objects/MediaTypeTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
declare(strict_types=1);
44

55
use Cortex\JsonSchema\Schema;
6-
use Cortex\OpenApi\Objects\Encoding;
76
use Cortex\OpenApi\Objects\Example;
7+
use Cortex\OpenApi\Objects\Encoding;
88
use Cortex\OpenApi\Objects\MediaType;
99
use Cortex\OpenApi\Objects\Reference;
1010

@@ -75,24 +75,30 @@
7575
it('example appears before encoding in output', function (): void {
7676
$mediaType = MediaType::json(Schema::string())
7777
->example('foo')
78-
->encoding(['photo' => Encoding::create()->contentType('image/png')]);
78+
->encoding([
79+
'photo' => Encoding::create()->contentType('image/png'),
80+
]);
7981

8082
$keys = array_keys($mediaType->toArray());
81-
expect(array_search('example', $keys))->toBeLessThan(array_search('encoding', $keys));
83+
expect(array_search('example', $keys, true))->toBeLessThan(array_search('encoding', $keys, true));
8284
});
8385

8486
it('example appears at end when only schema present', function (): void {
8587
$mediaType = MediaType::json(Schema::string())->example('foo');
8688

8789
expect($mediaType->toArray())->toBe([
88-
'schema' => ['type' => 'string'],
90+
'schema' => [
91+
'type' => 'string',
92+
],
8993
'example' => 'foo',
9094
]);
9195
});
9296

9397
it('emits encoding', function (): void {
9498
$mediaType = MediaType::json(Schema::object())
95-
->encoding(['photo' => Encoding::create()->contentType('image/png')]);
99+
->encoding([
100+
'photo' => Encoding::create()->contentType('image/png'),
101+
]);
96102

97103
expect($mediaType->toArray())->toHaveKey('encoding');
98104
});

tests/Unit/Objects/OperationTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
declare(strict_types=1);
44

55
use Cortex\JsonSchema\Schema;
6+
use Cortex\OpenApi\Objects\Server;
67
use Cortex\OpenApi\Enums\HttpMethod;
78
use Cortex\OpenApi\Objects\Callback;
89
use Cortex\OpenApi\Objects\PathItem;
9-
use Cortex\OpenApi\Objects\Reference;
1010
use Cortex\OpenApi\Objects\Response;
1111
use Cortex\OpenApi\Objects\MediaType;
1212
use Cortex\OpenApi\Objects\Operation;
1313
use Cortex\OpenApi\Objects\Parameter;
14+
use Cortex\OpenApi\Objects\Reference;
1415
use Cortex\OpenApi\Objects\RequestBody;
1516
use Cortex\OpenApi\Objects\ExternalDocs;
1617
use Cortex\OpenApi\Objects\SecurityRequirement;
17-
use Cortex\OpenApi\Objects\Server;
1818

1919
covers(Operation::class);
2020

@@ -112,14 +112,18 @@
112112
});
113113

114114
it('deprecated() defaults to true', function (): void {
115-
expect(Operation::get()->deprecated()->toArray())->toMatchArray(['deprecated' => true]);
115+
expect(Operation::get()->deprecated()->toArray())->toMatchArray([
116+
'deprecated' => true,
117+
]);
116118
});
117119

118120
it('emits servers when set', function (): void {
119121
$operation = Operation::get()->servers(Server::create('https://api.example.com'));
120122

121123
expect($operation->toArray())->toBe([
122-
'servers' => [['url' => 'https://api.example.com']],
124+
'servers' => [[
125+
'url' => 'https://api.example.com',
126+
]],
123127
]);
124128
});
125129

@@ -131,7 +135,9 @@
131135

132136
expect($operation->toArray())->toBe([
133137
'responses' => [
134-
'200' => ['description' => 'OK'],
138+
'200' => [
139+
'description' => 'OK',
140+
],
135141
],
136142
]);
137143
});

tests/Unit/Objects/ParameterTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,31 @@
8888
});
8989

9090
it('required() defaults to true', function (): void {
91-
expect(Parameter::query('test', Schema::string())->required()->toArray())->toMatchArray(['required' => true]);
91+
expect(Parameter::query('test', Schema::string())->required()->toArray())->toMatchArray([
92+
'required' => true,
93+
]);
9294
});
9395

9496
it('deprecated() defaults to true', function (): void {
95-
expect(Parameter::query('test', Schema::string())->deprecated()->toArray())->toMatchArray(['deprecated' => true]);
97+
expect(Parameter::query('test', Schema::string())->deprecated()->toArray())->toMatchArray([
98+
'deprecated' => true,
99+
]);
96100
});
97101

98102
it('explode() defaults to true', function (): void {
99-
expect(Parameter::query('test', Schema::string())->explode()->toArray())->toMatchArray(['explode' => true]);
103+
expect(Parameter::query('test', Schema::string())->explode()->toArray())->toMatchArray([
104+
'explode' => true,
105+
]);
100106
});
101107

102108
it('allowReserved() defaults to true', function (): void {
103-
expect(Parameter::query('test', Schema::string())->allowReserved()->toArray())->toMatchArray(['allowReserved' => true]);
109+
expect(Parameter::query('test', Schema::string())->allowReserved()->toArray())->toMatchArray([
110+
'allowReserved' => true,
111+
]);
104112
});
105113

106114
it('emits allowEmptyValue when set', function (): void {
107-
expect(Parameter::query('test', Schema::string())->allowEmptyValue(true)->toArray())->toMatchArray(['allowEmptyValue' => true]);
115+
expect(Parameter::query('test', Schema::string())->allowEmptyValue(true)->toArray())->toMatchArray([
116+
'allowEmptyValue' => true,
117+
]);
108118
});

tests/Unit/Objects/PathItemTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@
9090

9191
$result = $pathItem->toArray();
9292
expect($result['servers'])->toBe([
93-
['url' => 'https://api.example.com'],
94-
['url' => 'https://staging.example.com'],
93+
[
94+
'url' => 'https://api.example.com',
95+
],
96+
[
97+
'url' => 'https://staging.example.com',
98+
],
9599
]);
96100
expect(array_is_list($result['servers']))->toBeTrue();
97101
});

tests/Unit/Objects/RequestBodyTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,7 @@
6666
->required()
6767
->content(MediaType::json(Schema::string()));
6868

69-
expect($requestBody->toArray())->toMatchArray(['required' => true]);
69+
expect($requestBody->toArray())->toMatchArray([
70+
'required' => true,
71+
]);
7072
});

tests/Unit/Objects/XmlTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@
2828
});
2929

3030
it('attribute() defaults to true', function (): void {
31-
expect(Xml::create()->attribute()->toArray())->toBe(['attribute' => true]);
31+
expect(Xml::create()->attribute()->toArray())->toBe([
32+
'attribute' => true,
33+
]);
3234
});
3335

3436
it('wrapped() defaults to true', function (): void {
35-
expect(Xml::create()->wrapped()->toArray())->toBe(['wrapped' => true]);
37+
expect(Xml::create()->wrapped()->toArray())->toBe([
38+
'wrapped' => true,
39+
]);
3640
});

0 commit comments

Comments
 (0)