19 private $connectionMock;
43 $this->meta = $this->createPartialMock(
44 \
Magento\SalesSequence\Model\Meta::class,
45 [
'getSequenceTable',
'getActiveProfile']
47 $this->profile = $this->createPartialMock(
48 \
Magento\SalesSequence\Model\Profile::class,
49 [
'getSuffix',
'getPrefix',
'getStep',
'getStartValue']
51 $this->resource = $this->createPartialMock(\
Magento\Framework\
App\ResourceConnection::class, [
'getConnection']);
52 $this->connectionMock = $this->getMockForAbstractClass(
53 \
Magento\Framework\DB\Adapter\AdapterInterface::class,
59 [
'insert',
'lastInsertId']
61 $this->resource->expects($this->any())->method(
'getConnection')->willReturn($this->connectionMock);
62 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
63 $this->sequence =
$helper->getObject(
64 \
Magento\SalesSequence\Model\Sequence::class,
66 'meta' => $this->meta,
67 'resource' => $this->resource,
74 $this->assertNull($this->sequence->getCurrentValue());
82 $this->profile->expects($this->atLeastOnce())->method(
'getStartValue')->willReturn($startValue);
83 $this->meta->expects($this->atLeastOnce())
84 ->method(
'getActiveProfile')
88 $this->meta->expects($this->atLeastOnce())
89 ->method(
'getSequenceTable')
91 $this->sequenceParameters()->testTable
93 $this->connectionMock->expects($this->exactly(3))->method(
'insert')->with(
94 $this->sequenceParameters()->testTable,
97 $this->profile->expects($this->exactly(3))->method(
'getSuffix')->willReturn(
98 $this->sequenceParameters()->suffix
100 $this->profile->expects($this->exactly(3))->method(
'getPrefix')->willReturn(
101 $this->sequenceParameters()->prefix
103 $this->profile->expects($this->exactly(3))->method(
'getStep')->willReturn($step);
104 $lastInsertId = $this->nextIncrementStep($lastInsertId, 780);
105 $lastInsertId = $this->nextIncrementStep($lastInsertId, 1557);
106 $this->nextIncrementStep($lastInsertId, 2334);
114 private function nextIncrementStep($lastInsertId, $sequenceNumber)
117 $this->connectionMock->expects($this->at(1))->method(
'lastInsertId')->with(
118 $this->sequenceParameters()->testTable
125 $this->sequenceParameters()->prefix,
127 $this->sequenceParameters()->suffix
129 $this->sequence->getNextValue()
131 return $lastInsertId;
137 private function sequenceParameters()
139 $data = new \stdClass();
140 $data->prefix =
'AA-';
141 $data->suffix =
'-0';
142 $data->testTable =
'testSequence';
testSequenceInitialNull()