Example #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']);
 }
Example #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;
 }
Example #3
0
 protected function getInvalidTypeValues()
 {
     return ['BigInt' => [new BigNumber(-1), new BigNumber('18446744073709551616')], 'Binary' => false, 'Blob' => false, 'Boolean' => 'not_a_bool', 'Date' => 'not_a_date', 'DateTime' => 'not_a_date', 'Decimal' => 1, 'DynamicField' => 'not_a_dynamic_field', 'Float' => 1, 'GeoPoint' => 'not_a_geo_point', 'IntEnum' => Priority::NORMAL(), 'Int' => [-1, 4294967296], 'MediumInt' => [-1, 16777216], 'MediumBlob' => false, 'MediumText' => false, 'Message' => EmailMessage::create(), 'MessageRef' => 'not_a_message_ref', 'Microtime' => microtime(), 'SignedBigInt' => [new BigNumber('-9223372036854775809'), new BigNumber('9223372036854775808')], 'SignedMediumInt' => [-8388609, 8388608], 'SignedSmallInt' => [-32769, 32768], 'SignedTinyInt' => [-129, 128], 'SmallInt' => [-1, 65536], 'StringEnum' => Provider::AOL(), 'String' => false, 'Text' => false, 'TimeUuid' => 'not_a_time_uuid', 'Timestamp' => 'not_a_timestamp', 'TinyInt' => [-1, 256], 'Uuid' => 'not_a_uuid'];
 }