Skip to content

Commit 5081434

Browse files
committed
Cnam guarding because we sometimes get missing fields, up to developer to determine what to do with it.
1 parent dab6a94 commit 5081434

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

src/Insights/CnamTrait.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@
1414
trait CnamTrait
1515
{
1616

17-
public function getCallerName()
17+
public function getCallerName(): ?string
1818
{
19-
return $this->data['caller_name'];
19+
return $this->data['caller_name'] ?? null;
2020
}
2121

22-
public function getFirstName()
22+
public function getFirstName(): ?string
2323
{
24-
return $this->data['first_name'];
24+
return $this->data['first_name'] ?? null;
2525
}
2626

27-
public function getLastName()
27+
public function getLastName(): ?string
2828
{
29-
return $this->data['last_name'];
29+
return $this->data['last_name'] ?? null;
3030
}
3131

32-
public function getCallerType()
32+
public function getCallerType(): ?string
3333
{
34-
return $this->data['caller_type'];
34+
return $this->data['caller_type'] ?? null;
3535
}
3636
}

test/Insights/CnamTraitTest.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,59 @@
1616
class CnamTraitTest extends VonageTestCase
1717
{
1818
/**
19-
* @dataProvider cnamProvider
2019
*
2120
* @param $cnam
2221
* @param $inputData
2322
*/
24-
public function testObjectAccess($cnam, $inputData): void
23+
public function testObjectAccess(): void
2524
{
25+
$inputData = [
26+
'first_name' => 'Tony',
27+
'last_name' => 'Tiger',
28+
'caller_name' => 'Tony Tiger Esq',
29+
'caller_type' => 'consumer'
30+
];
31+
32+
$cnam = new Cnam('14155550100');
33+
$cnam->fromArray($inputData);
34+
2635
$this->assertEquals($inputData['first_name'], $cnam->getFirstName());
2736
$this->assertEquals($inputData['last_name'], $cnam->getLastName());
2837
$this->assertEquals($inputData['caller_name'], $cnam->getCallerName());
2938
$this->assertEquals($inputData['caller_type'], $cnam->getCallerType());
3039
}
3140

32-
public function cnamProvider(): array
41+
public function testCanHandleNullFields(): void
3342
{
34-
$r = [];
35-
36-
$input1 = [
43+
$inputData = [
3744
'first_name' => 'Tony',
3845
'last_name' => 'Tiger',
3946
'caller_name' => 'Tony Tiger Esq',
4047
'caller_type' => 'consumer'
4148
];
4249

43-
$cnam1 = new Cnam('14155550100');
44-
$cnam1->fromArray($input1);
45-
$r['cnam-1'] = [$cnam1, $input1];
50+
$inputFirstname = $inputData;
51+
unset($inputFirstname['first_name']);
52+
$firstName = new Cnam('14155550100');
53+
$firstName->fromArray($inputFirstname);
54+
$this->assertEquals(null, $firstName->getFirstName());
55+
56+
$inputLastName = $inputData;
57+
unset($inputLastName['last_name']);
58+
$lastName = new Cnam('14155550100');
59+
$lastName->fromArray($inputLastName);
60+
$this->assertEquals(null, $lastName->getLastName());
61+
62+
$inputCallerName = $inputData;
63+
unset($inputCallerName['caller_name']);
64+
$callerName = new Cnam('14155550100');
65+
$callerName->fromArray($inputCallerName);
66+
$this->assertEquals(null, $callerName->getCallerName());
4667

47-
return $r;
68+
$inputCallerType = $inputData;
69+
unset($inputCallerType['caller_type']);
70+
$callerType = new Cnam('14155550100');
71+
$callerType->fromArray($inputCallerType);
72+
$this->assertEquals(null, $callerType->getCallerType());
4873
}
4974
}

0 commit comments

Comments
 (0)