CustomerRepositoryTest.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Model\ResourceModel;
  7. use Magento\Customer\Api\CustomerMetadataInterface;
  8. use Magento\Customer\Model\Customer\NotificationStorage;
  9. use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
  10. /**
  11. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  12. * @SuppressWarnings(PHPMD.TooManyFields)
  13. */
  14. class CustomerRepositoryTest extends \PHPUnit\Framework\TestCase
  15. {
  16. /**
  17. * @var \Magento\Customer\Model\CustomerFactory|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $customerFactory;
  20. /**
  21. * @var \Magento\Customer\Model\Data\CustomerSecureFactory|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. private $customerSecureFactory;
  24. /**
  25. * @var \Magento\Customer\Model\CustomerRegistry|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. private $customerRegistry;
  28. /**
  29. * @var \Magento\Customer\Model\ResourceModel\AddressRepository|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. private $addressRepository;
  32. /**
  33. * @var \Magento\Customer\Model\ResourceModel\Customer|\PHPUnit_Framework_MockObject_MockObject
  34. */
  35. private $customerResourceModel;
  36. /**
  37. * @var \Magento\Customer\Api\CustomerMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
  38. */
  39. private $customerMetadata;
  40. /**
  41. * @var \Magento\Customer\Api\Data\CustomerSearchResultsInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
  42. */
  43. private $searchResultsFactory;
  44. /**
  45. * @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  46. */
  47. private $eventManager;
  48. /**
  49. * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  50. */
  51. private $storeManager;
  52. /**
  53. * @var \Magento\Framework\Api\ExtensibleDataObjectConverter|\PHPUnit_Framework_MockObject_MockObject
  54. */
  55. private $extensibleDataObjectConverter;
  56. /**
  57. * @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject
  58. */
  59. private $dataObjectHelper;
  60. /**
  61. * @var \Magento\Framework\Api\ImageProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
  62. */
  63. private $imageProcessor;
  64. /**
  65. * @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
  66. */
  67. private $extensionAttributesJoinProcessor;
  68. /**
  69. * @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject
  70. */
  71. private $customer;
  72. /**
  73. * @var CollectionProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
  74. */
  75. private $collectionProcessorMock;
  76. /**
  77. * @var NotificationStorage|\PHPUnit_Framework_MockObject_MockObject
  78. */
  79. private $notificationStorage;
  80. /**
  81. * @var \Magento\Customer\Model\ResourceModel\CustomerRepository
  82. */
  83. private $model;
  84. protected function setUp()
  85. {
  86. $this->customerResourceModel =
  87. $this->createMock(\Magento\Customer\Model\ResourceModel\Customer::class);
  88. $this->customerRegistry = $this->createMock(\Magento\Customer\Model\CustomerRegistry::class);
  89. $this->dataObjectHelper = $this->createMock(\Magento\Framework\Api\DataObjectHelper::class);
  90. $this->customerFactory =
  91. $this->createPartialMock(\Magento\Customer\Model\CustomerFactory::class, ['create']);
  92. $this->customerSecureFactory = $this->createPartialMock(
  93. \Magento\Customer\Model\Data\CustomerSecureFactory::class,
  94. ['create']
  95. );
  96. $this->addressRepository = $this->createMock(\Magento\Customer\Model\ResourceModel\AddressRepository::class);
  97. $this->customerMetadata = $this->getMockForAbstractClass(
  98. \Magento\Customer\Api\CustomerMetadataInterface::class,
  99. [],
  100. '',
  101. false
  102. );
  103. $this->searchResultsFactory = $this->createPartialMock(
  104. \Magento\Customer\Api\Data\CustomerSearchResultsInterfaceFactory::class,
  105. ['create']
  106. );
  107. $this->eventManager = $this->getMockForAbstractClass(
  108. \Magento\Framework\Event\ManagerInterface::class,
  109. [],
  110. '',
  111. false
  112. );
  113. $this->storeManager = $this->getMockForAbstractClass(
  114. \Magento\Store\Model\StoreManagerInterface::class,
  115. [],
  116. '',
  117. false
  118. );
  119. $this->extensibleDataObjectConverter = $this->createMock(
  120. \Magento\Framework\Api\ExtensibleDataObjectConverter::class
  121. );
  122. $this->imageProcessor = $this->getMockForAbstractClass(
  123. \Magento\Framework\Api\ImageProcessorInterface::class,
  124. [],
  125. '',
  126. false
  127. );
  128. $this->extensionAttributesJoinProcessor = $this->getMockForAbstractClass(
  129. \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface::class,
  130. [],
  131. '',
  132. false
  133. );
  134. $this->customer = $this->getMockForAbstractClass(
  135. \Magento\Customer\Api\Data\CustomerInterface::class,
  136. [],
  137. '',
  138. true,
  139. true,
  140. true,
  141. [
  142. '__toArray'
  143. ]
  144. );
  145. $this->collectionProcessorMock = $this->getMockBuilder(CollectionProcessorInterface::class)
  146. ->getMock();
  147. $this->notificationStorage = $this->getMockBuilder(NotificationStorage::class)
  148. ->disableOriginalConstructor()
  149. ->getMock();
  150. $this->model = new \Magento\Customer\Model\ResourceModel\CustomerRepository(
  151. $this->customerFactory,
  152. $this->customerSecureFactory,
  153. $this->customerRegistry,
  154. $this->addressRepository,
  155. $this->customerResourceModel,
  156. $this->customerMetadata,
  157. $this->searchResultsFactory,
  158. $this->eventManager,
  159. $this->storeManager,
  160. $this->extensibleDataObjectConverter,
  161. $this->dataObjectHelper,
  162. $this->imageProcessor,
  163. $this->extensionAttributesJoinProcessor,
  164. $this->collectionProcessorMock,
  165. $this->notificationStorage
  166. );
  167. }
  168. /**
  169. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  170. */
  171. public function testSave()
  172. {
  173. $customerId = 1;
  174. $storeId = 2;
  175. $customerModel = $this->createPartialMock(\Magento\Customer\Model\Customer::class, [
  176. 'getId',
  177. 'setId',
  178. 'setStoreId',
  179. 'getStoreId',
  180. 'getAttributeSetId',
  181. 'setAttributeSetId',
  182. 'setRpToken',
  183. 'setRpTokenCreatedAt',
  184. 'getDataModel',
  185. 'setPasswordHash',
  186. 'setFailuresNum',
  187. 'setFirstFailure',
  188. 'setLockExpires',
  189. 'save',
  190. ]);
  191. $origCustomer = $this->customer;
  192. $customerAttributesMetaData = $this->getMockForAbstractClass(
  193. \Magento\Framework\Api\CustomAttributesDataInterface::class,
  194. [],
  195. '',
  196. false,
  197. false,
  198. true,
  199. [
  200. 'getId',
  201. 'getEmail',
  202. 'getWebsiteId',
  203. 'getAddresses',
  204. 'setAddresses'
  205. ]
  206. );
  207. $customerSecureData = $this->createPartialMock(\Magento\Customer\Model\Data\CustomerSecure::class, [
  208. 'getRpToken',
  209. 'getRpTokenCreatedAt',
  210. 'getPasswordHash',
  211. 'getFailuresNum',
  212. 'getFirstFailure',
  213. 'getLockExpires',
  214. ]);
  215. $this->customer->expects($this->atLeastOnce())
  216. ->method('getId')
  217. ->willReturn($customerId);
  218. $this->customer->expects($this->atLeastOnce())
  219. ->method('__toArray')
  220. ->willReturn([]);
  221. $this->customerRegistry->expects($this->atLeastOnce())
  222. ->method('retrieve')
  223. ->with($customerId)
  224. ->willReturn($customerModel);
  225. $customerModel->expects($this->atLeastOnce())
  226. ->method('getDataModel')
  227. ->willReturn($this->customer);
  228. $this->imageProcessor->expects($this->once())
  229. ->method('save')
  230. ->with($this->customer, CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $this->customer)
  231. ->willReturn($customerAttributesMetaData);
  232. $this->customerRegistry->expects($this->atLeastOnce())
  233. ->method("remove")
  234. ->with($customerId);
  235. $this->extensibleDataObjectConverter->expects($this->once())
  236. ->method('toNestedArray')
  237. ->with($customerAttributesMetaData, [], \Magento\Customer\Api\Data\CustomerInterface::class)
  238. ->willReturn(['customerData']);
  239. $this->customerFactory->expects($this->once())
  240. ->method('create')
  241. ->with(['data' => ['customerData']])
  242. ->willReturn($customerModel);
  243. $customerModel->expects($this->once())
  244. ->method('getStoreId')
  245. ->willReturn(null);
  246. $store = $this->createMock(\Magento\Store\Model\Store::class);
  247. $store->expects($this->once())
  248. ->method('getId')
  249. ->willReturn($storeId);
  250. $this->storeManager
  251. ->expects($this->once())
  252. ->method('getStore')
  253. ->willReturn($store);
  254. $customerModel->expects($this->once())
  255. ->method('setStoreId')
  256. ->with($storeId);
  257. $customerModel->expects($this->once())
  258. ->method('setId')
  259. ->with($customerId);
  260. $customerAttributesMetaData->expects($this->atLeastOnce())
  261. ->method('getId')
  262. ->willReturn($customerId);
  263. $this->customerRegistry->expects($this->once())
  264. ->method('retrieveSecureData')
  265. ->with($customerId)
  266. ->willReturn($customerSecureData);
  267. $customerSecureData->expects($this->once())
  268. ->method('getRpToken')
  269. ->willReturn('rpToken');
  270. $customerSecureData->expects($this->once())
  271. ->method('getRpTokenCreatedAt')
  272. ->willReturn('rpTokenCreatedAt');
  273. $customerSecureData->expects($this->once())
  274. ->method('getPasswordHash')
  275. ->willReturn('passwordHash');
  276. $customerSecureData->expects($this->once())
  277. ->method('getFailuresNum')
  278. ->willReturn('failuresNum');
  279. $customerSecureData->expects($this->once())
  280. ->method('getFirstFailure')
  281. ->willReturn('firstFailure');
  282. $customerSecureData->expects($this->once())
  283. ->method('getLockExpires')
  284. ->willReturn('lockExpires');
  285. $customerModel->expects($this->once())
  286. ->method('setRpToken')
  287. ->willReturnMap([
  288. ['rpToken', $customerModel],
  289. [null, $customerModel],
  290. ]);
  291. $customerModel->expects($this->once())
  292. ->method('setRpTokenCreatedAt')
  293. ->willReturnMap([
  294. ['rpTokenCreatedAt', $customerModel],
  295. [null, $customerModel],
  296. ]);
  297. $customerModel->expects($this->once())
  298. ->method('setPasswordHash')
  299. ->with('passwordHash');
  300. $customerModel->expects($this->once())
  301. ->method('setFailuresNum')
  302. ->with('failuresNum');
  303. $customerModel->expects($this->once())
  304. ->method('setFirstFailure')
  305. ->with('firstFailure');
  306. $customerModel->expects($this->once())
  307. ->method('setLockExpires')
  308. ->with('lockExpires');
  309. $customerModel->expects($this->atLeastOnce())
  310. ->method('getId')
  311. ->willReturn($customerId);
  312. $customerModel->expects($this->once())
  313. ->method('save');
  314. $this->customerRegistry->expects($this->once())
  315. ->method('push')
  316. ->with($customerModel);
  317. $customerAttributesMetaData->expects($this->once())
  318. ->method('getEmail')
  319. ->willReturn('example@example.com');
  320. $customerAttributesMetaData->expects($this->once())
  321. ->method('getWebsiteId')
  322. ->willReturn(2);
  323. $this->customerRegistry->expects($this->once())
  324. ->method('retrieveByEmail')
  325. ->with('example@example.com', 2)
  326. ->willReturn($customerModel);
  327. $this->eventManager->expects($this->once())
  328. ->method('dispatch')
  329. ->with(
  330. 'customer_save_after_data_object',
  331. [
  332. 'customer_data_object' => $this->customer,
  333. 'orig_customer_data_object' => $origCustomer,
  334. 'delegate_data' => [],
  335. ]
  336. );
  337. $this->model->save($this->customer);
  338. }
  339. /**
  340. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  341. */
  342. public function testSaveWithPasswordHash()
  343. {
  344. $customerId = 1;
  345. $storeId = 2;
  346. $passwordHash = 'ukfa4sdfa56s5df02asdf4rt';
  347. $customerSecureData = $this->createPartialMock(\Magento\Customer\Model\Data\CustomerSecure::class, [
  348. 'getRpToken',
  349. 'getRpTokenCreatedAt',
  350. 'getPasswordHash',
  351. 'getFailuresNum',
  352. 'getFirstFailure',
  353. 'getLockExpires',
  354. ]);
  355. $origCustomer = $this->customer;
  356. $customerModel = $this->createPartialMock(\Magento\Customer\Model\Customer::class, [
  357. 'getId',
  358. 'setId',
  359. 'setStoreId',
  360. 'getStoreId',
  361. 'getAttributeSetId',
  362. 'setAttributeSetId',
  363. 'setRpToken',
  364. 'setRpTokenCreatedAt',
  365. 'getDataModel',
  366. 'setPasswordHash',
  367. 'save',
  368. ]);
  369. $customerAttributesMetaData = $this->getMockForAbstractClass(
  370. \Magento\Framework\Api\CustomAttributesDataInterface::class,
  371. [],
  372. '',
  373. false,
  374. false,
  375. true,
  376. [
  377. 'getId',
  378. 'getEmail',
  379. 'getWebsiteId',
  380. 'getAddresses',
  381. 'setAddresses'
  382. ]
  383. );
  384. $customerModel->expects($this->atLeastOnce())
  385. ->method('setRpToken')
  386. ->with(null);
  387. $customerModel->expects($this->atLeastOnce())
  388. ->method('setRpTokenCreatedAt')
  389. ->with(null);
  390. $customerModel->expects($this->atLeastOnce())
  391. ->method('setPasswordHash')
  392. ->with($passwordHash);
  393. $this->customerRegistry->expects($this->atLeastOnce())
  394. ->method('remove')
  395. ->with($customerId);
  396. $this->customerRegistry->expects($this->once())
  397. ->method('retrieveSecureData')
  398. ->with($customerId)
  399. ->willReturn($customerSecureData);
  400. $customerSecureData->expects($this->never())
  401. ->method('getRpToken')
  402. ->willReturn('rpToken');
  403. $customerSecureData->expects($this->never())
  404. ->method('getRpTokenCreatedAt')
  405. ->willReturn('rpTokenCreatedAt');
  406. $customerSecureData->expects($this->never())
  407. ->method('getPasswordHash')
  408. ->willReturn('passwordHash');
  409. $customerSecureData->expects($this->once())
  410. ->method('getFailuresNum')
  411. ->willReturn('failuresNum');
  412. $customerSecureData->expects($this->once())
  413. ->method('getFirstFailure')
  414. ->willReturn('firstFailure');
  415. $customerSecureData->expects($this->once())
  416. ->method('getLockExpires')
  417. ->willReturn('lockExpires');
  418. $this->customer->expects($this->atLeastOnce())
  419. ->method('getId')
  420. ->willReturn($customerId);
  421. $this->customer->expects($this->atLeastOnce())
  422. ->method('__toArray')
  423. ->willReturn([]);
  424. $this->customerRegistry->expects($this->atLeastOnce())
  425. ->method('retrieve')
  426. ->with($customerId)
  427. ->willReturn($customerModel);
  428. $customerModel->expects($this->atLeastOnce())
  429. ->method('getDataModel')
  430. ->willReturn($this->customer);
  431. $this->imageProcessor->expects($this->once())
  432. ->method('save')
  433. ->with($this->customer, CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $this->customer)
  434. ->willReturn($customerAttributesMetaData);
  435. $customerAttributesMetaData
  436. ->expects($this->atLeastOnce())
  437. ->method('getId')
  438. ->willReturn($customerId);
  439. $this->extensibleDataObjectConverter->expects($this->once())
  440. ->method('toNestedArray')
  441. ->with($customerAttributesMetaData, [], \Magento\Customer\Api\Data\CustomerInterface::class)
  442. ->willReturn(['customerData']);
  443. $this->customerFactory->expects($this->once())
  444. ->method('create')
  445. ->with(['data' => ['customerData']])
  446. ->willReturn($customerModel);
  447. $customerModel->expects($this->once())
  448. ->method('getStoreId')
  449. ->willReturn(null);
  450. $store = $this->createMock(\Magento\Store\Model\Store::class);
  451. $store->expects($this->once())
  452. ->method('getId')
  453. ->willReturn($storeId);
  454. $this->storeManager
  455. ->expects($this->once())
  456. ->method('getStore')
  457. ->willReturn($store);
  458. $customerModel->expects($this->once())
  459. ->method('setStoreId')
  460. ->with($storeId);
  461. $customerModel->expects($this->once())
  462. ->method('setId')
  463. ->with($customerId);
  464. $customerModel->expects($this->atLeastOnce())
  465. ->method('getId')
  466. ->willReturn($customerId);
  467. $customerModel->expects($this->once())
  468. ->method('save');
  469. $this->customerRegistry->expects($this->once())
  470. ->method('push')
  471. ->with($customerModel);
  472. $customerAttributesMetaData->expects($this->once())
  473. ->method('getEmail')
  474. ->willReturn('example@example.com');
  475. $customerAttributesMetaData->expects($this->once())
  476. ->method('getWebsiteId')
  477. ->willReturn(2);
  478. $this->customerRegistry->expects($this->once())
  479. ->method('retrieveByEmail')
  480. ->with('example@example.com', 2)
  481. ->willReturn($customerModel);
  482. $this->eventManager->expects($this->once())
  483. ->method('dispatch')
  484. ->with(
  485. 'customer_save_after_data_object',
  486. [
  487. 'customer_data_object' => $this->customer,
  488. 'orig_customer_data_object' => $origCustomer,
  489. 'delegate_data' => [],
  490. ]
  491. );
  492. $this->model->save($this->customer, $passwordHash);
  493. }
  494. /**
  495. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  496. */
  497. public function testGetList()
  498. {
  499. $collection = $this->createMock(\Magento\Customer\Model\ResourceModel\Customer\Collection::class);
  500. $searchResults = $this->getMockForAbstractClass(
  501. \Magento\Customer\Api\Data\AddressSearchResultsInterface::class,
  502. [],
  503. '',
  504. false
  505. );
  506. $searchCriteria = $this->getMockForAbstractClass(
  507. \Magento\Framework\Api\SearchCriteriaInterface::class,
  508. [],
  509. '',
  510. false
  511. );
  512. $customerModel = $this->getMockBuilder(\Magento\Customer\Model\Customer::class)
  513. ->setMethods(
  514. [
  515. 'getId',
  516. 'setId',
  517. 'setStoreId',
  518. 'getStoreId',
  519. 'getAttributeSetId',
  520. 'setAttributeSetId',
  521. 'setRpToken',
  522. 'setRpTokenCreatedAt',
  523. 'getDataModel',
  524. 'setPasswordHash',
  525. 'getCollection'
  526. ]
  527. )
  528. ->setMockClassName('customerModel')
  529. ->disableOriginalConstructor()
  530. ->getMock();
  531. $metadata = $this->getMockForAbstractClass(
  532. \Magento\Customer\Api\Data\AttributeMetadataInterface::class,
  533. [],
  534. '',
  535. false
  536. );
  537. $this->searchResultsFactory->expects($this->once())
  538. ->method('create')
  539. ->willReturn($searchResults);
  540. $searchResults->expects($this->once())
  541. ->method('setSearchCriteria')
  542. ->with($searchCriteria);
  543. $this->customerFactory->expects($this->once())
  544. ->method('create')
  545. ->willReturn($customerModel);
  546. $customerModel->expects($this->once())
  547. ->method('getCollection')
  548. ->willReturn($collection);
  549. $this->extensionAttributesJoinProcessor->expects($this->once())
  550. ->method('process')
  551. ->with($collection, \Magento\Customer\Api\Data\CustomerInterface::class);
  552. $this->customerMetadata->expects($this->once())
  553. ->method('getAllAttributesMetadata')
  554. ->willReturn([$metadata]);
  555. $metadata->expects($this->once())
  556. ->method('getAttributeCode')
  557. ->willReturn('attribute-code');
  558. $collection->expects($this->once())
  559. ->method('addAttributeToSelect')
  560. ->with('attribute-code');
  561. $collection->expects($this->once())
  562. ->method('addNameToSelect');
  563. $collection->expects($this->at(2))
  564. ->method('joinAttribute')
  565. ->with('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
  566. ->willReturnSelf();
  567. $collection->expects($this->at(3))
  568. ->method('joinAttribute')
  569. ->with('billing_city', 'customer_address/city', 'default_billing', null, 'left')
  570. ->willReturnSelf();
  571. $collection->expects($this->at(4))
  572. ->method('joinAttribute')
  573. ->with('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
  574. ->willReturnSelf();
  575. $collection->expects($this->at(5))
  576. ->method('joinAttribute')
  577. ->with('billing_region', 'customer_address/region', 'default_billing', null, 'left')
  578. ->willReturnSelf();
  579. $collection->expects($this->at(6))
  580. ->method('joinAttribute')
  581. ->with('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
  582. ->willReturnSelf();
  583. $collection->expects($this->at(7))
  584. ->method('joinAttribute')
  585. ->with('billing_company', 'customer_address/company', 'default_billing', null, 'left')
  586. ->willReturnSelf();
  587. $this->collectionProcessorMock->expects($this->once())
  588. ->method('process')
  589. ->with($searchCriteria, $collection);
  590. $collection->expects($this->once())
  591. ->method('getSize')
  592. ->willReturn(23);
  593. $searchResults->expects($this->once())
  594. ->method('setTotalCount')
  595. ->with(23);
  596. $collection->expects($this->once())
  597. ->method('getIterator')
  598. ->willReturn(new \ArrayIterator([$customerModel]));
  599. $customerModel->expects($this->atLeastOnce())
  600. ->method('getDataModel')
  601. ->willReturn($this->customer);
  602. $searchResults->expects($this->once())
  603. ->method('setItems')
  604. ->with([$this->customer]);
  605. $this->assertSame($searchResults, $this->model->getList($searchCriteria));
  606. }
  607. public function testDeleteById()
  608. {
  609. $customerId = 14;
  610. $customerModel = $this->createPartialMock(\Magento\Customer\Model\Customer::class, ['delete']);
  611. $this->customerRegistry
  612. ->expects($this->once())
  613. ->method('retrieve')
  614. ->with($customerId)
  615. ->willReturn($customerModel);
  616. $customerModel->expects($this->once())
  617. ->method('delete');
  618. $this->customerRegistry->expects($this->atLeastOnce())
  619. ->method('remove')
  620. ->with($customerId);
  621. $this->assertTrue($this->model->deleteById($customerId));
  622. }
  623. public function testDelete()
  624. {
  625. $customerId = 14;
  626. $customerModel = $this->createPartialMock(\Magento\Customer\Model\Customer::class, ['delete']);
  627. $this->customer->expects($this->once())
  628. ->method('getId')
  629. ->willReturn($customerId);
  630. $this->customerRegistry
  631. ->expects($this->once())
  632. ->method('retrieve')
  633. ->with($customerId)
  634. ->willReturn($customerModel);
  635. $customerModel->expects($this->once())
  636. ->method('delete');
  637. $this->customerRegistry->expects($this->atLeastOnce())
  638. ->method('remove')
  639. ->with($customerId);
  640. $this->notificationStorage->expects($this->atLeastOnce())
  641. ->method('remove')
  642. ->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId);
  643. $this->assertTrue($this->model->delete($this->customer));
  644. }
  645. }