Skip to content

Commit 12ecbb3

Browse files
committed
31606:Fixed static test failure
1 parent 5e74597 commit 12ecbb3

File tree

4 files changed

+110
-61
lines changed

4 files changed

+110
-61
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Magento\Sales\Test\Fixture;
4+
5+
use Magento\Framework\DataObject;
6+
use Magento\Sales\Api\Data\CommentInterface;
7+
use Magento\Sales\Api\Data\EntityInterface;
8+
use Magento\Sales\Api\Data\InvoiceCommentInterface;
9+
use Magento\Sales\Api\InvoiceCommentRepositoryInterface;
10+
use Magento\TestFramework\Fixture\Api\ServiceFactory;
11+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
12+
13+
class InvoiceComment implements RevertibleDataFixtureInterface
14+
{
15+
private const DEFAULT_DATA = [
16+
InvoiceCommentInterface::IS_CUSTOMER_NOTIFIED => 0,
17+
InvoiceCommentInterface::PARENT_ID => 0,
18+
CommentInterface::COMMENT => 'Test Comment',
19+
CommentInterface::IS_VISIBLE_ON_FRONT => 0,
20+
EntityInterface::ENTITY_ID => 0,
21+
EntityInterface::CREATED_AT => "0000-00-00 00:00:00",
22+
];
23+
24+
/**
25+
* @var ServiceFactory
26+
*/
27+
private $serviceFactory;
28+
29+
/**
30+
* @var InvoiceCommentRepositoryInterface
31+
*/
32+
private $invoiceCommentRepository;
33+
34+
/**
35+
* @param ServiceFactory $serviceFactory
36+
* @param InvoiceCommentRepositoryInterface $invoiceCommentRepository
37+
*/
38+
public function __construct(
39+
ServiceFactory $serviceFactory,
40+
InvoiceCommentRepositoryInterface $invoiceCommentRepository
41+
) {
42+
$this->serviceFactory = $serviceFactory;
43+
$this->invoiceCommentRepository = $invoiceCommentRepository;
44+
}
45+
46+
public function apply(array $data = []): ?DataObject
47+
{
48+
$service = $this->serviceFactory->create(InvoiceCommentRepositoryInterface::class, 'save');
49+
50+
$invoiceCommentId = $service->execute($this->prepareData($data));
51+
52+
return $this->invoiceCommentRepository->get($invoiceCommentId->getId());
53+
}
54+
55+
public function revert(DataObject $data): void
56+
{
57+
$invoice = $this->invoiceCommentRepository->get($data->getId());
58+
$this->invoiceCommentRepository->delete($invoice);
59+
}
60+
61+
/**
62+
* Prepare invoice data
63+
*
64+
* @param array $data
65+
* @return array
66+
*/
67+
private function prepareData(array $data): array
68+
{
69+
$data['entity'] = array_merge(self::DEFAULT_DATA, $data);
70+
71+
return $data;
72+
}
73+
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/InvoiceTest.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@
77

88
namespace Magento\GraphQl\Sales;
99

10+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
11+
use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture;
12+
use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture;
13+
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
14+
use Magento\Checkout\Test\Fixture\SetGuestEmail as SetGuestEmailFixture;
15+
use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture;
16+
use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddressFixture;
17+
use Magento\Customer\Test\Fixture\Customer;
1018
use Magento\Framework\Registry;
19+
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
20+
use Magento\Quote\Test\Fixture\CustomerCart;
21+
use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
1122
use Magento\Sales\Api\OrderRepositoryInterface;
1223
use Magento\Sales\Model\ResourceModel\Order\Collection;
24+
use Magento\Sales\Test\Fixture\Invoice as InvoiceFixture;
25+
use Magento\Sales\Test\Fixture\InvoiceComment as InvoiceCommentFixture ;
26+
use Magento\TestFramework\Fixture\DataFixture;
1327
use Magento\TestFramework\Helper\Bootstrap;
1428
use Magento\TestFramework\TestCase\GraphQlAbstract;
1529
use Magento\GraphQl\GetCustomerAuthenticationHeader;
@@ -410,9 +424,29 @@ public function testPartialInvoiceForCustomerWithTaxesAndDiscounts()
410424
$this->deleteOrder();
411425
}
412426

413-
/**
414-
* @magentoApiDataFixture Magento/Sales/_files/customer_invoice_comments_for_search.php
415-
*/
427+
#[
428+
DataFixture(Customer::class, ['email' => 'customer@search.example.com'], as: 'customer'),
429+
DataFixture(ProductFixture::class, as: 'product'),
430+
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'cart'),
431+
DataFixture(AddProductToCartFixture::class, ['cart_id' => '$cart.id$', 'product_id' => '$product.id$']),
432+
DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$cart.id$']),
433+
DataFixture(SetShippingAddressFixture::class, ['cart_id' => '$cart.id$']),
434+
DataFixture(SetGuestEmailFixture::class, ['cart_id' => '$cart.id$']),
435+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$cart.id$']),
436+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$cart.id$']),
437+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$cart.id$'], 'order'),
438+
DataFixture(InvoiceFixture::class, ['order_id' => '$order.id$'], 'invoice'),
439+
DataFixture(InvoiceCommentFixture::class, [
440+
'parent_id' => '$invoice.id$',
441+
'comment' => 'visible_comment',
442+
'is_visible_on_front' => 1,
443+
]),
444+
DataFixture(InvoiceCommentFixture::class, [
445+
'parent_id' => '$invoice.id$',
446+
'comment' => 'non_visible_comment',
447+
'is_visible_on_front' => 0,
448+
]),
449+
]
416450
public function testInvoiceCommentsQuery()
417451
{
418452
$query =

dev/tests/integration/testsuite/Magento/Sales/_files/customer_invoice_comments_for_search.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/Sales/_files/customer_invoice_comments_for_search_rollback.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)