-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.4-develop' of https://github.com/magento/magento2 int…
…o 2.3-bugfix/access_denied_issue25881
- Loading branch information
Showing
2,040 changed files
with
43,273 additions
and
18,581 deletions.
There are no files selected for viewing
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
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
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
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
37 changes: 37 additions & 0 deletions
37
app/code/Magento/AsynchronousOperations/Model/OperationStatusPool.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,37 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\AsynchronousOperations\Model; | ||
|
||
/** | ||
* Class OperationStatusPool | ||
* | ||
* Pool of statuses that require validate | ||
*/ | ||
class OperationStatusPool | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $statuses; | ||
|
||
/** | ||
* @param array $statuses | ||
*/ | ||
public function __construct(array $statuses = []) | ||
{ | ||
$this->statuses = $statuses; | ||
} | ||
|
||
/** | ||
* Retrieve statuses that require validate | ||
* | ||
* @return array | ||
*/ | ||
public function getStatuses() | ||
{ | ||
return $this->statuses; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
app/code/Magento/AsynchronousOperations/Model/OperationStatusValidator.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,47 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\AsynchronousOperations\Model; | ||
|
||
use Magento\AsynchronousOperations\Model\OperationStatusPool; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Doctrine\Instantiator\Exception\InvalidArgumentException; | ||
|
||
/** | ||
* Class OperationStatusValidator to validate operation status | ||
*/ | ||
class OperationStatusValidator | ||
{ | ||
/** | ||
* @var OperationStatusPool | ||
*/ | ||
private $operationStatusPool; | ||
|
||
/** | ||
* OperationStatusValidator constructor. | ||
* | ||
* @param OperationStatusPool $operationStatusPool | ||
*/ | ||
public function __construct(OperationStatusPool $operationStatusPool) | ||
{ | ||
$this->operationStatusPool = $operationStatusPool; | ||
} | ||
|
||
/** | ||
* Validate method | ||
* | ||
* @param int $status | ||
* @throws \InvalidArgumentException | ||
* @return void | ||
*/ | ||
public function validate($status) | ||
{ | ||
$statuses = $this->operationStatusPool->getStatuses(); | ||
|
||
if (!in_array($status, $statuses)) { | ||
throw new \InvalidArgumentException('Invalid Operation Status.'); | ||
} | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
app/code/Magento/AsynchronousOperations/Test/Unit/Model/OperationStatusValidatorTest.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,155 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\AsynchronousOperations\Test\Unit\Model; | ||
|
||
use Magento\AsynchronousOperations\Model\OperationStatusValidator; | ||
use Magento\AsynchronousOperations\Model\Operation; | ||
use Magento\AsynchronousOperations\Model\OperationStatusPool; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class OperationStatusValidatorTest implements logic for testing Operation::setStatus() method | ||
*/ | ||
class OperationStatusValidatorTest extends TestCase | ||
{ | ||
/** | ||
* @var OperationStatusPool | ||
*/ | ||
private $operationStatusPool; | ||
|
||
/** | ||
* @var OperationStatusValidator | ||
*/ | ||
private $operationStatusValidator; | ||
|
||
/** | ||
* @var Operation | ||
*/ | ||
private $operation; | ||
|
||
protected function setUp() | ||
{ | ||
$this->operationStatusPool = $this->getMockBuilder(OperationStatusPool::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$objectManager = new ObjectManager($this); | ||
|
||
$this->operationStatusValidator = $objectManager->getObject( | ||
OperationStatusValidator::class, | ||
[ | ||
'operationStatusPool' => $this->operationStatusPool | ||
] | ||
); | ||
|
||
$this->operation = $objectManager->getObject( | ||
Operation::class, | ||
[ | ||
'operationStatusValidator' => $this->operationStatusValidator | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @param string $status | ||
* @param array $statusPool | ||
* @param string $expectedResult | ||
* @dataProvider dataProviderForTestSetStatus | ||
*/ | ||
public function testSetStatus( | ||
string $status, | ||
array $statusPool, | ||
string $expectedResult | ||
) { | ||
$this->operationStatusPool | ||
->expects($this->any()) | ||
->method('getStatuses') | ||
->willReturn($statusPool); | ||
|
||
try { | ||
$this->operation->setStatus($status); | ||
$this->assertEquals($expectedResult, $this->operation->getStatus()); | ||
} catch (\Exception $exception) { | ||
$this->assertEquals($expectedResult, $exception->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||
*/ | ||
public function dataProviderForTestSetStatus() | ||
{ | ||
return [ | ||
[ | ||
'status' => 0, | ||
'statusPool' => [ | ||
'complete' => 1, | ||
'retriablyFailed' => 2, | ||
'notRetriablyFailed' => 3, | ||
'open' => 4, | ||
'rejected' => 5 | ||
], | ||
'expectedResult' => 'Invalid Operation Status.' | ||
], | ||
[ | ||
'status' => 1, | ||
'statusPool' => [ | ||
'complete' => 1, | ||
'retriablyFailed' => 2, | ||
'notRetriablyFailed' => 3, | ||
'open' => 4, | ||
'rejected' => 5 | ||
], | ||
'expectedResult' => 1 | ||
], | ||
[ | ||
'status' => 2, | ||
'statusPool' => [ | ||
'complete' => 1, | ||
'retriablyFailed' => 2, | ||
'notRetriablyFailed' => 3, | ||
'open' => 4, | ||
'rejected' => 5 | ||
], | ||
'expectedResult' => 2 | ||
], | ||
[ | ||
'status' => 3, | ||
'statusPool' => [ | ||
'complete' => 1, | ||
'retriablyFailed' => 2, | ||
'notRetriablyFailed' => 3, | ||
'open' => 4, | ||
'rejected' => 5 | ||
], | ||
'expectedResult' => 3 | ||
], | ||
[ | ||
'status' => 4, | ||
'statusPool' => [ | ||
'complete' => 1, | ||
'retriablyFailed' => 2, | ||
'notRetriablyFailed' => 3, | ||
'open' => 4, | ||
'rejected' => 5 | ||
], | ||
'expectedResult' => 4 | ||
], | ||
[ | ||
'status' => 5, | ||
'statusPool' => [ | ||
'complete' => 1, | ||
'retriablyFailed' => 2, | ||
'notRetriablyFailed' => 3, | ||
'open' => 4, | ||
'rejected' => 5 | ||
], | ||
'expectedResult' => 5 | ||
] | ||
]; | ||
} | ||
} |
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
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
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
Oops, something went wrong.