Skip to content

Commit

Permalink
Fixed the broken unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Oct 28, 2017
1 parent 567b331 commit 1ad99bc
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,41 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
*/
protected $orderStatusCollectionFactoryMock;

/**
* @var \Magento\Sales\Model\Order\Config|\PHPUnit_Framework_MockObject_MockObject
*/
protected $orderStatusFactoryMock;

/**
* @var \Magento\Sales\Model\Order\Status
*/
protected $orderStatusModel;

/**
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $storeManagerMock;

protected function setUp()
{
$orderStatusFactory = $this->createMock(\Magento\Sales\Model\Order\StatusFactory::class);
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
$this->orderStatusModel = $objectManager->getObject(\Magento\Sales\Model\Order\Status::class, [
'storeManager' => $this->storeManagerMock,
]);
$this->orderStatusFactoryMock = $this->getMockBuilder(\Magento\Sales\Model\Order\StatusFactory::class)
->setMethods(['load', 'create'])
->getMock();
$this->orderStatusCollectionFactoryMock = $this->createPartialMock(
\Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory::class,
['create']
);
$this->salesConfig = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
$this->salesConfig = $objectManager
->getObject(
\Magento\Sales\Model\Order\Config::class,
[
'orderStatusFactory' => $orderStatusFactory,
'orderStatusFactory' => $this->orderStatusFactoryMock,
'orderStatusCollectionFactory' => $this->orderStatusCollectionFactoryMock
]
);
Expand Down Expand Up @@ -147,6 +170,22 @@ public function testGetStatuses($state, $joinLabels, $collectionData, $expectedR
->method('joinStates')
->will($this->returnValue($collectionData));

$this->orderStatusFactoryMock->method('create')
->willReturnSelf();

$this->orderStatusFactoryMock->method('load')
->willReturn($this->orderStatusModel);

$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
$storeMock->method('getId')
->willReturn(1);

$this->storeManagerMock->method('getStore')
->with($this->anything())
->willReturn($storeMock);

$this->orderStatusModel->setData('store_labels', [1 => 'Pending label']);

$result = $this->salesConfig->getStateStatuses($state, $joinLabels);
$this->assertSame($expectedResult, $result);

Expand Down

0 comments on commit 1ad99bc

Please sign in to comment.