* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class CruncherTestUnitProducer extends BaseProducer implements UnitProducer, Registerable {
+class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, Registerable {
/**
* Protected constructor
*
* Produces some test units and pushes them onto the queue
*
* @return void
- * @todo 0% done
+ * @todo ~30% done
*/
public function produceUnits () {
- $this->partialStub('Please implement this method.');
+ // First get a database wrapper because we want to permanently store test units
+ $wrapperInstance = ObjectFactory::createObjectByConfiguredName('cruncher_unit_db_wrapper_class');
+
+ // Now get a search instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Add criteria for looking up already created and available test units
+ $searchInstance->addCriteria(CruncherUnitDatabaseWrapper::DB_COLUMN_UNIT_TYPE, BaseUnitProducer::UNIT_TYPE_TEST_UNIT);
+ $searchInstance->addCriteria(CruncherUnitDatabaseWrapper::DB_COLUMN_UNIT_STATUS, BaseUnitProducer::UNIT_STATUS_AVAILABLE);
+ $searchInstance->setLimit($this->getConfigInstance()->getConfigEntry('cruncher_test_unit_max_count'));
+
+ // Search for our units
+ $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
+
+ // Do we have some entries?
+ if ($resultInstance->next()) {
+ // Entries found
+ // @TODO Unfinished work here
+ $this->debugInstance();
+ } else {
+ // No entries found, so generate some. First we need a very secret message (a random string) ...
+ $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
+ $secretMessage = base64_encode($rngInstance->randomString($this->getConfigInstance()->getConfigEntry('cruncher_random_secret_message_length')));
+
+ // Second, we need a secret key
+ $secretKey = $rngInstance->randomString($this->getConfigInstance()->getConfigEntry('cruncher_random_secret_key_length'));
+
+ // Now encrypt the message with our key and a good (strong) cipher
+ $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+ $encryptedMessage = base64_encode($cryptoInstance->encryptString($secretMessage, $secretKey));
+
+ // Make sure the secret key and message are removed from memory
+ unset($secretKey);
+ unset($secretMessage);
+ die($encryptedMessage);
+ }
}
}