/**
  * Test creating a customer with absent required address fields
  */
 public function testCreateCustomerWithoutAddressRequiresException()
 {
     $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray($this->customerHelper->createSampleCustomerDataObject(), '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     foreach ($customerDataArray[Customer::KEY_ADDRESSES] as &$address) {
         $address[Address::FIRSTNAME] = null;
     }
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Save']];
     $requestData = ['customer' => $customerDataArray];
     try {
         $this->_webApiCall($serviceInfo, $requestData);
         $this->fail('Expected exception did not occur.');
     } catch (\Exception $e) {
         if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
             $expectedException = new InputException();
             $expectedException->addError(__('%fieldName is a required field.', ['fieldName' => Address::FIRSTNAME]));
             $this->assertInstanceOf('SoapFault', $e);
             $this->checkSoapFault($e, $expectedException->getRawMessage(), 'env:Sender', $expectedException->getParameters());
         } else {
             $this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
             $exceptionData = $this->processRestExceptionResult($e);
             $expectedExceptionData = ['message' => '%fieldName is a required field.', 'parameters' => ['fieldName' => Address::FIRSTNAME]];
             $this->assertEquals($expectedExceptionData, $exceptionData);
         }
     }
     try {
         $this->customerRegistry->retrieveByEmail($customerDataArray[Customer::EMAIL], $customerDataArray[Customer::WEBSITE_ID]);
         $this->fail('An expected NoSuchEntityException was not thrown.');
     } catch (NoSuchEntityException $e) {
         $exception = NoSuchEntityException::doubleField('email', $customerDataArray[Customer::EMAIL], 'websiteId', $customerDataArray[Customer::WEBSITE_ID]);
         $this->assertEquals($exception->getMessage(), $e->getMessage(), 'Exception message does not match expected message.');
     }
 }
Example #2
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @magentoAppArea adminhtml
  */
 public function testRemoveByEmail()
 {
     $customer = $this->_model->retrieve(self::CUSTOMER_ID);
     $this->assertInstanceOf('\\Magento\\Customer\\Model\\Customer', $customer);
     $customer->delete();
     $this->_model->removeByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
     $this->_model->retrieveByEmail(self::CUSTOMER_EMAIL, $customer->getWebsiteId());
 }
 public function testRemoveByEmail()
 {
     $this->customer->expects($this->exactly(2))->method('loadByEmail')->with(self::CUSTOMER_EMAIL)->will($this->returnValue($this->customer));
     $this->customer->expects($this->any())->method('getId')->will($this->returnValue(self::CUSTOMER_ID));
     $this->customer->expects($this->any())->method('getEmail')->will($this->returnValue(self::CUSTOMER_EMAIL));
     $this->customer->expects($this->any())->method('getWebsiteId')->will($this->returnValue(self::WEBSITE_ID));
     $this->customer->expects($this->any())->method('setEmail')->will($this->returnValue($this->customer));
     $this->customer->expects($this->any())->method('setWebsiteId')->will($this->returnValue($this->customer));
     $this->customerFactory->expects($this->exactly(2))->method('create')->will($this->returnValue($this->customer));
     $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
     $this->assertEquals($this->customer, $actual);
     $this->customerRegistry->removeByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
     $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
     $this->assertEquals($this->customer, $actual);
 }
 /**
  * {@inheritdoc}
  */
 public function get($email, $websiteId = null)
 {
     $customerModel = $this->customerRegistry->retrieveByEmail($email, $websiteId);
     return $customerModel->getDataModel();
 }
 /**
  * {@inheritdoc}
  */
 public function deleteCustomerByEmail($customerEmail, $websiteId = null)
 {
     $customerModel = $this->customerRegistry->retrieveByEmail($customerEmail, $websiteId);
     $customerId = $customerModel->getId();
     $customerModel->delete();
     $this->customerRegistry->remove($customerId);
     return true;
 }