Skip to content

Commit a4f0e96

Browse files
authored
ENGCOM-6751: Fixed type issue. Create unit test for customer data model #26490
2 parents 74ee21b + 26e49e3 commit a4f0e96

File tree

2 files changed

+89
-5
lines changed

2 files changed

+89
-5
lines changed

app/code/Magento/Customer/Model/Data/Customer.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
use \Magento\Framework\Api\AttributeValueFactory;
1010

1111
/**
12-
* Class Customer
12+
* Customer data model
13+
*
1314
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
1415
*/
1516
class Customer extends \Magento\Framework\Api\AbstractExtensibleObject implements
@@ -39,7 +40,7 @@ public function __construct(
3940
}
4041

4142
/**
42-
* {@inheritdoc}
43+
* @inheritdoc
4344
*/
4445
protected function getCustomAttributesCodes()
4546
{
@@ -50,6 +51,8 @@ protected function getCustomAttributesCodes()
5051
}
5152

5253
/**
54+
* Get default billing address id
55+
*
5356
* @return string|null
5457
*/
5558
public function getDefaultBilling()
@@ -150,7 +153,7 @@ public function getGender()
150153
/**
151154
* Get group id
152155
*
153-
* @return string|null
156+
* @return int|null
154157
*/
155158
public function getGroupId()
156159
{
@@ -489,7 +492,7 @@ public function setDisableAutoGroupChange($disableAutoGroupChange)
489492
}
490493

491494
/**
492-
* {@inheritdoc}
495+
* @inheritdoc
493496
*
494497
* @return \Magento\Customer\Api\Data\CustomerExtensionInterface|null
495498
*/
@@ -499,7 +502,7 @@ public function getExtensionAttributes()
499502
}
500503

501504
/**
502-
* {@inheritdoc}
505+
* @inheritdoc
503506
*
504507
* @param \Magento\Customer\Api\Data\CustomerExtensionInterface $extensionAttributes
505508
* @return $this
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Test\Unit\Model\Data;
8+
9+
use Magento\Customer\Model\Data\Customer;
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* Unit test for customer data model
15+
*/
16+
class CustomerTest extends TestCase
17+
{
18+
/** @var Customer */
19+
protected $model;
20+
21+
/** @var ObjectManager */
22+
protected $objectManager;
23+
24+
protected function setUp()
25+
{
26+
$this->objectManager = new ObjectManager($this);
27+
28+
$this->model = $this->objectManager->getObject(Customer::class);
29+
}
30+
31+
/**
32+
* Test getGroupId()
33+
*
34+
* @return void
35+
*/
36+
public function testGetGroupId()
37+
{
38+
$testGroupId = 3;
39+
$this->model->setGroupId($testGroupId);
40+
$this->assertEquals($testGroupId, $this->model->getGroupId());
41+
}
42+
43+
/**
44+
* Test getCreatedIn()
45+
*
46+
* @param array|string $options
47+
* @param array $expectedResult
48+
*
49+
* @dataProvider getCreatedInDataProvider
50+
*
51+
* @return void
52+
*/
53+
public function testGetCreatedIn($options, $expectedResult)
54+
{
55+
$optionsCount = count($options);
56+
$expectedCount = count($expectedResult);
57+
58+
for ($i = 0; $i < $optionsCount; $i++) {
59+
$this->model->setCreatedIn($options[$i]);
60+
for ($j = $i; $j < $expectedCount; $j++) {
61+
$this->assertEquals($expectedResult[$j], $this->model->getCreatedIn());
62+
break;
63+
}
64+
}
65+
}
66+
67+
/**
68+
* Data provider for testGetCreatedIn
69+
*
70+
* @return array
71+
*/
72+
public function getCreatedInDataProvider()
73+
{
74+
return [
75+
'array' => [
76+
'options' => ['Default', 'Admin', 'US'],
77+
'expectedResult' => ['Default', 'Admin', 'US']
78+
]
79+
];
80+
}
81+
}

0 commit comments

Comments
 (0)