<?php
/*
 * PSX is an open source PHP framework to develop RESTful APIs.
 * For the current version and information visit <https://phpsx.org>
 *
 * Copyright 2010-2022 Christoph Kappestein <christoph.kappestein@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace PSX\Api\Tests\Resource;

use PHPUnit\Framework\TestCase;
use PSX\Api\Resource\Factory;

/**
 * MethodAbstractTest
 *
 * @author  Christoph Kappestein <christoph.kappestein@gmail.com>
 * @license http://www.apache.org/licenses/LICENSE-2.0
 * @link    https://phpsx.org
 */
class MethodAbstractTest extends TestCase
{
    public function testMethod()
    {
        $method = Factory::getMethod('POST');
        $method->setDescription('foobar');
        $method->setQueryParameters('GetQuery');
        $method->setRequest('Request');
        $method->addResponse(200, 'Response');
        $method->setTags(['Foo']);

        $this->assertEquals('foobar', $method->getDescription());
        $this->assertEquals('GetQuery', $method->getQueryParameters());
        $this->assertTrue($method->hasRequest());
        $this->assertEquals('Request', $method->getRequest());
        $this->assertEquals('Response', $method->getResponse(200));
        $this->assertTrue($method->hasResponse(200));
        $this->assertFalse($method->hasResponse(201));
        $this->assertTrue($method->hasQueryParameters());
        $this->assertIsArray($method->getTags());
        $this->assertEquals('Foo', current($method->getTags()));
    }

    public function testGetResponseInvalid()
    {
        $this->expectException(\RuntimeException::class);

        Factory::getMethod('POST')->getResponse(500);
    }
}
