GraphQL\Tests\Type\ScalarSerializationTest::testSerializesOutputFloat PHP Метод

testSerializesOutputFloat() публичный Метод

    public function testSerializesOutputFloat()
    {
        $floatType = Type::float();
        $this->assertSame(1.0, $floatType->serialize(1));
        $this->assertSame(0.0, $floatType->serialize(0));
        $this->assertSame(123.5, $floatType->serialize('123.5'));
        $this->assertSame(-1.0, $floatType->serialize(-1));
        $this->assertSame(0.1, $floatType->serialize(0.1));
        $this->assertSame(1.1, $floatType->serialize(1.1));
        $this->assertSame(-1.1, $floatType->serialize(-1.1));
        $this->assertSame(-1.1, $floatType->serialize('-1.1'));
        try {
            $floatType->serialize('one');
            $this->fail('Expected exception was not thrown');
        } catch (InvariantViolation $e) {
            $this->assertEquals('Float cannot represent non numeric value: one', $e->getMessage());
        }
        try {
            $floatType->serialize('');
            $this->fail('Expected exception was not thrown');
        } catch (InvariantViolation $e) {
            $this->assertEquals('Float cannot represent non numeric value: (empty string)', $e->getMessage());
        }
        $this->assertSame(0.0, $floatType->serialize(false));
        $this->assertSame(1.0, $floatType->serialize(true));
    }