Sonata\Tests\InvoiceBundle\Entity\BaseInvoiceTest::testInvoiceElementsVatAmounts PHP Method

testInvoiceElementsVatAmounts() public method

    public function testInvoiceElementsVatAmounts()
    {
        $invoice = new InvoiceTest();
        $element1 = $this->getMockBuilder('Sonata\\InvoiceBundle\\Entity\\BaseInvoiceElement')->getMock();
        $element1->expects($this->any())->method('getVatRate')->will($this->returnValue(20));
        $element1->expects($this->any())->method('getVatAmount')->will($this->returnValue(3));
        $element2 = $this->getMockBuilder('Sonata\\InvoiceBundle\\Entity\\BaseInvoiceElement')->getMock();
        $element2->expects($this->any())->method('getVatRate')->will($this->returnValue(10));
        $element2->expects($this->any())->method('getVatAmount')->will($this->returnValue(2));
        $element3 = $this->getMockBuilder('Sonata\\BasketBundle\\Entity\\BaseBasketElement')->getMock();
        $element3->expects($this->any())->method('getProduct')->will($this->returnValue($this->getMockBuilder('Sonata\\ProductBundle\\Entity\\BaseProduct')->getMock()));
        $element3->expects($this->any())->method('getVatRate')->will($this->returnValue(10));
        $element3->expects($this->any())->method('getVatAmount')->will($this->returnValue(5));
        $invoice->setInvoiceElements(array($element1, $element2, $element3));
        $items = $invoice->getVatAmounts();
        $this->assertTrue(is_array($items), 'Should return an array');
        foreach ($items as $item) {
            $this->assertArrayHasKey('rate', $item, 'Array items should contains a "rate" key');
            $this->assertArrayHasKey('amount', $item, 'Array items should contains a "amount" key');
            $this->assertTrue(in_array($item['rate'], array(10, 20)));
            $this->assertTrue(in_array($item['amount'], array(7, 3)));
        }
    }