/** * @return void */ public function testRun() { /** @var $worker PHPUnit_Framework_MockObject_MockObject|jp_worker_Interface */ $worker = $this->getMock('jp_worker_Interface'); $worker->expects($this->exactly(5))->method('processItem')->with($this->isInstanceOf('ExampleData'))->will($this->returnValue(true)); /** @var $client PHPUnit_Framework_MockObject_MockObject|JobPoolIf */ $client = $this->getMock('JobPoolIf'); $client->expects($this->exactly(6))->method('acquire')->will($this->returnCallback(array($this, 'mockAcquire'))); $protocolFactory = new TBinaryProtocolFactory(); $transport = new TMemoryBuffer(); $protocol = $protocolFactory->getProtocol($transport); // Fill a mock queue backend for ($i = 0; $i < 5; $i++) { /** @var $job PHPUnit_Framework_MockObject_MockObject|Job */ $job = $this->getMock('Job'); $doc = new ExampleData(); $doc->language = 'php'; $doc->api = 'simple' . $i; $doc->format = 'thrift'; $doc->write($protocol); $message = $transport->read($transport->available()); $job->message = $message; $job->id = $i; $this->addToQueueBackend($job); } $consumer = new jp_consumer_Thrift('foo', array('client' => $client, 'poll_interval' => 0), $worker, 'ExampleData'); $this->assertEquals(5, $consumer->run()); }
/** * Receive post data from ExampleData edit form. * * Url: * * /example/edit/{id} * * @param Web $w */ function edit_POST(Web $w) { $p = $w->pathMatch("id"); if (isset($p['id'])) { $data = $w->Example->getDataForId($p['id']); } else { $data = new ExampleData($w); } $data->fill($_POST); // fill in validation step! $data->insertOrUpdate(); // go back to the list view $w->msg("ExampleData updated", "example/index"); }
/** * @return void */ public function testAdd() { $doc = new ExampleData(); $doc->language = 'php'; $doc->api = 'simple'; $doc->format = 'thrift'; $protocolFactory = new TBinaryProtocolFactory(); $transport = new TMemoryBuffer(); $protocol = $protocolFactory->getProtocol($transport); $doc->write($protocol); $message = $transport->read($transport->available()); /** @var $client PHPUnit_Framework_MockObject_MockObject|JobPoolIf */ $client = $this->getMock('JobPoolIf'); $client->expects($this->once())->method('add')->with($this->equalTo('foo'), $this->equalTo($message)); $consumer = new jp_producer_Thrift('foo', array('client' => $client)); $consumer->add($doc); }
public function postProcess() { if (Tools::isSubmit('submitAdd' . $this->table)) { // Create Object ExampleData $exemple_data = new ExampleData(); $exemple_data->exampledate = array(); $languages = Language::getLanguages(false); foreach ($languages as $language) { $exemple_data->name[$language['id_lang']] = Tools::getValue('name_' . $language['id_lang']); } // Save object if (!$exemple_data->save()) { $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token); } } }