/** * @dataProvider formatProvider */ public function testFormatsJson($def, $args, $result) { $j = new JsonBody(new Service([], function () { return []; })); $shape = Shape::create($def, new ShapeMap([])); $this->assertEquals($result, $j->build($shape, $args)); }
public function testCreatesNestedShapeReferences() { $s = Shape::create(['shape' => 'bar'], new ShapeMap(['bar' => ['type' => 'float']])); $this->assertInstanceOf('Vws\\Api\\Shape', $s); $this->assertEquals('float', $s->getType()); $this->assertEquals(false, $s->getMin()); $this->assertEquals(false, $s->getMax()); $this->assertEquals(false, $s->getPattern()); }
/** * @dataProvider validationProvider */ public function testValidatesInput($shape, $input, $result) { $shape = Shape::create($shape, new ShapeMap([])); $validator = new Validator(); try { call_user_func($validator, 'Foo', $shape, $input); if ($result !== true) { $this->fail('Should have failed with ' . $result); } } catch (\InvalidArgumentException $e) { if ($result === true) { throw $e; } else { $this->assertEquals($result, $e->getMessage()); } } }
protected function shapeFor(array $definition) { return isset($definition['shape']) ? $this->shapeMap->resolve($definition) : Shape::create($definition, $this->shapeMap); }