예제 #1
0
 public function testToArray()
 {
     $p = new Parameter('test');
     $p2 = new Parameter('test2');
     $p2->setValue('test');
     $pc = new ParameterCollection();
     $pc->addParameter($p);
     $pc->addParameter($p2);
     $this->assertEquals(array('test' => null, 'test2' => 'test'), $pc->toArray());
 }
예제 #2
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testValueValidatorException()
 {
     $p = new Parameter('test');
     $this->assertEquals(null, $p->getValue());
     $p->setValue('test');
     $this->assertEquals('test', $p->getValue());
     $validatorMock = $this->getMock('\\hergot\\databroker\\DataAdapter\\ValidatorInterface');
     $validatorMock->expects($this->once())->method('isValid')->will($this->returnCallback(function ($value) {
         $this->assertEquals('test', $value);
         return false;
     }));
     $p->setValidator($validatorMock);
     $p->setValue('test');
 }
예제 #3
0
 public function testExecutePlugin()
 {
     $adapterMock = $this->getMock('\\hergot\\databroker\\DataAdapter\\DataAdapterInterface', array('fetch', 'getParameters'));
     $adapterMock->expects($this->once())->method('getParameters')->will($this->returnCallback(function (ParameterCollection $parameterCollection) {
         $parameter = new Parameter('parameter');
         $parameter->setDefaultValue('test');
         $parameterCollection->addParameter($parameter);
     }));
     $loaderMock = $this->getMock('\\hergot\\databroker\\DataAdapter\\DataAdapterLoaderInterface', array('instantiate'));
     $loaderMock->expects($this->once())->method('instantiate')->will($this->returnCallback(function ($name) use($adapterMock) {
         $this->assertEquals('testAdapter', $name);
         return $adapterMock;
     }));
     $pluginMock = $this->getMock('\\hergot\\databroker\\Plugin\\PluginInterface');
     $pluginMock->expects($this->once())->method('runBeforeExecute')->will($this->returnCallback(function (DataAdapterInterface $dataAdapter, array $parameters, $result) use($adapterMock) {
         $this->assertEquals($adapterMock, $dataAdapter);
         $this->assertEquals(array('parameter' => 'test'), $parameters);
         $this->assertEquals(null, $result);
         return 'test';
     }));
     $pluginMock->expects($this->once())->method('runAfterExecute')->will($this->returnCallback(function (DataAdapterInterface $dataAdapter, array $parameters, $result, \Exception $exception = null) use($adapterMock) {
         $this->assertEquals($adapterMock, $dataAdapter);
         $this->assertEquals(array('parameter' => 'test'), $parameters);
         $this->assertEquals('test', $result);
         $this->assertEquals(null, $exception);
         return 'test2';
     }));
     $databroker = new DataBroker($loaderMock);
     $databroker->addPlugin($pluginMock);
     $this->assertEquals('test2', $databroker->execute('testAdapter', array('parameter' => 'test')));
 }