public function testSaveSettings() { $namespace = 'some_namespace'; $storedSettingsArray = ['color' => 'red', 'interval' => 10, 'last_update' => '2014-06-01']; $namespaceParameters = []; foreach ($storedSettingsArray as $name => $value) { $parameter = new Parameter(); $parameter->setName($name); $parameter->setValue($value); $parameter->setNamespace($namespace); $namespaceParameters[] = $parameter; } $hydrator = new Hydrator\ArraySerializable(); $newSettingsArray = ['color' => 'black', 'interval' => 12, 'height' => 12, 'width' => 6]; $newSettings = new ArrayObject(); $hydrator->hydrate($newSettingsArray, $newSettings); $namespaceHydratorProvider = $this->getMock('HtSettingsModule\\Service\\NamespaceHydratorProviderInerface'); $namespaceHydratorProvider->expects($this->once())->method('getHydrator')->with($namespace)->will($this->returnValue($hydrator)); $settingsMapper = $this->getMock('HtSettingsModule\\Mapper\\SettingsMapperInterface'); $settingsMapper->expects($this->at(0))->method('findByNamespace')->with($namespace)->will($this->returnValue($namespaceParameters)); //var_dump($settingsMapper->findByNamespace($namespace));exit(); $updateParameter1 = Parameter::create($namespace, 'color', 'black'); $settingsMapper->expects($this->at(1))->method('updateParameter')->with($updateParameter1); $updateParameter2 = Parameter::create($namespace, 'interval', 12); $settingsMapper->expects($this->at(2))->method('updateParameter')->with($updateParameter2); $insertParameter1 = Parameter::create($namespace, 'height', 12); $settingsMapper->expects($this->at(3))->method('insertParameter')->with($insertParameter1); $insertParameter2 = Parameter::create($namespace, 'width', 6); $settingsMapper->expects($this->at(4))->method('insertParameter')->with($insertParameter2); $options = new ModuleOptions(); $settingsService = new SettingsService($options, $settingsMapper, $namespaceHydratorProvider); $settingsService->save($newSettings, $namespace); }
public function testCreate() { $parameter = Parameter::create('theme', 'color', 'red'); $this->assertEquals('theme', $parameter->getNamespace()); $this->assertEquals('color', $parameter->getName()); $this->assertEquals('red', $parameter->getValue()); }
public function testFindParameter() { $adapter = $this->getMock('HtSettingsModule\\Mapper\\FileSystem\\Adapter\\AdapterInterface'); $adapter->expects($this->any())->method('getFileName')->will($this->returnValue('football.json')); $fileSystem = $this->getMock('League\\Flysystem\\FilesystemInterface'); $mapper = new FileSystemMapper($fileSystem, new Parameter(), $adapter); $fileSystem->expects($this->exactly(2))->method('has')->with('football.json')->will($this->returnValue(true)); $arrData = ['team' => 'Liverpool', 'boot' => 'Addidas']; $jsonContents = Json::encode($arrData); $fileSystem->expects($this->exactly(2))->method('read')->with('football.json')->will($this->returnValue($jsonContents)); $adapter->expects($this->exactly(2))->method('onRead')->with($jsonContents)->will($this->returnValue($arrData)); $parameter = new Parameter(); $parameter->setName('team'); $parameter->setNamespace('football'); $newParameter = $mapper->findParameter($parameter); $this->assertEquals('Liverpool', $parameter->getValue()); $newParameter = $mapper->findParameter('football', 'team'); $this->assertEquals('Liverpool', $parameter->getValue()); $this->setExpectedException('HtSettingsModule\\Exception\\InvalidArgumentException'); $mapper->findParameter([]); }