|
18 | 18 | use Magento\Store\Model\StoreManagerInterface;
|
19 | 19 | use PHPUnit\Framework\TestCase;
|
20 | 20 |
|
| 21 | +class ConfigHelperTestable extends ConfigHelper |
| 22 | +{ |
| 23 | + /** expose protected methods for unit testing */ |
| 24 | + public function serialize(array $value): string |
| 25 | + { |
| 26 | + return parent::serialize($value); |
| 27 | + } |
| 28 | +} |
| 29 | + |
21 | 30 | class ConfigHelperTest extends TestCase
|
22 | 31 | {
|
23 |
| - protected ConfigHelper $configHelper; |
| 32 | + protected ConfigHelperTestable $configHelper; |
24 | 33 | protected ScopeConfigInterface $configInterface;
|
25 | 34 | protected WriterInterface $configWriter;
|
26 | 35 | protected StoreManagerInterface $storeManager;
|
@@ -51,7 +60,7 @@ public function setUp(): void
|
51 | 60 | $this->groupExcludedWebsiteRepository = $this->createMock(GroupExcludedWebsiteRepositoryInterface::class);
|
52 | 61 | $this->cookieHelper = $this->createMock(CookieHelper::class);
|
53 | 62 |
|
54 |
| - $this->configHelper = new ConfigHelper( |
| 63 | + $this->configHelper = new ConfigHelperTestable( |
55 | 64 | $this->configInterface,
|
56 | 65 | $this->configWriter,
|
57 | 66 | $this->storeManager,
|
@@ -79,4 +88,22 @@ public function testGetIndexPrefixWhenNull() {
|
79 | 88 | $this->configInterface->method('getValue')->willReturn(null);
|
80 | 89 | $this->assertEquals('', $this->configHelper->getIndexPrefix());
|
81 | 90 | }
|
| 91 | + |
| 92 | + public function testSerializerReturnsString() { |
| 93 | + $this->serializer->method('serialize')->willReturn('{"foo":"bar"}'); |
| 94 | + $array = [ |
| 95 | + 'foo' => 'bar' |
| 96 | + ]; |
| 97 | + $result = $this->configHelper->serialize($array); |
| 98 | + $this->assertEquals('{"foo":"bar"}', $result); |
| 99 | + } |
| 100 | + |
| 101 | + public function testSerializerFailure() { |
| 102 | + $this->serializer->method('serialize')->willReturn(false); |
| 103 | + $array = [ |
| 104 | + 'foo' => 'bar' |
| 105 | + ]; |
| 106 | + $result = $this->configHelper->serialize($array); |
| 107 | + $this->assertEquals('', $result); |
| 108 | + } |
82 | 109 | }
|
0 commit comments