/** * Constructeur * * @param array $args * @throws \Itkg\Exception\NotFoundException */ public function __construct(array $args = array()) { // Si aucun argument n'est passé, on lève une exception if (empty($args)) { throw new \Exception('Le nom du batch n\'a pas été renseigné'); } // On récupère la clé du batch $this->name = $args[0]; // On récupère le batch (Permet de vérifier que le batch existe // et de récupérer sa configuration) $this->batch = Factory::getBatch($this->name); // Initialisation de la configuration $this->getConfiguration(); // Initialisation de l'ID qui sera utilisé tout au long du process $this->setId(IdGenerator::generate() . ' - ' . $this->getConfiguration()->getIdentifier() . $this->batch->getConfiguration()->getIdentifier() . ' '); }
/** * @covers Itkg\Log\IdGenerator::generate * */ public function testGenerate() { $id = IdGenerator::generate(); //'Y-m-d H:i:s' format de la date $temp = explode(' ', $id); $date = $temp[0] . ' ' . $temp[1]; $this->assertNotNull(strptime($date, '%D %H:%M:%S')); $id = $temp[2]; $this->assertEquals('#', substr($id, 0, 1)); $value = substr($id, 1); $this->assertLessThanOrEqual(1000000, $value); $this->assertGreaterThanOrEqual(1, $value); $id = IdGenerator::generate(10, 100, '_', false); $this->assertEquals('_', substr($id, 0, 1)); $value = substr($id, 1); $this->assertLessThanOrEqual(100, $value); $this->assertGreaterThanOrEqual(10, $value); }
/** * génère le log id * * @return int */ protected function generateId() { return IdGenerator::generate(); }