123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- /**
- * File PathTest.php
- *
- * @author Edward Pfremmer <epfremme@nerdery.com>
- */
- namespace Epfremme\Swagger\Tests\Entity;
- use Doctrine\Common\Collections\ArrayCollection;
- use Epfremme\Swagger\Entity\Operation;
- use Epfremme\Swagger\Entity\Parameters;
- use Epfremme\Swagger\Entity\Path;
- use Epfremme\Swagger\Tests\Mixin\SerializerContextTrait;
- /**
- * Class PathTest
- *
- * @package Epfremme\Swagger
- * @subpackage Tests\Entity
- */
- class PathTest extends \PHPUnit_Framework_TestCase
- {
- use SerializerContextTrait;
- /**
- * @var Path
- */
- protected $path;
- /**
- * {@inheritdoc}
- */
- protected function setUp()
- {
- $this->path = new Path();
- }
-
- /**
- * @covers Epfremme\Swagger\Entity\Path::getOperations
- * @covers Epfremme\Swagger\Entity\Path::setOperations
- */
- public function testOperations()
- {
- $operations = new ArrayCollection([
- 'foo' => new Operation(),
- 'bar' => new Operation(),
- 'baz' => new Operation(),
- ]);
- $this->assertClassHasAttribute('operations', Path::class);
- $this->assertInstanceOf(Path::class, $this->path->setOperations($operations));
- $this->assertAttributeInstanceOf(ArrayCollection::class, 'operations', $this->path);
- $this->assertAttributeEquals($operations, 'operations', $this->path);
- $this->assertEquals($operations, $this->path->getOperations());
- $this->assertContainsOnlyInstancesOf(Operation::class, $this->path->getOperations());
- }
- /**
- * @covers Epfremme\Swagger\Entity\Path
- */
- public function testSerialize()
- {
- $data = json_encode([
- 'get' => [
- 'summary' => 'foo',
- 'description' => 'bar',
- 'responses' => [
- '200' => [
- 'description' => 'Pet updated.'
- ],
- '405' => [
- 'description' => 'Invalid input'
- ]
- ],
- 'schemes' => ['http', 'https'],
- 'security' => [
- [
- 'petstore_auth' => [
- 'read:pets',
- ]
- ]
- ],
- 'deprecated' => false,
- ],
- 'post' => [
- 'tags' => [
- 'foo'
- ],
- 'summary' => 'foo',
- 'description' => 'bar',
- 'externalDocs' => (object)[],
- 'operationId' => 'baz',
- 'consumes' => [
- 'application/x-www-form-urlencoded'
- ],
- 'produces' => [
- 'application/json',
- 'application/xml'
- ],
- 'parameters' => [
- [
- 'name' => 'petId',
- 'in' => Parameters\AbstractParameter::IN_PATH,
- 'description' => 'ID of pet that needs to be updated',
- 'required' => true,
- 'type' => Parameters\AbstractTypedParameter::STRING_TYPE
- ],
- [
- 'name' => 'name',
- 'in' => Parameters\AbstractParameter::IN_FORM_DATA,
- 'description' => 'Updated name of the pet',
- 'required' => false,
- 'type' => Parameters\AbstractTypedParameter::STRING_TYPE
- ],
- [
- 'name' => 'status',
- 'in' => Parameters\AbstractParameter::IN_FORM_DATA,
- 'description' => 'Updated status of the pet',
- 'required' => false,
- 'type' => Parameters\AbstractTypedParameter::STRING_TYPE
- ]
- ],
- 'responses' => [
- '200' => [
- 'description' => 'Pet updated.'
- ],
- '405' => [
- 'description' => 'Invalid input'
- ]
- ],
- 'schemes' => ['http', 'https'],
- 'security' => [
- [
- 'petstore_auth' => [
- 'read:pets',
- ]
- ]
- ],
- 'deprecated' => true,
- ],
- ]);
- $path = $this->getSerializer()->deserialize($data, Path::class, 'json');
- $this->assertInstanceOf(Path::class, $path);
- $this->assertAttributeInstanceOf(ArrayCollection::class, 'operations', $path);
- $this->assertAttributeContainsOnly(Operation::class, 'operations', $path);
- $json = $this->getSerializer()->serialize($path, 'json');
- $this->assertJson($json);
- $this->assertJsonStringEqualsJsonString($data, $json);
- }
- }
|