Beispiel #1
0
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     $this->title = $data->get('title');
     $this->discriminator = $data->get('discriminator');
     $this->readOnly = $data->has('readOnly') && $data->get('readOnly');
     $this->example = $data->get('example');
     $this->required = $data->get('required');
     $this->properties = new Definitions($data->get('properties'));
     if ($data->has('additionalProperties')) {
         $this->additionalProperties = new self($data->get('additionalProperties'));
     }
     $this->allOf = new ArrayList();
     if ($data->has('allOf')) {
         foreach ($data->get('allOf') as $schema) {
             $this->allOf->add(new self($schema));
         }
     }
     // parts
     $this->parseRef($data);
     $this->parseType($data);
     $this->parseDescription($data);
     $this->parseItems($data);
     $this->parseExternalDocs($data);
     $this->parseExtensions($data);
 }
Beispiel #2
0
 public function testDefaultPropertyComparator()
 {
     $list = new ArrayList();
     $list->add(PhpProperty::create('arr')->setVisibility(PhpProperty::VISIBILITY_PRIVATE));
     $list->add(PhpProperty::create('bar')->setVisibility(PhpProperty::VISIBILITY_PROTECTED));
     $list->add(PhpProperty::create('foo'));
     $list->add(PhpProperty::create('baz'));
     $list->sort(new DefaultPropertyComparator());
     $ordered = $list->map(function ($item) {
         return $item->getName();
     })->toArray();
     $this->assertEquals(['baz', 'foo', 'bar', 'arr'], $ordered);
 }
 /**
  * Recursively transforms data into a list (on the first level, deeper levels
  * transformed to an appropriate collection) (experimental API)
  *
  * @param array|Iterator $collection
  * @return ArrayList
  */
 public static function toList($collection)
 {
     $list = new ArrayList();
     foreach ($collection as $v) {
         $list->add(self::toCollection($v));
     }
     return $list;
 }
 public function testGroupStack()
 {
     $log = new ArrayList();
     $listener = function (GroupEvent $event) use($log) {
         $log->add($event->getName() . ' ' . $event->getGroup()->type);
     };
     $parser = new Parser();
     $parser->getContext()->addListener(Context::EVENT_GROUP_ENTER, $listener);
     $parser->getContext()->addListener(Context::EVENT_GROUP_LEAVE, $listener);
     $parser->parse($this->getCode());
     $this->assertEquals(['context.group_enter block', 'context.group_leave block', 'context.group_enter block', 'context.group_leave block', 'context.group_enter call', 'context.group_leave call', 'context.group_enter block', 'context.group_leave block', 'context.group_enter block', 'context.group_enter group', 'context.group_leave group', 'context.group_leave block'], $log->toArray());
 }
 public function testSize()
 {
     $list = new ArrayList();
     $this->assertTrue($list->isEmpty());
     $this->assertEquals(0, $list->size());
     $list->add('item 1')->add('item 2');
     $this->assertFalse($list->isEmpty());
     $this->assertEquals(2, $list->size());
     $list->clear();
     $this->assertTrue($list->isEmpty());
     $this->assertEquals(0, $list->size());
     $list = new ArrayList(['item 1', 'item 2']);
     $this->assertFalse($list->isEmpty());
     $this->assertEquals(2, $list->size());
 }
Beispiel #6
0
 public function testSortAndReverse()
 {
     $unsorted = [5, 2, 8, 3, 9, 4, 6, 1, 7, 10];
     $list = new ArrayList($unsorted);
     $this->assertEquals([10, 7, 1, 6, 4, 9, 3, 8, 2, 5], $list->reverse()->toArray());
     $this->assertEquals(range(1, 10), $list->sort()->toArray());
     $list = new ArrayList($unsorted);
     $this->assertEquals(range(10, 1), $list->reverseSort()->toArray());
     $list = new ArrayList($unsorted);
     $cmp = function ($a, $b) {
         if ($a == $b) {
             return 0;
         }
         return $a < $b ? -1 : 1;
     };
     $this->assertEquals(range(1, 10), $list->sort($cmp)->toArray());
     $items = ['x', 'c', 'a', 't', 'm'];
     $list = new ArrayList();
     foreach ($items as $item) {
         $list->add(new Item($item));
     }
     $list->sort(new ComparableComparator());
     $this->assertEquals(['a', 'c', 'm', 't', 'x'], $list->map(function ($item) {
         return $item->getContent();
     })->toArray());
 }