Skip to content

Commit cb8c78e

Browse files
committed
Adding missing sanitize methods tests
1 parent c5fa9dd commit cb8c78e

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"phpcs": "php-cs-fixer fix --dry-run --diff -vvv --allow-risky=yes --ansi",
5151
"phpcs:fix": "php-cs-fixer fix -vvv --allow-risky=yes --ansi",
5252
"phpstan": "phpstan analyse -c phpstan.neon --ansi --memory-limit 192M",
53-
"phpunit": "phpunit --coverage-text",
53+
"phpunit": "XDEBUG_MODE=coverage phpunit --coverage-text",
5454
"test": [
5555
"@phpunit",
5656
"@phpstan",

src/DictionaryTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,35 @@ public function it_can_be_regenerated_with_eval(): void
256256

257257
self::assertEquals($instance, $generatedInstance);
258258
}
259+
260+
/** @test */
261+
public function it_can_sanitize_the_maps(): void
262+
{
263+
$structuredField = Dictionary::fromAssociative();
264+
$structuredField->append('item', 42);
265+
$item = $structuredField->get('item');
266+
$item->parameters->append('forty-two', '42');
267+
$wrongUpdatedItem = $item->parameters->get('forty-two');
268+
$wrongUpdatedItem->parameters->append('invalid-value', 'not-valid');
269+
self::assertCount(1, $wrongUpdatedItem->parameters);
270+
271+
$structuredField->sanitize();
272+
self::assertCount(0, $wrongUpdatedItem->parameters);
273+
}
274+
275+
/** @test */
276+
public function it_fails_http_conversion_with_invalid_parameters(): void
277+
{
278+
$this->expectException(StructuredFieldError::class);
279+
280+
$structuredField = Dictionary::fromPairs();
281+
$structuredField->append('item', 42);
282+
$item = $structuredField->get('item');
283+
$item->parameters->append('forty-two', '42');
284+
$wrongUpdatedItem = $item->parameters->get('forty-two');
285+
$wrongUpdatedItem->parameters->append('invalid-value', 'not-valid');
286+
self::assertCount(1, $wrongUpdatedItem->parameters);
287+
288+
$structuredField->toHttpValue();
289+
}
259290
}

src/InnerListTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,40 @@ public function testArrayAccessThrowsInvalidIndex2(): void
214214

215215
self::assertCount(0, $sequence);
216216
}
217+
218+
219+
220+
/** @test */
221+
public function it_can_sanitize_the_maps(): void
222+
{
223+
$structuredField = InnerList::from();
224+
$structuredField[] = 42;
225+
$structuredField[] = 69;
226+
$structuredField[] = 666;
227+
unset($structuredField[1]);
228+
$item = $structuredField[0];
229+
$item->parameters->append('forty-two', '42');
230+
$wrongUpdatedItem = $item->parameters->get('forty-two');
231+
$wrongUpdatedItem->parameters->append('invalid-value', 'not-valid');
232+
self::assertCount(1, $wrongUpdatedItem->parameters);
233+
234+
$structuredField->sanitize();
235+
self::assertCount(0, $wrongUpdatedItem->parameters);
236+
}
237+
238+
/** @test */
239+
public function it_fails_http_conversion_with_invalid_parameters(): void
240+
{
241+
$this->expectException(StructuredFieldError::class);
242+
243+
$structuredField = InnerList::fromList();
244+
$structuredField[] = 69;
245+
$item = $structuredField[0];
246+
$item->parameters->append('forty-two', '42');
247+
$wrongUpdatedItem = $item->parameters->get('forty-two');
248+
$wrongUpdatedItem->parameters->append('invalid-value', 'not-valid');
249+
self::assertCount(1, $wrongUpdatedItem->parameters);
250+
251+
$structuredField->toHttpValue();
252+
}
217253
}

src/OrderedListTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,38 @@ public function testArrayAccessThrowsInvalidIndex2(): void
186186

187187
self::assertCount(0, $sequence);
188188
}
189+
190+
/** @test */
191+
public function it_can_sanitize_the_maps(): void
192+
{
193+
$structuredField = OrderedList::from();
194+
$structuredField[] = 42;
195+
$structuredField[] = 42;
196+
$structuredField[] = 42;
197+
unset($structuredField[1]);
198+
$item = $structuredField[0];
199+
$item->parameters->append('forty-two', '42');
200+
$wrongUpdatedItem = $item->parameters->get('forty-two');
201+
$wrongUpdatedItem->parameters->append('invalid-value', 'not-valid');
202+
self::assertCount(1, $wrongUpdatedItem->parameters);
203+
204+
$structuredField->sanitize();
205+
self::assertCount(0, $wrongUpdatedItem->parameters);
206+
}
207+
208+
/** @test */
209+
public function it_fails_http_conversion_with_invalid_parameters(): void
210+
{
211+
$this->expectException(StructuredFieldError::class);
212+
213+
$structuredField = OrderedList::fromList();
214+
$structuredField[] = 42;
215+
$item = $structuredField[0];
216+
$item->parameters->append('forty-two', '42');
217+
$wrongUpdatedItem = $item->parameters->get('forty-two');
218+
$wrongUpdatedItem->parameters->append('invalid-value', 'not-valid');
219+
self::assertCount(1, $wrongUpdatedItem->parameters);
220+
221+
$structuredField->toHttpValue();
222+
}
189223
}

0 commit comments

Comments
 (0)