Exemplo n.º 1
0
 public function testExtractWithMissingKey()
 {
     $expData = ['name' => 'A product'];
     $product = new Product();
     $product->setName('A product');
     $hydrator = new APIHydrator(['id', 'name'], new Product());
     $data = $hydrator->extract($product);
     $this->assertSame($expData, $data);
 }
Exemplo n.º 2
0
return [Entity\CollectionInterface::class => DI\object(Entity\Collection::class), Entity\SearchCollectionInterface::class => DI\object(Entity\SearchCollection::class), Entity\PhoneNumberInterface::class => DI\object(Entity\PhoneNumber::class), Entity\UserInterface::class => DI\object(Entity\User::class), Entity\CustomerInterface::class => DI\object(Entity\Customer::class), Entity\ProductInterface::class => DI\object(Entity\Product::class), Entity\InvoiceInterface::class => DI\object(Entity\Invoice::class), Entity\InvoiceItemInterface::class => DI\object(Entity\InvoiceItem::class), Entity\TimeslotInterface::class => DI\object(Entity\Timeslot::class), 'api.base_url' => 'https://api.baekkelundhundepension.dk/', ClientInterface::class => DI\object(Client::class)->constructor(DI\get('api.base_url')), 'oauth2.client_id' => '', 'oauth2.client_secret' => '', 'oauth2.redirect_uri' => '', 'oauth2.scopes' => ['user', 'users', 'customer', 'customers', 'products', 'invoices', 'timeslots', 'access_key_read'], 'oauth2.base_url' => 'https://api.baekkelundhundepension.dk', 'oauth2.auth_uri' => '/oauth/authorize', 'oauth2.token_uri' => '/oauth/token', 'OAuth2Provider' => function (ContainerInterface $c) {
    $p = new GenericProvider(['clientId' => $c->get('oauth2.client_id'), 'clientSecret' => $c->get('oauth2.client_secret'), 'redirectUri' => $c->get('oauth2.redirect_uri'), 'urlAuthorize' => $c->get('oauth2.base_url') . $c->get('oauth2.auth_uri'), 'urlAccessToken' => $c->get('oauth2.base_url') . $c->get('oauth2.token_uri'), 'urlResourceOwnerDetails' => '', 'scopes' => $c->get('oauth2.scopes'), 'scopeSeparator' => ' ', 'accessTokenResourceOwnerId' => 'uid', 'responseResourceOwnerId' => 'uid']);
    return $p;
}, 'phone_number.keys' => ['type', 'countryCode', 'number'], 'product.keys' => ['name', 'description', 'price', 'unit', 'subjectToVat'], 'user.keys' => ['name', 'email', 'role'], 'customer.keys' => ['address', 'city', 'postalCode', 'country', 'phoneNumbers'], 'invoice.keys' => ['name', 'address', 'city', 'postalCode', 'country', 'items'], 'invoice_item.keys' => ['title', 'description', 'price', 'quantity', 'unit', 'subjectToVat'], 'timeslot.keys' => ['startsAt', 'endsAt'], 'collection.prototype' => DI\get(Entity\CollectionInterface::class), 'search_collection.prototype' => DI\get(Entity\SearchCollectionInterface::class), 'phone_number.prototype' => DI\get(Entity\PhoneNumberInterface::class), 'product.prototype' => DI\get(Entity\ProductInterface::class), 'user.prototype' => DI\get(Entity\UserInterface::class), 'customer.prototype' => DI\get(Entity\CustomerInterface::class), 'invoice.prototype' => DI\get(Entity\InvoiceInterface::class), 'invoice_item.prototype' => DI\get(Entity\InvoiceItemInterface::class), 'timeslot.prototype' => DI\get(Entity\TimeslotInterface::class), 'PhoneNumberHydrator' => function (ContainerInterface $c) {
    return new APIHydrator($c->get('phone_number.keys'), $c->get('phone_number.prototype'));
}, 'ProductHydrator' => function (ContainerInterface $c) {
    return new APIHydrator($c->get('product.keys'), $c->get('product.prototype'));
}, 'UserHydrator' => function (ContainerInterface $c) {
    return new APIHydrator($c->get('user.keys'), $c->get('user.prototype'));
}, 'CustomerHydrator' => function (ContainerInterface $c) {
    $h = new APIHydrator($c->get('customer.keys'), $c->get('customer.prototype'));
    $h->setStrategy('phoneNumbers', new CollectionStrategy($c->get('PhoneNumberHydrator')));
    $h->setStrategy('user', new HydratorStrategy($c->get('UserHydrator')));
    return $h;
}, 'InvoiceHydrator' => function (ContainerInterface $c) {
    $h = new APIHydrator($c->get('invoice.keys'), $c->get('invoice.prototype'));
    $h->setStrategy('createdAt', new DateStrategy());
    $h->setStrategy('customer', new HydratorStrategy($c->get('CustomerHydrator')));
    $h->setStrategy('items', new CollectionStrategy($c->get('InvoiceItemHydrator')));
    return $h;
}, 'InvoiceItemHydrator' => function (ContainerInterface $c) {
    $h = new APIHydrator($c->get('invoice_item.keys'), $c->get('invoice_item.prototype'));
    $h->setStrategy('product', new HydratorStrategy($c->get('ProductHydrator')));
    return $h;
}, 'TimeslotHydrator' => function (ContainerInterface $c) {
    $h = new APIHydrator($c->get('timeslot.keys'), $c->get('timeslot.prototype'));
    $h->setStrategy('startsAt', new DateStrategy());
    $h->setStrategy('endsAt', new DateStrategy());
    $h->setStrategy('customer', new HydratorStrategy($c->get('CustomerHydrator')));
    return $h;
}, Service\CustomerService::class => DI\object()->constructorParameter('hydrator', DI\get('CustomerHydrator')), Service\ProductService::class => DI\object()->constructorParameter('hydrator', DI\get('ProductHydrator')), Service\InvoiceService::class => DI\object()->constructorParameter('hydrator', DI\get('InvoiceHydrator')), Service\TimeslotService::class => DI\object()->constructorParameter('hydrator', DI\get('TimeslotHydrator'))];