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.
Fix magento#14958 - apply requested changes
- Loading branch information
1 parent
c83a283
commit 328bc51
Showing
10 changed files
with
329 additions
and
116 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
48 changes: 48 additions & 0 deletions
48
app/code/Magento/SalesSequence/Model/ResourceModel/Meta/Ids.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,48 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\SalesSequence\Model\ResourceModel\Meta; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
|
||
/** | ||
* Class Ids is used to retrieve metadata ids for sequence | ||
*/ | ||
class Ids extends AbstractDb | ||
{ | ||
/** | ||
* Model initialization | ||
* | ||
* @return void | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init('sales_sequence_meta', 'meta_id'); | ||
} | ||
|
||
/** | ||
* Retrieves Metadata Ids by store id | ||
* | ||
* @param int $storeId | ||
* @return int[] | ||
* @throws LocalizedException | ||
*/ | ||
public function getByStoreId($storeId) | ||
{ | ||
$connection = $this->getConnection(); | ||
$bind = ['store_id' => $storeId]; | ||
$select = $connection->select()->from( | ||
$this->getMainTable(), | ||
[$this->getIdFieldName()] | ||
)->where( | ||
'store_id = :store_id' | ||
); | ||
|
||
return $connection->fetchCol($select, $bind); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
app/code/Magento/SalesSequence/Model/ResourceModel/Profile/Ids.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,42 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\SalesSequence\Model\ResourceModel\Profile; | ||
|
||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
|
||
/** | ||
* Class Ids is used to retrieve profile ids for sequence profile | ||
*/ | ||
class Ids extends AbstractDb | ||
{ | ||
/** | ||
* Model initialization | ||
* | ||
* @return void | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init('sales_sequence_profile', 'profile_id'); | ||
} | ||
|
||
/** | ||
* Get profile ids by metadata ids | ||
* | ||
* @param int[] $metadataIds | ||
* @return int[] | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function getByMetadataIds(array $metadataIds) | ||
{ | ||
$connection = $this->getConnection(); | ||
$select = $connection->select() | ||
->from($this->getMainTable(), ['profile_id']) | ||
->where('meta_id IN (?)', $metadataIds); | ||
|
||
return $connection->fetchCol($select); | ||
} | ||
} |
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
99 changes: 99 additions & 0 deletions
99
app/code/Magento/SalesSequence/Test/Unit/Model/ResourceModel/Meta/IdsTest.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,99 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\SalesSequence\Test\Unit\Model\ResourceModel\Meta; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\DB\Adapter\AdapterInterface; | ||
use Magento\Framework\DB\Select; | ||
use Magento\Framework\Model\ResourceModel\Db\Context; | ||
use Magento\SalesSequence\Model\ResourceModel\Meta\Ids; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class IdsTest | ||
*/ | ||
class IdsTest extends TestCase | ||
{ | ||
/** | ||
* @var AdapterInterface | MockObject | ||
*/ | ||
private $connectionMock; | ||
|
||
/** | ||
* @var Context | MockObject | ||
*/ | ||
private $dbContext; | ||
|
||
/** | ||
* @var Ids | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* @var Resource | MockObject | ||
*/ | ||
protected $resourceMock; | ||
|
||
/** | ||
* @var Select | MockObject | ||
*/ | ||
private $select; | ||
|
||
/** | ||
* Initialization | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->connectionMock = $this->getMockForAbstractClass( | ||
AdapterInterface::class, | ||
[], | ||
'', | ||
false, | ||
false, | ||
true, | ||
['query'] | ||
); | ||
$this->dbContext = $this->createMock(Context::class); | ||
$this->resourceMock = $this->createPartialMock( | ||
ResourceConnection::class, | ||
['getConnection', 'getTableName'] | ||
); | ||
$this->dbContext->expects($this->once())->method('getResources')->willReturn($this->resourceMock); | ||
$this->select = $this->createMock(Select::class); | ||
$this->resource = new Ids( | ||
$this->dbContext | ||
); | ||
} | ||
|
||
public function testGetByStoreId() | ||
{ | ||
$metaTableName = 'sequence_meta'; | ||
$metaIdFieldName = 'meta_id'; | ||
$storeId = 1; | ||
$metaIds = [1, 2]; | ||
$this->resourceMock->expects($this->any()) | ||
->method('getConnection') | ||
->willReturn($this->connectionMock); | ||
$this->resourceMock->expects($this->once()) | ||
->method('getTableName') | ||
->willReturn($metaTableName); | ||
$this->connectionMock->expects($this->any())->method('select')->willReturn($this->select); | ||
$this->select->expects($this->at(0)) | ||
->method('from') | ||
->with($metaTableName, [$metaIdFieldName]) | ||
->willReturn($this->select); | ||
$this->select->expects($this->at(1)) | ||
->method('where') | ||
->with('store_id = :store_id') | ||
->willReturn($this->select); | ||
$this->connectionMock->expects($this->once()) | ||
->method('fetchCol') | ||
->with($this->select, ['store_id' => $storeId]) | ||
->willReturn($metaIds); | ||
$this->assertEquals($metaIds, $this->resource->getByStoreId($storeId)); | ||
} | ||
} |
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.