diff --git a/app/code/Magento/SalesSequence/Model/Meta.php b/app/code/Magento/SalesSequence/Model/Meta.php index d179d127e95af..8cee7cdf8e1cc 100644 --- a/app/code/Magento/SalesSequence/Model/Meta.php +++ b/app/code/Magento/SalesSequence/Model/Meta.php @@ -11,6 +11,10 @@ * Class Meta * * @api + * @method Profile getActiveProfile() + * @method string getEntityType() + * @method int getStoreId() + * @method string getSequenceTable() * @since 100.0.2 */ class Meta extends AbstractModel diff --git a/app/code/Magento/SalesSequence/Model/Profile.php b/app/code/Magento/SalesSequence/Model/Profile.php index 63a83dc2e5413..9a97693b078f7 100644 --- a/app/code/Magento/SalesSequence/Model/Profile.php +++ b/app/code/Magento/SalesSequence/Model/Profile.php @@ -11,6 +11,10 @@ * Class Profile * * @api + * @method string getPrefix() + * @method string getSuffix() + * @method int getStartValue() + * @method int getStep() * @since 100.0.2 */ class Profile extends AbstractModel diff --git a/app/code/Magento/SalesSequence/Model/Sequence.php b/app/code/Magento/SalesSequence/Model/Sequence.php index 9e3b0c67c3065..208cff9909a3b 100644 --- a/app/code/Magento/SalesSequence/Model/Sequence.php +++ b/app/code/Magento/SalesSequence/Model/Sequence.php @@ -49,7 +49,7 @@ class Sequence implements SequenceInterface public function __construct( Meta $meta, AppResource $resource, - $pattern = self::DEFAULT_PATTERN + string $pattern = self::DEFAULT_PATTERN ) { $this->meta = $meta; $this->connection = $resource->getConnection('sales'); @@ -59,9 +59,9 @@ public function __construct( /** * Retrieve current value * - * @return string + * @return ?string */ - public function getCurrentValue() + public function getCurrentValue(): ?string { if (!isset($this->lastIncrementId)) { return null; @@ -76,11 +76,9 @@ public function getCurrentValue() } /** - * Retrieve next value - * - * @return string + * @inheritdoc */ - public function getNextValue() + public function getNextValue(): string { $this->connection->insert($this->meta->getSequenceTable(), []); $this->lastIncrementId = $this->connection->lastInsertId($this->meta->getSequenceTable()); @@ -92,9 +90,39 @@ public function getNextValue() * * @return string */ - private function calculateCurrentValue() + public function calculateCurrentValue(): string { return ($this->lastIncrementId - $this->meta->getActiveProfile()->getStartValue()) * $this->meta->getActiveProfile()->getStep() + $this->meta->getActiveProfile()->getStartValue(); } + + /** + * Retrieve the current entity type + * + * @return string + */ + public function getEntityType(): string + { + return $this->meta->getEntityType(); + } + + /** + * Retrieve the current store id + * + * @return int + */ + public function getStoreId(): int + { + return $this->meta->getStoreId(); + } + + /** + * Retrieve the currently active meta profile + * + * @return Profile + */ + public function getMetaProfile(): Profile + { + return $this->meta->getActiveProfile(); + } } diff --git a/app/code/Magento/SalesSequence/Test/Unit/Model/SequenceTest.php b/app/code/Magento/SalesSequence/Test/Unit/Model/SequenceTest.php index 303e998ebb5db..d7058a534c68a 100644 --- a/app/code/Magento/SalesSequence/Test/Unit/Model/SequenceTest.php +++ b/app/code/Magento/SalesSequence/Test/Unit/Model/SequenceTest.php @@ -49,7 +49,7 @@ class SequenceTest extends TestCase protected function setUp(): void { $this->meta = $this->getMockBuilder(Meta::class) - ->addMethods(['getSequenceTable', 'getActiveProfile']) + ->addMethods(['getSequenceTable', 'getActiveProfile', 'getStoreId', 'getEntityType']) ->disableOriginalConstructor() ->getMock(); $this->profile = $this->getMockBuilder(Profile::class) @@ -85,6 +85,30 @@ public function testSequenceInitialNull(): void $this->assertNull($this->sequence->getCurrentValue()); } + /** + * Test that the meta getters return values as expected + * + * @return void + */ + public function testMetaGetters(): void + { + $exampleEntityType = 'order'; + $exampleStoreId = 0; + $this->meta->expects($this->atLeastOnce()) + ->method('getActiveProfile') + ->willReturn($this->profile); + + $this->meta->expects($this->atLeastOnce()) + ->method('getStoreId') + ->willReturn($exampleStoreId); + $this->meta->expects($this->atLeastOnce()) + ->method('getEntityType') + ->willReturn($exampleEntityType); + + $this->assertEquals($exampleEntityType, $this->sequence->getEntityType()); + $this->assertEquals($exampleStoreId, $this->sequence->getStoreId()); + } + /** * @return void */ diff --git a/lib/internal/Magento/Framework/DB/Sequence/SequenceInterface.php b/lib/internal/Magento/Framework/DB/Sequence/SequenceInterface.php index a3a8687891ee8..28b8e9dda40ff 100644 --- a/lib/internal/Magento/Framework/DB/Sequence/SequenceInterface.php +++ b/lib/internal/Magento/Framework/DB/Sequence/SequenceInterface.php @@ -17,14 +17,14 @@ interface SequenceInterface /** * Retrieve current value * - * @return string + * @return ?string */ - public function getCurrentValue(); + public function getCurrentValue(): ?string; /** * Retrieve next value * * @return string */ - public function getNextValue(); + public function getNextValue(): string; } diff --git a/lib/internal/Magento/Framework/EntityManager/Sequence/Sequence.php b/lib/internal/Magento/Framework/EntityManager/Sequence/Sequence.php index 2576e72a7e21e..a0d00dfb01c75 100644 --- a/lib/internal/Magento/Framework/EntityManager/Sequence/Sequence.php +++ b/lib/internal/Magento/Framework/EntityManager/Sequence/Sequence.php @@ -36,8 +36,8 @@ class Sequence implements SequenceInterface */ public function __construct( ResourceConnection $resource, - $connectionName, - $sequenceTable + string $connectionName, + string $sequenceTable ) { $this->resource = $resource; $this->connectionName = $connectionName; @@ -47,7 +47,7 @@ public function __construct( /** * @inheritdoc */ - public function getNextValue() + public function getNextValue(): string { $this->resource->getConnection($this->connectionName) ->insert($this->resource->getTableName($this->sequenceTable), []); @@ -58,7 +58,7 @@ public function getNextValue() /** * @inheritdoc */ - public function getCurrentValue() + public function getCurrentValue(): string { $select = $this->resource->getConnection($this->connectionName)->select(); $select->from($this->resource->getTableName($this->sequenceTable));