public function testGetAuthenticatedCustomer()
 {
     $phoneNumber = new PhoneNumber();
     $phoneNumber->setType('Home')->setCountryCode('1')->setNumber('12345678');
     $user = new User();
     $user->setId(1)->setName('John Doe')->setEmail('*****@*****.**');
     $customer = new Customer();
     $customer->setId(1)->setAddress('Some rd. 1')->setCity('Some City')->setPostalCode('1234')->setCountry('Some Country')->setPhoneNumbers([$phoneNumber])->setUser($user);
     $customerArray = ['id' => 1, 'name' => 'John Doe', 'address' => 'Some rd. 1', 'city' => 'Some City', 'postalCode' => '1234', 'country' => 'Some Country', 'email' => '*****@*****.**', 'phoneNumbers' => [['type' => 'Home', 'countryCode' => '1', 'number' => '12345678']], 'balance' => 100];
     $client = $this->createMock(Client::class);
     $client->expects($this->once())->method('get')->with($this->equalTo('/customer'))->will($this->returnValue($customerArray));
     $hydrator = $this->getMockBuilder(APIHydrator::class)->disableOriginalConstructor()->getMock();
     $hydrator->expects($this->once())->method('hydrate')->with($this->equalTo($customerArray), $this->equalTo(null))->will($this->returnValue($customer));
     $service = new CustomerService($client, $hydrator, new Collection());
     $this->assertSame($customer, $service->getAuthenticatedCustomer());
 }
예제 #2
0
 public function extractProvider()
 {
     $builder = new DI\ContainerBuilder();
     $builder->addDefinitions('config/di.php');
     $di = $builder->build();
     return [[$di->get('ProductHydrator'), function () {
         $obj = new Product();
         $obj->setId(1)->setName('Test')->setDescription('Test descr')->setPrice(99.95)->setUnit('Kg')->setSubjectToVat(true);
         return $obj;
     }, ['name' => 'Test', 'description' => 'Test descr', 'price' => 99.95, 'unit' => 'Kg', 'subjectToVat' => true]], [$di->get('PhoneNumberHydrator'), function () {
         $obj = new PhoneNumber();
         $obj->setType('Home')->setCountryCode('1')->setNumber('12345678');
         return $obj;
     }, ['type' => 'Home', 'countryCode' => '1', 'number' => '12345678']], [$di->get('UserHydrator'), function () {
         $obj = new User();
         $obj->setId(1)->setName('John Doe')->setEmail('*****@*****.**')->setRole('customer')->setEmailConfirmed(true);
         return $obj;
     }, ['name' => 'John Doe', 'email' => '*****@*****.**', 'role' => 'customer']], [$di->get('CustomerHydrator'), function () {
         $phoneNumbers = [];
         $pObj = new PhoneNumber();
         $pObj->setType('Home')->setCountryCode('1')->setNumber('12345678');
         $phoneNumbers[] = $pObj;
         $user = new User();
         $user->setId(1)->setName('John Doe')->setEmail('*****@*****.**')->setRole('customer')->setEmailConfirmed(true);
         $obj = new Customer();
         $obj->setId(1)->setAddress('Some rd. 1')->setCity('Some City')->setPostalCode('1234')->setCountry('Some Country')->setPhoneNumbers($phoneNumbers)->setUser($user);
         return $obj;
     }, ['address' => 'Some rd. 1', 'city' => 'Some City', 'postalCode' => '1234', 'country' => 'Some Country', 'phoneNumbers' => [['type' => 'Home', 'countryCode' => '1', 'number' => '12345678']]]], [$di->get('TimeslotHydrator'), function () {
         $phoneNumbers = [];
         $pObj = new PhoneNumber();
         $pObj->setType('Home')->setCountryCode('1')->setNumber('12345678');
         $phoneNumbers[] = $pObj;
         $user = new User();
         $user->setId(1)->setName('John Doe')->setEmail('*****@*****.**')->setRole('customer')->setEmailConfirmed(true);
         $cObj = new Customer();
         $cObj->setId(1)->setAddress('Some rd. 1')->setCity('Some City')->setPostalCode('1234')->setCountry('Some Country')->setPhoneNumbers($phoneNumbers)->setUser($user);
         $obj = new Timeslot();
         $obj->setId(1)->setCustomer($cObj)->setStartsAt(new DateTime('2015-01-01T00:00:00Z'))->setEndsAt(new DateTime('2015-01-01T00:30:00Z'))->setCost(1)->setDuration(30)->setActive(false);
         return $obj;
     }, ['startsAt' => '2015-01-01T00:00:00+00:00', 'endsAt' => '2015-01-01T00:30:00+00:00']], [$di->get('InvoiceItemHydrator'), function () {
         $pObj = new Product();
         $pObj->setId(1)->setName('Test')->setDescription('Test descr')->setPrice(99.95)->setUnit('Kg')->setSubjectToVat(true);
         $obj = new InvoiceItem();
         $obj->setTitle('Test item')->setDescription('Item description')->setPrice(10.0)->setQuantity(2)->setUnit('Kg')->setSubjectToVat(true)->setTotal(20.0)->setProduct($pObj);
         return $obj;
     }, ['title' => 'Test item', 'description' => 'Item description', 'price' => 10.0, 'quantity' => 2, 'unit' => 'Kg', 'subjectToVat' => true]], [$di->get('InvoiceHydrator'), function () {
         $phoneNumbers = [];
         $pObj = new PhoneNumber();
         $pObj->setType('Home')->setCountryCode('1')->setNumber('12345678');
         $phoneNumbers[] = $pObj;
         $user = new User();
         $user->setId(1)->setName('John Doe')->setEmail('*****@*****.**')->setRole('customer')->setEmailConfirmed(true);
         $cObj = new Customer();
         $cObj->setId(1)->setAddress('Some rd. 1')->setCity('Some City')->setPostalCode('1234')->setCountry('Some Country')->setPhoneNumbers($phoneNumbers)->setUser($user);
         $items = [];
         $pObj = new Product();
         $pObj->setId(1)->setName('Test')->setDescription('Test descr')->setPrice(99.95)->setUnit('Kg')->setSubjectToVat(true);
         $iObj = new InvoiceItem();
         $iObj->setTitle('Test item')->setDescription('Item description')->setPrice(10.0)->setQuantity(2)->setUnit('Kg')->setSubjectToVat(true)->setTotal(20.0)->setProduct($pObj);
         $items[] = $iObj;
         $obj = new Invoice();
         $obj->setId(1)->setCustomer($cObj)->setName('John Doe')->setAddress('Some rd. 1')->setCity('Some City')->setPostalCode('1234')->setCountry('Some Country')->setItems($items)->setCreatedAt(new DateTime('2015-02-01T10:00:00Z'))->setApproved(true)->setCancelled(false)->setPaid(false)->setTotal(20.0)->setVatBase(20.0)->setVat(5.0);
         return $obj;
     }, ['name' => 'John Doe', 'address' => 'Some rd. 1', 'city' => 'Some City', 'postalCode' => '1234', 'country' => 'Some Country', 'items' => [['title' => 'Test item', 'description' => 'Item description', 'price' => 10.0, 'quantity' => 2, 'unit' => 'Kg', 'subjectToVat' => true]]]]];
 }