validate(); $this->assertEquals([], $securityScheme->getErrors()); $this->assertTrue($result); $this->assertEquals('http', $securityScheme->type); $this->assertEquals('basic', $securityScheme->scheme); /** @var $securityScheme SecurityScheme */ $securityScheme = Reader::readFromYaml(<<validate(); $this->assertEquals(['SecurityScheme is missing required property: type'], $securityScheme->getErrors()); $this->assertFalse($result); /** @var $securityScheme SecurityScheme */ $securityScheme = Reader::readFromYaml(<<validate(); $this->assertEquals([ 'SecurityScheme is missing required property: name', 'SecurityScheme is missing required property: in', ], $securityScheme->getErrors()); $this->assertFalse($result); /** @var $securityScheme SecurityScheme */ $securityScheme = Reader::readFromYaml(<<validate(); $this->assertEquals([ 'SecurityScheme is missing required property: scheme', ], $securityScheme->getErrors()); $this->assertFalse($result); /** @var $securityScheme SecurityScheme */ $securityScheme = Reader::readFromYaml(<<validate(); $this->assertEquals([ 'SecurityScheme is missing required property: flows', ], $securityScheme->getErrors()); $this->assertFalse($result); /** @var $securityScheme SecurityScheme */ $securityScheme = Reader::readFromYaml(<<validate(); $this->assertEquals([ 'SecurityScheme is missing required property: openIdConnectUrl', ], $securityScheme->getErrors()); $this->assertFalse($result); } public function testOAuth2() { /** @var $securityScheme SecurityScheme */ $securityScheme = Reader::readFromYaml(<<validate(); $this->assertEquals([ 'OAuthFlow is missing required property: scopes', ], $securityScheme->getErrors()); $this->assertFalse($result); /** @var $securityScheme SecurityScheme */ $securityScheme = Reader::readFromYaml(<<validate(); $this->assertEquals([], $securityScheme->getErrors()); $this->assertTrue($result); $this->assertInstanceOf(OAuthFlows::class, $securityScheme->flows); $this->assertInstanceOf(OAuthFlow::class, $securityScheme->flows->implicit); $this->assertInstanceOf(OAuthFlow::class, $securityScheme->flows->authorizationCode); $this->assertNull($securityScheme->flows->clientCredentials); $this->assertNull($securityScheme->flows->password); $this->assertEquals('https://example.com/api/oauth/dialog', $securityScheme->flows->implicit->authorizationUrl); $this->assertEquals([ 'write:pets' => 'modify pets in your account', 'read:pets' => 'read your pets', ], $securityScheme->flows->implicit->scopes); } public function testSecurityRequirement() { /** @var $securityRequirement SecurityRequirement */ $securityRequirement = Reader::readFromYaml(<<validate(); $this->assertEquals([], $securityRequirement->getErrors()); $this->assertTrue($result); $this->assertSame([], $securityRequirement->api_key); /** @var $securityRequirement SecurityRequirement */ $securityRequirement = Reader::readFromYaml(<<validate(); $this->assertEquals([], $securityRequirement->getErrors()); $this->assertTrue($result); $this->assertSame(['write:pets', 'read:pets'], $securityRequirement->petstore_auth); } public function testDefaultSecurity() { $openapi = Reader::readFromYaml(<<assertSame([], $openapi->paths->getPath('/path/one')->post->security); $this->assertSame(null, $openapi->paths->getPath('/path/two')->post->security); $this->assertCount(1, $openapi->security); $this->assertSame([], $openapi->security[0]->Bearer); } }