/** * @param Schema $schema * @param Property $property * @param string $operationType * @return Operation */ public static function factory(Schema $schema, Property $property, $operationType) { $operation = new self(); $operation->setType($operationType); $operation->setSchema($schema); $operation->setPath($property->getPath()); $operation->setValue($property->getValue()); return $operation; }
public function test_Escaping_Tilde() { $property = new Property(); $property->setName('~foo'); $operation = new Operation(); $operation->setPath($property->getPath()); $operation->setType(OperationType::REPLACE); $operation->setValue('bar~baz~'); $encoded = Encoder::encode(array($operation)); $this->assertEquals('[{"op": "replace", "path": "/~0foo", "value": "bar~0baz~0"}]', $encoded); }
public function test_Deciding_Operation_Type() { $json1 = '{"properties": {"foo": {"type": "string"}, "baz": {"type": "string"}}}'; $schema1 = Schema::factory(json_decode($json1, true)); $property1 = Property::factory(array('type' => 'string', 'name' => 'foo')); $this->assertEquals(OperationType::REPLACE, $schema1->decideOperationType($property1)); $property2 = Property::factory(array('type' => 'string', 'name' => 'username')); $this->assertEquals(OperationType::ADD, $schema1->decideOperationType($property2)); }
public function test_Factory() { $schema = Schema::factory($this->getSchemaData()); $property = Property::factory($this->getPropertyData()); $operation = Operation::factory($schema, $property, OperationType::REPLACE); $this->assertEquals($schema, $operation->getSchema()); $this->assertEquals($property->getPath(), $operation->getPath()); $this->assertEquals($property->getValue(), $operation->getValue()); }
/** * Based on this schema, decide the most appropriate operation type for a given property * * @param Property $property The property being performed on * @return string */ public function decideOperationType(Property $property) { $name = $property->getName(); return $this->propertyExists($name) ? OperationType::REPLACE : OperationType::ADD; }
public function test_Get_Path() { $data = $this->getData(); unset($data['enum'], $data['pattern']); $property = Property::factory($data); $this->assertEquals('/id', $property->getPath()); }