From 393c9a594635fe184d38045828c7cbbfa946a6ea Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Mon, 24 May 2021 14:42:23 +0200 Subject: [PATCH] Add more tests --- tests/Composer/Test/Json/JsonFileTest.php | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Composer/Test/Json/JsonFileTest.php b/tests/Composer/Test/Json/JsonFileTest.php index 3a19b2fe7..eb0646ae4 100644 --- a/tests/Composer/Test/Json/JsonFileTest.php +++ b/tests/Composer/Test/Json/JsonFileTest.php @@ -176,6 +176,34 @@ class JsonFileTest extends TestCase } $this->assertTrue($json->validateSchema(JsonFile::LAX_SCHEMA)); + file_put_contents($file, '{ "type": "library" }'); + try { + $json->validateSchema(); + $this->fail('Expected exception to be thrown (strict)'); + } catch (JsonValidationException $e) { + $this->assertEquals($expectedMessage, $e->getMessage()); + $errors = $e->getErrors(); + $this->assertContains('name : The property name is required', $errors); + $this->assertContains('description : The property description is required', $errors); + } + $this->assertTrue($json->validateSchema(JsonFile::LAX_SCHEMA)); + + file_put_contents($file, '{ "type": "project" }'); + try { + $json->validateSchema(); + $this->fail('Expected exception to be thrown (strict)'); + } catch (JsonValidationException $e) { + $this->assertEquals($expectedMessage, $e->getMessage()); + $errors = $e->getErrors(); + $this->assertContains('name : The property name is required', $errors); + $this->assertContains('description : The property description is required', $errors); + } + $this->assertTrue($json->validateSchema(JsonFile::LAX_SCHEMA)); + + file_put_contents($file, '{ "name": "vendor/package", "description": "generic description" }'); + $this->assertTrue($json->validateSchema()); + $this->assertTrue($json->validateSchema(JsonFile::LAX_SCHEMA)); + unlink($file); }