@@ -669,7 +669,8 @@ public function dataForGettingSwatchAsArray()
669
669
670
670
public function testGetSwatchesByOptionsIdIf1 ()
671
671
{
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);
673
674
674
675
$ optionsData = [
675
676
[
@@ -692,22 +693,18 @@ public function testGetSwatchesByOptionsIdIf1()
692
693
->willReturn ($ optionsData [0 ]['type ' ]);
693
694
$ swatchMock ->expects ($ this ->at (1 ))->method ('offsetGet ' )->with ('option_id ' )
694
695
->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 ' )
698
697
->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 ' )
700
699
->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 ' )
702
701
->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 ' )
704
703
->willReturn ($ optionsData [1 ]['option_id ' ]);
705
- $ swatchMock ->expects ($ this ->at (7 ))->method ('getData ' )->with ('' )
706
- ->willReturn ($ optionsData [1 ]);
707
704
708
- $ swatchCollectionMock = $ this ->objectManager
709
- ->getCollectionMock (Collection::class, [$ swatchMock , $ swatchMock ]);
705
+ $ swatchCollectionMock = $ this ->createMock (Collection::class);
710
706
$ swatchCollectionMock ->method ('addFilterByOptionsIds ' )->with ([35 ])->will ($ this ->returnSelf ());
707
+ $ swatchCollectionMock ->expects ($ this ->once ())->method ('getData ' )->willReturn ([$ swatchMock , $ swatchMock ]);
711
708
$ this ->swatchCollectionFactoryMock ->method ('create ' )->willReturn ($ swatchCollectionMock );
712
709
713
710
$ storeMock = $ this ->createMock (\Magento \Store \Model \Store::class);
@@ -719,7 +716,8 @@ public function testGetSwatchesByOptionsIdIf1()
719
716
720
717
public function testGetSwatchesByOptionsIdIf2 ()
721
718
{
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);
723
721
724
722
$ optionsData = [
725
723
[
@@ -742,23 +740,16 @@ public function testGetSwatchesByOptionsIdIf2()
742
740
$ swatchMock ->expects ($ this ->at (1 ))->method ('offsetGet ' )->with ('store_id ' )->willReturn (1 );
743
741
$ swatchMock ->expects ($ this ->at (2 ))->method ('offsetGet ' )->with ('value ' )->willReturn ('test ' );
744
742
$ 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);
759
749
$ this ->swatchCollectionFactoryMock ->method ('create ' )->willReturn ($ swatchCollectionMock );
760
750
761
751
$ swatchCollectionMock ->method ('addFilterByOptionsIds ' )->with ([35 ])->will ($ this ->returnSelf ());
752
+ $ swatchCollectionMock ->expects ($ this ->once ())->method ('getData ' )->willReturn ([$ swatchMock , $ swatchMock ]);
762
753
763
754
$ storeMock = $ this ->createMock (\Magento \Store \Model \Store::class);
764
755
$ this ->storeManagerMock ->method ('getStore ' )->willReturn ($ storeMock );
@@ -769,7 +760,8 @@ public function testGetSwatchesByOptionsIdIf2()
769
760
770
761
public function testGetSwatchesByOptionsIdIf3 ()
771
762
{
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);
773
765
774
766
$ optionsData = [
775
767
'type ' => 0 ,
@@ -783,17 +775,12 @@ public function testGetSwatchesByOptionsIdIf3()
783
775
$ swatchMock ->expects ($ this ->at (1 ))->method ('offsetGet ' )->with ('store_id ' )->willReturn (0 );
784
776
$ swatchMock ->expects ($ this ->at (2 ))->method ('offsetGet ' )->with ('store_id ' )->willReturn (0 );
785
777
$ swatchMock ->expects ($ this ->at (3 ))->method ('offsetGet ' )->with ('option_id ' )->willReturn (35 );
786
- $ swatchMock ->expects ($ this ->at (4 ))->method ('getData ' )->with ('' )->willReturn ($ optionsData );
787
778
788
- $ swatchCollectionMock = $ this ->objectManager ->getCollectionMock (
789
- Collection::class,
790
- [
791
- $ swatchMock ,
792
- ]
793
- );
779
+ $ swatchCollectionMock = $ this ->createMock (Collection::class);
794
780
$ this ->swatchCollectionFactoryMock ->method ('create ' )->willReturn ($ swatchCollectionMock );
795
781
796
782
$ swatchCollectionMock ->method ('addFilterByOptionsIds ' )->with ([35 ])->will ($ this ->returnSelf ());
783
+ $ swatchCollectionMock ->expects ($ this ->once ())->method ('getData ' )->willReturn ([$ swatchMock ]);
797
784
798
785
$ storeMock = $ this ->createMock (\Magento \Store \Model \Store::class);
799
786
$ this ->storeManagerMock ->method ('getStore ' )->willReturn ($ storeMock );
0 commit comments