Skip to content

Commit 0263b4c

Browse files
author
Andrew Chorniy
committed
Fixed type issue. Create unit test for customer data model
1 parent 1ad65a3 commit 0263b4c

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function getCreatedAt()
9494
*/
9595
public function getCreatedIn()
9696
{
97-
return $this->_get(self::CREATED_IN);
97+
return (string)$this->_get(self::CREATED_IN);
9898
}
9999

100100
/**
@@ -150,7 +150,7 @@ public function getGender()
150150
/**
151151
* Get group id
152152
*
153-
* @return string|null
153+
* @return int|null
154154
*/
155155
public function getGroupId()
156156
{
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Magento\Customer\Test\Unit\Model\Data;
4+
5+
use Magento\Customer\Model\Data\Customer;
6+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
7+
use PHPUnit\Framework\TestCase;
8+
9+
/**
10+
* Unit test for customer data model
11+
*/
12+
class CustomerTest extends TestCase
13+
{
14+
/** @var Customer */
15+
protected $model;
16+
17+
/** @var ObjectManager */
18+
protected $objectManager;
19+
20+
protected function setUp()
21+
{
22+
$this->objectManager = new ObjectManager($this);
23+
24+
$this->model = $this->objectManager->getObject(Customer::class);
25+
}
26+
27+
/**
28+
* Test getGroupId()
29+
*
30+
* @return void
31+
*/
32+
public function testGetGroupId()
33+
{
34+
$testGroupId = 3;
35+
$this->model->setGroupId($testGroupId);
36+
$this->assertEquals($testGroupId, $this->model->getGroupId());
37+
}
38+
39+
/**
40+
* Test getCreatedIn()
41+
*
42+
* @param array|string $options
43+
* @param array $expectedResult
44+
*
45+
* @dataProvider getCreatedInDataProvider
46+
*
47+
* @return void
48+
*/
49+
public function testGetCreatedIn($options, $expectedResult)
50+
{
51+
for ($i = 0; $i < count($options); $i++) {
52+
$this->model->setCreatedIn($options[$i]);
53+
for ($j = $i; $j < count($expectedResult); $j++) {
54+
$this->assertEquals($expectedResult[$j], $this->model->getCreatedIn());
55+
break;
56+
}
57+
}
58+
}
59+
60+
/**
61+
* Data provider for testGetCreatedIn
62+
*
63+
* @return array
64+
*/
65+
public function getCreatedInDataProvider()
66+
{
67+
return [
68+
'array' => [
69+
'options' => ['Default', 'Admin', 'US'],
70+
'expectedResult' => ['Default', 'Admin', 'US']
71+
]
72+
];
73+
}
74+
}

0 commit comments

Comments
 (0)