Пример #1
0
 public function testItAddsTypeThatIsNotYetInStorage()
 {
     $this->generator->shouldReceive('getTypeClassName')->with(FooBar::class)->andReturn('__Enum__\\' . FooBarType::class);
     $this->storage->shouldReceive('exists')->with('__Enum__\\' . FooBarType::class)->andReturn(false);
     $this->generator->shouldNotReceive('generate')->with('foobar', FooBar::class)->andReturn(new GenerationResult('__Enum__\\' . FooBarType::class, 'type_class_content'));
     $this->storage->shouldReceive('save')->with('__Enum__\\' . FooBarType::class, 'type_class_content');
     $this->assertFalse(Type::hasType('foobar'));
     $this->sut->addType('foobar', FooBar::class);
     $map = Type::getTypesMap();
     $this->assertEquals('__Enum__\\' . FooBarType::class, $map['foobar']);
 }
Пример #2
0
 /**
  * @param string $typeName
  * @param string $enumClass
  * @throws EnumException
  * @throws \Doctrine\DBAL\DBALException
  */
 public function addType($typeName, $enumClass)
 {
     if ($this->hasType($typeName)) {
         return;
     }
     if (!preg_match('/^[A-Za-z0-9_]+$/', $typeName)) {
         throw new EnumException('Enum type name contains invalid characters. Only letters, numbers and underscores are allowed.');
     }
     if (!is_subclass_of($enumClass, Enum::class)) {
         throw new EnumException("{$enumClass} is not a valid enum class.");
     }
     $typeClass = $this->typeGenerator->getTypeClassName($enumClass);
     if (!$this->typeStorage->exists($typeClass)) {
         $result = $this->typeGenerator->generate($typeName, $enumClass);
         $this->typeStorage->save($result->getClassName(), $result->getContent());
     }
     Type::addType($typeName, $typeClass);
 }
 public function testItReturnsFalseIfClassDoesNotExistsInStorage()
 {
     $this->storage->shouldReceive('exists')->with('some_class')->andReturn(false);
     $this->assertFalse($this->sut->loadClass('some_class'));
 }