Exemplo n.º 1
0
 public function testEnumInList()
 {
     $message = EmailMessage::create()->addToList('enum_in_list', [Provider::AOL(), Provider::AOL(), Provider::GMAIL(), Provider::GMAIL()]);
     $result = array_map(function (Enum $enum) {
         return $enum->getValue();
     }, $message->get('enum_in_list'));
     $this->assertCount(4, $result);
     $this->assertSame($result, ['aol', 'aol', 'gmail', 'gmail']);
 }
Exemplo n.º 2
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     $schema = new Schema('pbj:gdbots:tests.pbj:fixtures:email-message:1-0-0', __CLASS__, [Fb::create('id', T\TimeUuidType::create())->required()->build(), Fb::create('from_name', T\StringType::create())->build(), Fb::create('from_email', T\StringType::create())->required()->format('email')->build(), Fb::create('subject', T\StringType::create())->withDefault(function (EmailMessage $message = null) {
         if (!$message) {
             return null;
         }
         return implode(',', $message->get('labels', [])) . ' test';
     })->build(), Fb::create('body', T\StringType::create())->build(), Fb::create('priority', T\IntEnumType::create())->required()->className('Gdbots\\Tests\\Pbj\\Fixtures\\Enum\\Priority')->withDefault(Priority::NORMAL)->build(), Fb::create('sent', T\BooleanType::create())->build(), Fb::create('date_sent', T\DateTimeType::create())->build(), Fb::create('microtime_sent', T\MicrotimeType::create())->build(), Fb::create('provider', T\StringEnumType::create())->className('Gdbots\\Tests\\Pbj\\Fixtures\\Enum\\Provider')->withDefault(Provider::GMAIL())->build(), Fb::create('labels', T\StringType::create())->format(Format::HASHTAG())->asASet()->build(), Fb::create('nested', T\MessageType::create())->className('Gdbots\\Tests\\Pbj\\Fixtures\\NestedMessage')->build(), Fb::create('enum_in_set', T\StringEnumType::create())->className('Gdbots\\Tests\\Pbj\\Fixtures\\Enum\\Provider')->asASet()->build(), Fb::create('enum_in_list', T\StringEnumType::create())->className('Gdbots\\Tests\\Pbj\\Fixtures\\Enum\\Provider')->asAList()->build(), Fb::create('any_of_message', T\MessageType::create())->className('Gdbots\\Pbj\\Message')->asAList()->build(), Fb::create('dynamic_fields', T\DynamicFieldType::create())->asAList()->build()]);
     MessageResolver::registerSchema($schema);
     return $schema;
 }