<?php

/**
 * Created by PhpStorm.
 * User: ondra
 * Date: 2.1.18
 * Time: 12:39.
 */

namespace KupShop\OrderingBundle\Tests;

use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\OrderingBundle\Util\Order\OrderItemInfo;

class OrderItemInfoTest extends \DatabaseTestCase
{
    /** @var OrderItemInfo */
    private $orderItemInfo;

    public function setUp(): void
    {
        parent::setUp();

        $this->orderItemInfo = ServiceContainer::getService(OrderItemInfo::class);
    }

    public function testGetItemInfo()
    {
        $order = new \Order();
        $order->createFromDB(10);

        $types = [];
        foreach ($order->fetchItems() as $item) {
            $types[$item['id']] = $this->orderItemInfo->getItemType($item);
        }

        $this->assertEquals([
            20 => OrderItemInfo::TYPE_DELIVERY,
            21 => OrderItemInfo::TYPE_GIFT,
            22 => OrderItemInfo::TYPE_PRODUCT,
            23 => OrderItemInfo::TYPE_DISCOUNT,
            24 => OrderItemInfo::TYPE_PRODUCT,
        ], $types);
    }

    public function getDataSet()
    {
        return $this->getJsonDataSetFromFile();
    }
}
