Skip to content

Commit 6ed0d87

Browse files
committed
Tests fix
1 parent eb81164 commit 6ed0d87

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

app/code/Magento/Swatches/Helper/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Data
3535
const EMPTY_IMAGE_VALUE = 'no_selection';
3636

3737
/**
38-
* Default store ID
38+
* The int value of the Default store ID
3939
*/
4040
const DEFAULT_STORE_ID = 0;
4141

app/code/Magento/Swatches/Test/Unit/Helper/DataTest.php

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,8 @@ public function dataForGettingSwatchAsArray()
669669

670670
public function testGetSwatchesByOptionsIdIf1()
671671
{
672-
$swatchMock = $this->createMock(\Magento\Swatches\Model\Swatch::class);
672+
//Simulate behaviour of \Magento\Swatches\Model\Swatch as array item
673+
$swatchMock = $this->createMock(\ArrayAccess::class);
673674

674675
$optionsData = [
675676
[
@@ -692,22 +693,18 @@ public function testGetSwatchesByOptionsIdIf1()
692693
->willReturn($optionsData[0]['type']);
693694
$swatchMock->expects($this->at(1))->method('offsetGet')->with('option_id')
694695
->willReturn($optionsData[0]['option_id']);
695-
$swatchMock->expects($this->at(2))->method('getData')->with('')
696-
->willReturn($optionsData[0]);
697-
$swatchMock->expects($this->at(3))->method('offsetGet')->with('type')
696+
$swatchMock->expects($this->at(2))->method('offsetGet')->with('type')
698697
->willReturn($optionsData[1]['type']);
699-
$swatchMock->expects($this->at(4))->method('offsetGet')->with('store_id')
698+
$swatchMock->expects($this->at(3))->method('offsetGet')->with('store_id')
700699
->willReturn($optionsData[1]['store_id']);
701-
$swatchMock->expects($this->at(5))->method('offsetGet')->with('store_id')
700+
$swatchMock->expects($this->at(4))->method('offsetGet')->with('store_id')
702701
->willReturn($optionsData[1]['store_id']);
703-
$swatchMock->expects($this->at(6))->method('offsetGet')->with('option_id')
702+
$swatchMock->expects($this->at(5))->method('offsetGet')->with('option_id')
704703
->willReturn($optionsData[1]['option_id']);
705-
$swatchMock->expects($this->at(7))->method('getData')->with('')
706-
->willReturn($optionsData[1]);
707704

708-
$swatchCollectionMock = $this->objectManager
709-
->getCollectionMock(Collection::class, [$swatchMock, $swatchMock]);
705+
$swatchCollectionMock = $this->createMock(Collection::class);
710706
$swatchCollectionMock->method('addFilterByOptionsIds')->with([35])->will($this->returnSelf());
707+
$swatchCollectionMock->expects($this->once())->method('getData')->willReturn([$swatchMock, $swatchMock]);
711708
$this->swatchCollectionFactoryMock->method('create')->willReturn($swatchCollectionMock);
712709

713710
$storeMock = $this->createMock(\Magento\Store\Model\Store::class);
@@ -719,7 +716,8 @@ public function testGetSwatchesByOptionsIdIf1()
719716

720717
public function testGetSwatchesByOptionsIdIf2()
721718
{
722-
$swatchMock = $this->createMock(\Magento\Swatches\Model\Swatch::class);
719+
//Simulate behaviour of \Magento\Swatches\Model\Swatch as array item
720+
$swatchMock = $this->createMock(\ArrayAccess::class);
723721

724722
$optionsData = [
725723
[
@@ -742,23 +740,16 @@ public function testGetSwatchesByOptionsIdIf2()
742740
$swatchMock->expects($this->at(1))->method('offsetGet')->with('store_id')->willReturn(1);
743741
$swatchMock->expects($this->at(2))->method('offsetGet')->with('value')->willReturn('test');
744742
$swatchMock->expects($this->at(3))->method('offsetGet')->with('option_id')->willReturn(35);
745-
$swatchMock->expects($this->at(4))->method('getData')->with('')->willReturn($optionsData[0]);
746-
$swatchMock->expects($this->at(5))->method('offsetGet')->with('type')->willReturn(0);
747-
$swatchMock->expects($this->at(6))->method('offsetGet')->with('store_id')->willReturn(1);
748-
$swatchMock->expects($this->at(7))->method('offsetGet')->with('value')->willReturn('test2');
749-
$swatchMock->expects($this->at(8))->method('offsetGet')->with('option_id')->willReturn(36);
750-
$swatchMock->expects($this->at(9))->method('getData')->with('')->willReturn($optionsData[1]);
751-
752-
$swatchCollectionMock = $this->objectManager->getCollectionMock(
753-
Collection::class,
754-
[
755-
$swatchMock,
756-
$swatchMock,
757-
]
758-
);
743+
$swatchMock->expects($this->at(4))->method('offsetGet')->with('type')->willReturn(0);
744+
$swatchMock->expects($this->at(5))->method('offsetGet')->with('store_id')->willReturn(1);
745+
$swatchMock->expects($this->at(6))->method('offsetGet')->with('value')->willReturn('test2');
746+
$swatchMock->expects($this->at(7))->method('offsetGet')->with('option_id')->willReturn(36);
747+
748+
$swatchCollectionMock = $this->createMock(Collection::class);
759749
$this->swatchCollectionFactoryMock->method('create')->willReturn($swatchCollectionMock);
760750

761751
$swatchCollectionMock->method('addFilterByOptionsIds')->with([35])->will($this->returnSelf());
752+
$swatchCollectionMock->expects($this->once())->method('getData')->willReturn([$swatchMock, $swatchMock]);
762753

763754
$storeMock = $this->createMock(\Magento\Store\Model\Store::class);
764755
$this->storeManagerMock->method('getStore')->willReturn($storeMock);
@@ -769,7 +760,8 @@ public function testGetSwatchesByOptionsIdIf2()
769760

770761
public function testGetSwatchesByOptionsIdIf3()
771762
{
772-
$swatchMock = $this->createMock(\Magento\Swatches\Model\Swatch::class);
763+
//Simulate behaviour of \Magento\Swatches\Model\Swatch as array item
764+
$swatchMock = $this->createMock(\ArrayAccess::class);
773765

774766
$optionsData = [
775767
'type' => 0,
@@ -783,17 +775,12 @@ public function testGetSwatchesByOptionsIdIf3()
783775
$swatchMock->expects($this->at(1))->method('offsetGet')->with('store_id')->willReturn(0);
784776
$swatchMock->expects($this->at(2))->method('offsetGet')->with('store_id')->willReturn(0);
785777
$swatchMock->expects($this->at(3))->method('offsetGet')->with('option_id')->willReturn(35);
786-
$swatchMock->expects($this->at(4))->method('getData')->with('')->willReturn($optionsData);
787778

788-
$swatchCollectionMock = $this->objectManager->getCollectionMock(
789-
Collection::class,
790-
[
791-
$swatchMock,
792-
]
793-
);
779+
$swatchCollectionMock = $this->createMock(Collection::class);
794780
$this->swatchCollectionFactoryMock->method('create')->willReturn($swatchCollectionMock);
795781

796782
$swatchCollectionMock->method('addFilterByOptionsIds')->with([35])->will($this->returnSelf());
783+
$swatchCollectionMock->expects($this->once())->method('getData')->willReturn([$swatchMock]);
797784

798785
$storeMock = $this->createMock(\Magento\Store\Model\Store::class);
799786
$this->storeManagerMock->method('getStore')->willReturn($storeMock);

0 commit comments

Comments
 (0)