Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
WebsiteTest Class Reference
Inheritance diagram for WebsiteTest:

Public Member Functions

 setUp ()
 
 testGet ()
 

Detailed Description

Class WebsiteTest

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 22 of file WebsiteTest.php.

Member Function Documentation

◆ setUp()

setUp ( )

Definition at line 54 of file WebsiteTest.php.

55  {
56  $this->collectionFactory = $this->getMockBuilder(ScopedFactory::class)
57  ->disableOriginalConstructor()
58  ->setMethods(['create'])
59  ->getMockForAbstractClass();
60  $this->converter = $this->getMockBuilder(Converter::class)
61  ->disableOriginalConstructor()
62  ->getMock();
63  $this->websiteFactory = $this->getMockBuilder(\Magento\Store\Model\WebsiteFactory::class)
64  ->disableOriginalConstructor()
65  ->setMethods(['create'])
66  ->getMockForAbstractClass();
67  $this->website = $this->getMockBuilder(\Magento\Store\Model\Website::class)
68  ->disableOriginalConstructor()
69  ->getMock();
70  $this->defaultScopeReader = $this->getMockBuilder(DefaultScope::class)
71  ->disableOriginalConstructor()
72  ->getMock();
73  $this->websiteSource = new WebsiteSource(
74  $this->collectionFactory,
75  $this->converter,
76  $this->websiteFactory,
77  $this->defaultScopeReader
78  );
79  }

◆ testGet()

testGet ( )

Definition at line 81 of file WebsiteTest.php.

82  {
83  $scopeCode = 'myWebsite';
84  $expectedResult = [
85  'config/key1' => 'default_db_value1',
86  'config/key3' => 'default_db_value3',
87  ];
88  $this->websiteFactory->expects($this->once())
89  ->method('create')
90  ->willReturn($this->website);
91  $this->website->expects($this->once())
92  ->method('load')
93  ->with($scopeCode);
94  $this->website->expects($this->once())
95  ->method('getId')
96  ->willReturn(1);
97  $this->collectionFactory->expects($this->once())
98  ->method('create')
99  ->with(['scope' => ScopeInterface::SCOPE_WEBSITES, 'scopeId' => 1])
100  ->willReturn([
101  new DataObject(['path' => 'config/key1', 'value' => 'default_db_value1']),
102  new DataObject(['path' => 'config/key3', 'value' => 'default_db_value3']),
103  ]);
104  $this->defaultScopeReader->expects($this->once())
105  ->method('get')
106  ->willReturn([]);
107  $this->converter->expects($this->once())
108  ->method('convert')
109  ->with($expectedResult)
110  ->willReturnArgument(0);
111  $this->assertEquals($expectedResult, $this->websiteSource->get($scopeCode));
112  }

The documentation for this class was generated from the following file: