Bitpay\ItemTest::testBadStringPrice PHP Method

testBadStringPrice() public method

public testBadStringPrice ( )
    public function testBadStringPrice()
    {
        // Accepts standard integer string
        $this->item->setPrice("456");
        $this->assertSame(456.0, $this->item->getPrice());
        // Accepts float string without leading integer
        $this->item->setPrice(".99");
        $this->assertSame(0.99, $this->item->getPrice());
        $this->item->setPrice(".0");
        $this->assertSame(0.0, $this->item->getPrice());
        // Accepts float string without decimal numbers
        $this->item->setPrice("9.");
        $this->assertSame(9.0, $this->item->getPrice());
        // Arbitrary precision
        $this->item->setPrice("9.4329082");
        $this->assertSame(9.4329082, $this->item->getPrice());
        // Try with different locale
        setlocale(LC_NUMERIC, 'it_IT');
        // Accepts floats
        $this->item->setPrice(9.99);
        $this->assertSame(9.99, $this->item->getPrice());
        // Accepts integers
        $this->item->setPrice(9);
        $this->assertSame(9.0, $this->item->getPrice());
        // Accepts standard float string
        $this->item->setPrice("9.99");
        $this->assertSame(9.99, $this->item->getPrice());
        // Accepts standard integer string
        $this->item->setPrice("456");
        $this->assertSame(456.0, $this->item->getPrice());
        // Accepts float string without leading integer
        $this->item->setPrice(".99");
        $this->assertSame(0.99, $this->item->getPrice());
        $this->item->setPrice(".0");
        $this->assertSame(0.0, $this->item->getPrice());
        // Accepts float string without decimal numbers
        $this->item->setPrice("9.");
        $this->assertSame(9.0, $this->item->getPrice());
        // Arbitrary precision
        $this->item->setPrice("9.4329082");
        $this->assertSame(9.4329082, $this->item->getPrice());
        setlocale(LC_NUMERIC, 'en_US');
    }