public function testSetCacheOptions() { $options = new ModuleOptions(); $cacheOptions = new CacheOptions(); $options->setCacheOptions($cacheOptions); $this->assertEquals($cacheOptions, $options->getCacheOptions()); $options->setCacheOptions(['enabled' => true]); $this->assertTrue(true, $options->getCacheOptions()->isEnabled()); $this->setExpectedException('HtSettingsModule\\Exception\\InvalidArgumentException'); $options->setCacheOptions(new \ArrayObject()); }
public function testGetSettingsFromRealSourceAndCreateCache() { $cacheOptions = new CacheOptions(); $cacheManager = new CacheManager($cacheOptions); $cacheOptions->setEnabled(true); $adapter = new \Zend\Cache\Storage\Adapter\Memory(); $cacheOptions->setAdapter($adapter); $options = new ModuleOptions(); $options->setCacheOptions($cacheOptions); $settingsMapper = $this->getMock('HtSettingsModule\\Mapper\\SettingsMapperInterface'); $namespaceHydratorProvider = $this->getMockBuilder('HtSettingsModule\\Service\\NamespaceHydratorProviderInerface')->disableOriginalConstructor()->getMock(); $settingsProvider = new SettingsProvider($options, $settingsMapper, $namespaceHydratorProvider); $namespaceOptions = new NamespaceOptions(['entity_class' => 'ArrayObject']); $namespaceHydratorProvider->expects($this->once())->method('getHydrator')->with('theme')->will($this->returnValue(new Hydrator\ArraySerializable())); $options->addNamespace($namespaceOptions, 'theme'); $settingsProvider->setCacheManager($cacheManager); $settingsMapper->expects($this->any())->method('findByNamespace')->will($this->returnValue([new Parameter('theme', 'color', 'red'), new Parameter('theme', 'font_size', 33)])); $settings = $settingsProvider->getSettings('theme'); $this->assertEquals('red', $settings['color']); $this->assertEquals(33, $settings['font_size']); $this->assertEquals($settings, $adapter->getItem('theme')); $settingsMapper->expects($this->any())->method('findByNamespace')->will($this->returnValue([])); $settings = $settingsProvider->getSettings('theme'); }