public static function isScalarType($type) { if (is_object($type)) { return $type instanceof AbstractScalarType || $type instanceof AbstractEnumType; } return in_array(strtolower($type), TypeFactory::getScalarTypesNames()); }
public function testScalarPrimitives() { foreach (TypeFactory::getScalarTypesNames() as $typeName) { $scalarType = TypeFactory::getScalarType($typeName); $testDataMethod = 'get' . $typeName . 'TestData'; $this->assertNotEmpty($scalarType->getDescription()); $this->assertEquals($scalarType->getKind(), TypeMap::KIND_SCALAR); $this->assertEquals($scalarType->isCompositeType(), false); $this->assertEquals(TypeService::isAbstractType($scalarType), false); $this->assertEquals($scalarType->getType(), $scalarType); $this->assertEquals($scalarType->getType(), $scalarType->getNamedType()); $this->assertNull($scalarType->getConfig()); foreach (call_user_func(['Youshido\\Tests\\DataProvider\\TestScalarDataProvider', $testDataMethod]) as list($data, $serialized, $isValid)) { $this->assertSerialization($scalarType, $data, $serialized); $this->assertParse($scalarType, $data, $serialized); if ($isValid) { $this->assertTrue($scalarType->isValidValue($data), $typeName . ' validation for :' . serialize($data)); } else { $this->assertFalse($scalarType->isValidValue($data), $typeName . ' validation for :' . serialize($data)); } } } try { TypeFactory::getScalarType('invalid type'); } catch (\Exception $e) { $this->assertEquals('Configuration problem with type invalid type', $e->getMessage()); } $this->assertEquals('String', (string) new StringType()); }