Exemple #1
0
 /**
  * @covers Itkg\Batch\Factory::getBatch
  * @covers Itkg\Batch\Factory::getConfiguration
  */
 public function testGetBatch()
 {
     //cas du batch null -----------------------------------
     $batch = null;
     try {
         $this->object->getBatch($batch);
         $this->fail('getBatch doit renvoyer une exception Itkg\\Exception\\NotFoundException');
     } catch (\Exception $e) {
         $this->assertEquals($e->getMessage(), "Le batch  n'existe pas car la classe \\Batch\\ n'est pas définie");
         $this->assertEquals('UnexpectedValueException', get_class($e));
     }
     //cas du batch qui n'existe pas -----------------------------------
     $batch = 'test';
     try {
         $this->object->getBatch($batch);
         $this->fail('getBatch doit renvoyer une exception Itkg\\Exception\\NotFoundException');
     } catch (\Exception $e) {
         $this->assertEquals($e->getMessage(), "Le batch test n'existe pas car la classe Test\\Batch\\Test n'est pas définie");
         $this->assertEquals('UnexpectedValueException', get_class($e));
     }
     //cas OK -----------------------------------
     $batch = 'MY_BATCH';
     try {
         $this->object->getBatch($batch);
     } catch (\Exception $e) {
         $this->fail('getBatch ne doit pas renvoyer d\'exception' . $e->getMessage());
     }
     //cas de la config qui n'existe pas -----------------------------------
     $batch = 'MY_BATCH';
     \Itkg\Batch::$config['MY_BATCH']['configuration'] = null;
     try {
         $this->object->getBatch($batch);
     } catch (\Exception $e) {
         $this->fail('getBatch ne doit pas renvoyer une exception ' . $e->getMessage());
     }
 }
Exemple #2
0
 /**
  * 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() . ' ');
 }