DispatchModelTest.php 3.37 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
<?php
/**
 * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
 */
namespace Temando\Shipping\Model;

use Magento\TestFramework\Helper\Bootstrap;

/**
 * Temando Dispatch Model Test
 *
 * @package  Temando\Shipping\Test\Integration
 * @author   Christoph Aßmann <christoph.assmann@netresearch.de>
 * @license  http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 * @link     http://www.temando.com/
 */
class DispatchModelTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @test
     */
    public function dataIsSetThroughConstructorArgument()
    {
        $dispatchId = '03df240e-969d-4549-bf10-ea7cd22f3070';
        $status = 'processing';
        $carrierName = 'UPS';
        $createdAtDate = '2017-03-03T04:35:42.022Z';
        $readyAtDate = '2017-01-01T00:00:01Z';
        $shipmentCount = 3;
        $documentation = [];

        /** @var Dispatch $dispatch */
        $dispatch = Bootstrap::getObjectManager()->create(Dispatch::class, ['data' => [
            Dispatch::DISPATCH_ID => $dispatchId,
            Dispatch::STATUS => $status,
            Dispatch::CARRIER_NAME => $carrierName,
            Dispatch::CREATED_AT_DATE => $createdAtDate,
            Dispatch::READY_AT_DATE => $readyAtDate,
            Dispatch::INCLUDED_SHIPMENTS => $shipmentCount,
            Dispatch::DOCUMENTATION => $documentation,
        ]]);

        $this->assertEquals($dispatchId, $dispatch->getDispatchId());
        $this->assertEquals($status, $dispatch->getStatus());
        $this->assertEquals($carrierName, $dispatch->getCarrierName());
        $this->assertEquals($createdAtDate, $dispatch->getCreatedAtDate());
        $this->assertEquals($readyAtDate, $dispatch->getReadyAtDate());
        $this->assertEquals($shipmentCount, $dispatch->getIncludedShipments());
        $this->assertEquals($documentation, $dispatch->getDocumentation());
    }

    /**
     * @test
     */
    public function dataIsSetThroughSetters()
    {
        $dispatchId = '03df240e-969d-4549-bf10-ea7cd22f3070';
        $status = 'processing';
        $carrierName = 'UPS';
        $createdAtDate = '2017-03-03T04:35:42.022Z';
        $readyAtDate = '2017-01-01T00:00:01Z';
        $shipmentCount = 3;
        $documentation = [];

        /** @var Dispatch $dispatch */
        $dispatch = Bootstrap::getObjectManager()->create(Dispatch::class);

        $this->assertEmpty($dispatch->getDispatchId());

        $dispatch->setData(Dispatch::DISPATCH_ID, $dispatchId);
        $this->assertEquals($dispatchId, $dispatch->getDispatchId());

        $dispatch->setData(Dispatch::STATUS, $status);
        $this->assertEquals($status, $dispatch->getStatus());

        $dispatch->setData(Dispatch::CARRIER_NAME, $carrierName);
        $this->assertEquals($carrierName, $dispatch->getCarrierName());

        $dispatch->setData(Dispatch::CREATED_AT_DATE, $createdAtDate);
        $this->assertEquals($createdAtDate, $dispatch->getCreatedAtDate());

        $dispatch->setData(Dispatch::READY_AT_DATE, $readyAtDate);
        $this->assertEquals($readyAtDate, $dispatch->getReadyAtDate());

        $dispatch->setData(Dispatch::INCLUDED_SHIPMENTS, $shipmentCount);
        $this->assertEquals($shipmentCount, $dispatch->getIncludedShipments());

        $dispatch->setData(Dispatch::DOCUMENTATION, $documentation);
        $this->assertEquals($documentation, $dispatch->getDocumentation());
    }
}