getName() public method

public getName ( )
Exemplo n.º 1
0
 /**
  * @param Field                 $intField
  * @param Field                 $objField
  * @param AbstractInterfaceType $interface
  *
  * @return bool
  *
  * @throws ConfigurationException
  */
 protected function assertFieldsIdentical($intField, $objField, AbstractInterfaceType $interface)
 {
     $isValid = true;
     if ($intField->getType()->isCompositeType() !== $objField->getType()->isCompositeType()) {
         $isValid = false;
     }
     if ($intField->getType()->getNamedType()->getName() != $objField->getType()->getNamedType()->getName()) {
         $isValid = false;
     }
     if (!$isValid) {
         throw new ConfigurationException(sprintf('Implementation of %s is invalid for the field %s', $interface->getName(), $objField->getName()));
     }
 }
 public function testAddField()
 {
     $fieldsData = ['id' => ['type' => new IntType()]];
     $config = new ObjectTypeConfig(['name' => 'UserType', 'fields' => $fieldsData]);
     $this->assertTrue($config->hasFields());
     $idField = new Field(['name' => 'id', 'type' => new IntType()]);
     $idField->getName();
     $nameField = new Field(['name' => 'name', 'type' => new StringType()]);
     $this->assertEquals(['id' => $idField], $config->getFields());
     $config->addField($nameField);
     $this->assertEquals(['id' => $idField, 'name' => $nameField], $config->getFields());
     $config->removeField('id');
     $this->assertEquals(['name' => $nameField], $config->getFields());
     $config->addFields(['id' => $idField]);
     $this->assertEquals(['name' => $nameField, 'id' => $idField], $config->getFields());
     $levelField = new Field(['name' => 'level', 'type' => new IntType()]);
     $config->addFields([$levelField]);
     $this->assertEquals(['name' => $nameField, 'id' => $idField, 'level' => $levelField], $config->getFields());
 }
Exemplo n.º 3
0
 public function testInterfaceMethods()
 {
     $interface = new TestInterfaceType();
     $this->assertEquals($interface->getNamedType(), $interface->getType());
     $nameField = new Field(['name' => 'name', 'type' => new StringType()]);
     $nameField->getName();
     $this->assertEquals(['name' => $nameField], $interface->getFields());
     $object = new ObjectType(['name' => 'Test', 'fields' => ['name' => new StringType()], 'interfaces' => [$interface]]);
     $this->assertEquals([$interface], $object->getInterfaces());
     $this->assertTrue($interface->isValidValue($object));
     $this->assertFalse($interface->isValidValue('invalid object'));
     $this->assertEquals($interface->serialize($object), $object);
     $interfaceType = new InterfaceType(['name' => 'UserInterface', 'fields' => ['name' => new StringType()], 'resolveType' => function ($object) {
         return $object;
     }]);
     $this->assertEquals('UserInterface', $interfaceType->getName());
     $this->assertEquals($object, $interfaceType->resolveType($object));
     $this->assertTrue($interfaceType->isValidValue($object));
     $this->assertFalse($interfaceType->isValidValue('invalid object'));
 }