예제 #1
0
 /**
  * build instance of Expected by $modelId
  *
  * @param string $modelId
  * @param bool $onlyRequired
  * @param bool $firstCollection
  * @return Expected
  * @throws AnnotationException
  */
 public function buildExpectedByModelId($modelId, $onlyRequired, $firstCollection = false)
 {
     if (!$this->exists('id', $modelId)) {
         $url = Annotation::$url;
         $httpMethod = Annotation::$httpMethod;
         throw new AnnotationException("specified SWG\\Model is not written in your doc. httpMethod: {$httpMethod}, url: {$url}, modelId: {$modelId}");
     }
     $expected = new Expected();
     foreach ($this->pick('id', $modelId)->properties($onlyRequired)->getCollection() as $property) {
         /* @var $property \SwaggerAssert\Annotation\Resources\Resource\Models\Model\Properties\Property */
         if ($property->hasRef()) {
             $expected->push($property->key(), $this->buildExpectedByModelId($property->refModelId(), $onlyRequired));
             continue;
         }
         if ($property->hasItemsRef()) {
             $expected->push('collection', $this->buildExpectedByModelId($property->itemsRefModelId(), $onlyRequired));
             continue;
         }
         $expected->push($property->key());
     }
     if ($firstCollection) {
         $collectionExpected = new Expected();
         $collectionExpected->push('collection', $expected);
         return $collectionExpected;
     }
     return $expected;
 }
예제 #2
0
 /**
  * @test
  */
 public function collectionCase()
 {
     $expected = new Expected();
     $expected->push('collection', new Expected('A'));
     $actual = new Expected();
     $actual->push('collection', new Actual('A'));
     $picker = $this->createPickerMock($expected, $actual);
     $subject = new CompareResponseAndAnnotation($picker);
     $this->assertTrue($subject->execute());
 }
예제 #3
0
 /**
  * @test
  * @expectedException \SwaggerAssert\Exception\CompareException
  */
 public function tooManyExpectedKey()
 {
     $expected = new Expected();
     $expected->push('a');
     $expected->push('b');
     $expected->push('c');
     $actual = new Actual();
     $actual->push('a');
     $actual->push('b');
     $picker = $this->createPickerMock($expected, $actual);
     $subject = new CompareResponseAndAnnotation($picker);
     $subject->execute();
 }