From b1aa87b83b7719cf541960f499a21e0f57efaf8b Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Thu, 4 Apr 2019 12:01:58 +0200 Subject: [PATCH] Use a data provider for testInvalidTypes --- tests/InvalidTypesTest.php | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/tests/InvalidTypesTest.php b/tests/InvalidTypesTest.php index 8a2ab36..573edcf 100644 --- a/tests/InvalidTypesTest.php +++ b/tests/InvalidTypesTest.php @@ -10,40 +10,28 @@ class InvalidTypesTest extends TestCase { - public function testInvalidTypeDateTime() : void - { - $this->expectException(InvalidTypeException::class); - $this->expectExceptionMessage('Type "dateTime" is not a valid type.'); - - $schema = (object) [ - 'type' => 'dateTime' - ]; - - Convert::openapiSchemaToJsonSchema($schema); - } - - public function testInvalidTypeFoo() : void + /** + * @dataProvider providerInvalidTypes + */ + public function testInvalidTypes($type) : void { $this->expectException(InvalidTypeException::class); - $this->expectExceptionMessage('Type "foo" is not a valid type.'); + $this->expectExceptionMessage('Type ' . json_encode($type) . ' is not a valid type.'); $schema = (object) [ - 'type' => 'foo' + 'type' => $type ]; Convert::openapiSchemaToJsonSchema($schema); } - public function testInvalidTypeNotAsString() : void + public function providerInvalidTypes() : array { - $this->expectException(InvalidTypeException::class); - $this->expectExceptionMessage('Type ["string",null] is not a valid type.'); - - $schema = (object) [ - 'type' => ['string', null] + return [ + ['dateTime'], + ['foo'], + [['string', null]], // 'null' should be a string ]; - - Convert::openapiSchemaToJsonSchema($schema); } public function testInvalidTypeInsideComplexSchema() : void