public function assertModelMatchesConfiguration(ModelInterface $model, $configuration = array()) { if (empty($configuration)) { $configuration = $this->configuration; } $this->assertSame($this->configuration['object'], $model->objectType); $this->assertSame($this->configuration['id'], $model->id); $this->assertSame($this->configuration['name'], $model->name); $this->assertSame($this->configuration['subject'], $model->subject); $this->assertSame($this->configuration['from_email'], $model->fromEmail); $this->assertSame($this->configuration['from_name'], $model->fromName); $template = ModelFactory::create($this->configuration['template']); $this->assertEquals($template, $model->template); $this->assertSame($this->configuration['status'], $model->status); $this->assertSame($this->configuration['status_id'], $model->statusId); $this->assertSame($this->configuration['status_label'], $model->statusLabel); $this->assertSame($this->configuration['sent_at'], $model->sentAt); $this->assertSame($this->configuration['send_time'], $model->sendTime); $created = new \DateTime($this->configuration['created']); $this->assertEquals($created, $model->created); $updated = new \DateTime($this->configuration['updated']); $this->assertEquals($updated, $model->updated); $this->assertEquals($this->configuration['num_recipients'], $model->numRecipients); $this->assertEquals($this->configuration['is_segmented'], $model->isSegmented); $this->assertEquals($this->configuration['campaign_type'], $model->campaignType); $lists = []; foreach ($configuration['lists'] as $list) { $lists[] = ModelFactory::create($list); } $this->assertEquals($lists, $model->lists); }
/** * Register our model factory creation with the container. */ protected function registerModelFactoryCreate(Container $container) { $self = $this; $container['model.factory'] = $container->factory(function ($c) use($self) { $configuration = $c['model.factory.params']['configuration']; $type = $c['model.factory.params']['type']; $model = ModelFactory::create($configuration, $type); $self->registerModelFactoryDefaultParams($c); return $model; }); }
public function testModelCreation() { $this->assertInstanceOf(EmptyModel::class, ModelFactory::create([])); $person_configuration = ['$email' => '*****@*****.**', '$first_name' => 'nothing']; $person = ModelFactory::create($person_configuration, 'person'); $this->assertInstanceOf(PersonModel::class, $person); $person_json = ModelFactory::createFromJson(json_encode($person_configuration), 'person'); $this->assertInstanceOf(PersonModel::class, $person_json); $this->assertEquals($person, $person_json); $person_1 = ModelFactory::callModelCreationMethod('create', $person_configuration, 'person'); $this->assertInstanceOf(PersonModel::class, $person_1); $this->assertEquals($person, $person_1); $person_json_1 = ModelFactory::callModelCreationMethod('createFromJson', json_encode($person_configuration), 'person'); $this->assertInstanceOf(PersonModel::class, $person_json_1); $this->assertEquals($person_json, $person_json_1); }
/** * Check if the specified members are in the list by email address. * * @param ListModel $list * The list for which to retrieve members. * @param array $emails * The emails to check are associated with the specified list. * * @return array * An array of MembershipModels associated with the specified list. */ public function checkMembersAreInList(ListModel $list, $emails) { $options = ['query' => ['email' => implode(',', $emails)]]; $response = $this->api->request('GET', $this->getResourcePath("{$list->listType}/{$list->id}/members"), $options); $page = ModelFactory::create(json_decode($response->getBody()->getContents(), TRUE), 'page'); return array_map(ModelFactory::class . '::create', $page->data); }
/** * Retrieve a specific page from Klaviyo. * * @param int $page * The page number to retrieve. * @param int $count * The number of items per page. * * @return array * An array of information that represents a page. */ public function getPage($resource, $page = 0, $count = 50, $query_parameters = []) { $options = ['query' => ['page' => $page, 'count' => $count] + $query_parameters]; $response = $this->getApi()->request('GET', $resource, $options); return ModelFactory::create(json_decode($response->getBody()->getContents(), TRUE), 'page'); }