Skip to content

Commit a8954c6

Browse files
committed
AC-1271: Add rate limiting for payment information endpoint and mutation
1 parent 71991bf commit a8954c6

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

dev/tests/integration/testsuite/Magento/Framework/App/Backpressure/SlidingWindow/CacheRequestLoggerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use Magento\TestFramework\Helper\Bootstrap;
1414
use PHPUnit\Framework\TestCase;
1515

16+
/**
17+
* Tests CacheRequestLogger class
18+
*/
1619
class CacheRequestLoggerTest extends TestCase
1720
{
1821
/**
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Webapi\Test\Unit\Backpressure;
9+
10+
use Magento\Framework\Webapi\Backpressure\BackpressureRequestTypeExtractorInterface;
11+
use PHPUnit\Framework\MockObject\MockObject;
12+
use PHPUnit\Framework\TestCase;
13+
use Magento\Framework\Webapi\Backpressure\CompositeRequestTypeExtractor;
14+
15+
/**
16+
* Tests the CompositeRequestTypeExtractor class
17+
*/
18+
class CompositeRequestTypeExtractorTest extends TestCase
19+
{
20+
/**
21+
* @var CompositeRequestTypeExtractor
22+
*/
23+
private CompositeRequestTypeExtractor $compositeRequestTypeExtractor;
24+
25+
/**
26+
* @var BackpressureRequestTypeExtractorInterface|MockObject
27+
*/
28+
private $extractorMock;
29+
30+
/**
31+
* @inheritDoc
32+
*/
33+
protected function setUp(): void
34+
{
35+
$this->extractorMock = $this->getMockForAbstractClass(
36+
BackpressureRequestTypeExtractorInterface::class
37+
);
38+
39+
$this->compositeRequestTypeExtractor = new CompositeRequestTypeExtractor(
40+
array_fill(0, 3, $this->extractorMock)
41+
);
42+
}
43+
44+
/**
45+
* Tests CompositeRequestTypeExtractor
46+
*/
47+
public function testExtract()
48+
{
49+
$this->extractorMock->expects($this->exactly(2))
50+
->method('extract')
51+
->with('someService', 'someMethod', 'someEndpoint')
52+
->willReturnOnConsecutiveCalls(null, 'someType');
53+
54+
$this->assertEquals(
55+
'someType',
56+
$this->compositeRequestTypeExtractor->extract(
57+
'someService',
58+
'someMethod',
59+
'someEndpoint'
60+
)
61+
);
62+
}
63+
64+
/**
65+
* Tests CompositeRequestTypeExtractor when type
66+
*/
67+
public function testExtractTypeNotFound()
68+
{
69+
$this->extractorMock->expects($this->exactly(3))
70+
->method('extract')
71+
->with('someService', 'someMethod', 'someEndpoint')
72+
->willReturn(null);
73+
$this->assertEquals(
74+
null,
75+
$this->compositeRequestTypeExtractor->extract(
76+
'someService',
77+
'someMethod',
78+
'someEndpoint'
79+
)
80+
);
81+
}
82+
}

0 commit comments

Comments
 (0)