Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop
Browse files Browse the repository at this point in the history
Accepted Community Pull Requests:
 - #25940: Asynchronous operation validate (by @sedonik)
 - #25523: Contact form > Adding ViewModel (by @rafaelstz)
 - #25697: [New Relic] Making system configs dependent by Enabled field (by @eduard13)
 - #26067: [Msrp] Cover MsrpPriceCalculator by Unit Test (by @edenduong)
 - #24360: #24357 Eav sort order by attribute option_id (by @tnsezer)
 - #26069: [CMS] Improving the test coverage for UrlBuilder ViewModel  (by @eduard13)
 - #26063: [Theme] Reverting removed container class (by @eduard13)
 - #26057: [Contact] covered Model Config by Unit Test (by @srsathish92)
 - #26050: [Catalog] covered product ViewModel AddToCompareAvailability by Unit Test (by @srsathish92)
 - #26037: Fixes phpcs  errors and warnings for Magento\Framework\View\Element (by @krisdante)
 - #26045: [Downloadable] Cover Helper Data by Unit Test (by @edenduong)
 - #26043: [Persistent] Cover CustomerData by Unit Test (by @edenduong)
 - #26042: [Catalog] Cover Component/FilterFactory by Unit Test (by @edenduong)
 - #26044: Set empty value to color picker when input is reset to update preview (by @gperis)
 - #26034: MAGETWO-95866 Add horizontal scroll if elements extend menu's width (by @ptylek)
 - #26001: Fix caching Magento Metadata getVersion (by @luklewluk)
 - #26003: [Directory] Cover action directory/json/countryRegion by Integration Test (by @edenduong)


Fixed GitHub Issues:
 - #100: Oracle and Other RDBMS Status? (reported by @dicgf8) has been fixed in #25940 by @sedonik in 2.4-develop branch
   Related commits:
     1. dc8821d
     2. f305a84
     3. 345ece3
     4. b1e518c

 - #24357: Eav sort order by attribute option_id (reported by @tnsezer) has been fixed in #24360 by @tnsezer in 2.4-develop branch
   Related commits:
     1. 459c596
     2. a047aca
     3. 952d12e
     4. 4000459
     5. 49738bd
     6. d0006b9

 - #20379: calendar icon not aligned inside the textbox in Add Design Change page (reported by @irajneeshgupta) has been fixed in #26063 by @eduard13 in 2.4-develop branch
   Related commits:
     1. 218c3ff

 - #18687: Left Side Back End Menu Design fix (reported by @jigar48) has been fixed in #26034 by @ptylek in 2.4-develop branch
   Related commits:
     1. f59c1ca
     2. 7a2bc8f
     3. 6bf903f

 - #24025: Slow Performance of ProductMetadata::getVersion (reported by @beberlei) has been fixed in #26001 by @luklewluk in 2.4-develop branch
   Related commits:
     1. 16ab63b
     2. ab6cabd
     3. 0b7c34e
  • Loading branch information
VladimirZaets authored Dec 18, 2019
2 parents 320ccf2 + 4ffea5b commit 9400c1e
Show file tree
Hide file tree
Showing 46 changed files with 1,651 additions and 21 deletions.
23 changes: 22 additions & 1 deletion app/code/Magento/AsynchronousOperations/Model/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,33 @@
namespace Magento\AsynchronousOperations\Model;

use Magento\AsynchronousOperations\Api\Data\OperationInterface;
use Magento\AsynchronousOperations\Model\OperationStatusValidator;
use Magento\Framework\DataObject;

/**
* Class Operation
* Class Operation encapsulates methods for Operation Model Object
*/
class Operation extends DataObject implements OperationInterface
{
/**
* @var OperationStatusValidator
*/
private $operationStatusValidator;

/**
* Operation constructor.
*
* @param OperationStatusValidator $operationStatusValidator
* @param array $data
*/
public function __construct(
OperationStatusValidator $operationStatusValidator,
array $data = []
) {
$this->operationStatusValidator = $operationStatusValidator;
parent::__construct($data);
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -106,6 +126,7 @@ public function getStatus()
*/
public function setStatus($status)
{
$this->operationStatusValidator->validate($status);
return $this->setData(self::STATUS, $status);
}

Expand Down
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;
}
}
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.');
}
}
}
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
]
];
}
}
11 changes: 11 additions & 0 deletions app/code/Magento/AsynchronousOperations/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@
</argument>
</arguments>
</type>
<type name="Magento\AsynchronousOperations\Model\OperationStatusPool">
<arguments>
<argument name="statuses" xsi:type="array">
<item name="complete" xsi:type="string">1</item>
<item name="retriablyFailed" xsi:type="string">2</item>
<item name="notRetriablyFailed" xsi:type="string">3</item>
<item name="open" xsi:type="string">4</item>
<item name="rejected" xsi:type="string">5</item>
</argument>
</arguments>
</type>
<virtualType
name="Magento\AsynchronousOperations\Ui\Component\DataProvider"
type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider"/>
Expand Down
Loading

0 comments on commit 9400c1e

Please sign in to comment.