getClassMapByType() public method

There are 3 built-in types that must have a class name : - self::TYPE_WORKFLOW - self::TYPE_STATUS - self::TYPE_TRANSITION The constructor ensure that if a class map is provided, it include class names for these 3 types. Failure to do so will result in an exception being thrown by the constructor.
public getClassMapByType ( string $type ) : string | null
$type string Type name
return string | null | null the class name or NULL if no class name is found forthis type.
 public function testConstructSuccess()
 {
     $this->specify('Workflow source construct default', function () {
         $src = new WorkflowFileSource();
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_WORKFLOW))->equals('raoul2000\\workflow\\base\\Workflow');
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_STATUS))->equals('raoul2000\\workflow\\base\\Status');
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_TRANSITION))->equals('raoul2000\\workflow\\base\\Transition');
         expect($src->getDefinitionCache())->equals(null);
         expect($src->getDefinitionLoader())->notNull();
     });
     $this->specify('Workflow source construct with class map', function () {
         $src = new WorkflowFileSource(['classMap' => [WorkflowFileSource::TYPE_WORKFLOW => 'my\\namespace\\Workflow', WorkflowFileSource::TYPE_STATUS => 'my\\namespace\\Status', WorkflowFileSource::TYPE_TRANSITION => 'my\\namespace\\Transition']]);
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_WORKFLOW))->equals('my\\namespace\\Workflow');
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_STATUS))->equals('my\\namespace\\Status');
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_TRANSITION))->equals('my\\namespace\\Transition');
     });
     $this->specify('Workflow source construct with cache', function () {
         // initialized by array
         $src = new WorkflowFileSource(['definitionCache' => ['class' => 'yii\\caching\\FileCache']]);
         expect_that($src->getDefinitionCache() instanceof yii\caching\FileCache);
         // initialized by component ID
         Yii::$app->set('myCache', ['class' => 'yii\\caching\\FileCache']);
         $src = new WorkflowFileSource(['definitionCache' => 'myCache']);
         expect_that($src->getDefinitionCache() instanceof yii\caching\FileCache);
         // initialized by object
         $cache = Yii::$app->get('myCache');
         Yii::$app->set('myCache', ['class' => 'yii\\caching\\FileCache']);
         $src = new WorkflowFileSource(['definitionCache' => $cache]);
         expect_that($src->getDefinitionCache() instanceof yii\caching\FileCache);
     });
 }
Esempio n. 2
0
 public function testClassMapStatus()
 {
     $this->specify('Replace default status class with custom one', function () {
         $src = new WorkflowFileSource(['definitionLoader' => ['class' => 'raoul2000\\workflow\\source\\file\\PhpClassLoader', 'namespace' => 'tests\\codeception\\unit\\models'], 'classMap' => [WorkflowFileSource::TYPE_STATUS => 'tests\\codeception\\unit\\models\\MyStatus']]);
         verify($src->getClassMapByType(WorkflowFileSource::TYPE_WORKFLOW))->equals('raoul2000\\workflow\\base\\Workflow');
         verify($src->getClassMapByType(WorkflowFileSource::TYPE_STATUS))->equals('tests\\codeception\\unit\\models\\MyStatus');
         verify($src->getClassMapByType(WorkflowFileSource::TYPE_TRANSITION))->equals('raoul2000\\workflow\\base\\Transition');
         $status = $src->getStatus('Item04Workflow/A');
         expect(get_class($status))->equals('tests\\codeception\\unit\\models\\MyStatus');
     });
 }