Skip to content

Commit 101dab3

Browse files
committed
Add more tests for static array faker
1 parent 7378cfd commit 101dab3

3 files changed

+67
-0
lines changed

tests/Unit/SchemaFaker/StaticArrayFakerTest.php

+54
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ function it_can_generate_example_integer_items()
233233
$fakeData = ArrayFaker::generate(SchemaFactory::fromJson(
234234
<<<'JSON'
235235
{
236+
"type": "array",
236237
"items": {
237238
"type": "integer"
238239
},
@@ -243,4 +244,57 @@ function it_can_generate_example_integer_items()
243244

244245
$this->assertMatchesJsonSnapshot($fakeData);
245246
}
247+
248+
/** @test */
249+
function it_can_generate_example_of_an_individual_array_item()
250+
{
251+
$fakeData = ArrayFaker::generate(SchemaFactory::fromJson(
252+
<<<'JSON'
253+
{
254+
"type": "array",
255+
"items": {
256+
"type": "integer",
257+
"example": 1
258+
}
259+
}
260+
JSON,
261+
), $this->options);
262+
263+
$this->assertMatchesJsonSnapshot($fakeData);
264+
}
265+
266+
/** @test */
267+
function it_can_generate_example_for_array_of_objects()
268+
{
269+
$fakeData = ArrayFaker::generate(SchemaFactory::fromJson(
270+
<<<'JSON'
271+
{
272+
"type": "array",
273+
"items": {
274+
"type": "object",
275+
"properties": {
276+
"id": {
277+
"type": "integer"
278+
},
279+
"name": {
280+
"type": "string"
281+
}
282+
}
283+
},
284+
"example": [
285+
{
286+
"id": 1,
287+
"name": "John"
288+
},
289+
{
290+
"id": 2,
291+
"name": "Jane"
292+
}
293+
]
294+
}
295+
JSON,
296+
), $this->options);
297+
298+
$this->assertMatchesJsonSnapshot($fakeData);
299+
}
246300
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"id": 1,
4+
"name": "John"
5+
},
6+
{
7+
"id": 2,
8+
"name": "Jane"
9+
}
10+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
1
3+
]

0 commit comments

Comments
 (0)