forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Artem Kirkor
committed
Aug 4, 2022
1 parent
00e33ad
commit 89d9691
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
app/code/Magento/SalesGraphQl/Test/Unit/Model/Resolver/OrdersTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\SalesGraphQl\Test\Unit\Model\Resolver; | ||
|
||
use Magento\GraphQl\Model\Query\ContextInterface; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface; | ||
use Magento\SalesGraphQl\Model\Resolver\Orders; | ||
use Magento\Sales\Model\ResourceModel\Order\Collection; | ||
use Magento\Sales\Model\Order; | ||
|
||
class OrdersTest extends TestCase | ||
{ | ||
/** | ||
* @var Orders | ||
*/ | ||
private $resolver; | ||
|
||
/** | ||
* @var ContextInterface|MockObject | ||
*/ | ||
private $contextMock; | ||
|
||
/** | ||
* @var CollectionFactoryInterface|MockObject | ||
*/ | ||
private $collectionFactoryInterfaceMock; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->contextMock = $this->createMock(ContextInterface::class); | ||
|
||
$this->collectionFactoryInterfaceMock = $this->getMockBuilder(CollectionFactoryInterface::class) | ||
->getMock(); | ||
|
||
$this->resolver = new Orders( | ||
$this->collectionFactoryInterfaceMock, | ||
); | ||
} | ||
|
||
public function testResolve(): void | ||
{ | ||
$collectionMock = $this->getMockBuilder(Collection::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$orderMock = $this->createMock(Order::class); | ||
|
||
$collectionMock->method('getIterator') | ||
->willReturn(new \ArrayObject([$orderMock])); | ||
|
||
$this->contextMock | ||
->method('getUserId') | ||
->willReturn(1); | ||
|
||
$this->collectionFactoryInterfaceMock | ||
->method('create') | ||
->willReturn($collectionMock); | ||
|
||
$result = $this->resolver->resolve( | ||
$this->getFieldStub(), | ||
$this->contextMock, | ||
$this->getResolveInfoStub(), | ||
null | ||
); | ||
|
||
$this->assertIsArray($result); | ||
$assertKeys = [ | ||
'id', | ||
'increment_id', | ||
'order_number', | ||
'created_at', | ||
'grand_total', | ||
'status', | ||
'model' | ||
]; | ||
foreach ($assertKeys as $key) { | ||
$this->assertArrayHasKey($key, current($result['items'])); | ||
} | ||
$this->assertEquals($orderMock, current($result['items'])['model']); | ||
} | ||
|
||
/** | ||
* @return MockObject|Field | ||
*/ | ||
private function getFieldStub(): Field | ||
{ | ||
return $this->createMock(Field::class); | ||
} | ||
|
||
/** | ||
* @return MockObject|ResolveInfo | ||
*/ | ||
private function getResolveInfoStub(): ResolveInfo | ||
{ | ||
/** @var MockObject|ResolveInfo $resolveInfoMock */ | ||
return $this->createMock(ResolveInfo::class); | ||
} | ||
} |