Skip to content

Commit 1cd0d56

Browse files
authored
Merge pull request #130 from dniccum/main
Undefined index within customer getByEmail method
2 parents 1b6e40a + a83b619 commit 1cd0d56

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/BigCommerce/Api/Customers/CustomersApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getByEmail(string $email): ?Customer
3333
{
3434
$customers = $this->getAll([self::FILTER__EMAIL_IN => $email])->getCustomers();
3535

36-
if (!$customers[0]) {
36+
if (count($customers) === 0) {
3737
return null;
3838
} elseif (count($customers) > 1) {
3939
throw new UnexpectedValueException("There are more than one customer with the email address $email");

tests/BigCommerce/Api/Customers/CustomersApiTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public function testCanGetCustomerByEmail()
3838
$this->assertEquals('John', $customer->first_name);
3939
}
4040

41+
public function testUnknownCustomerReturnsEmptyResult()
42+
{
43+
$this->setReturnData('customers__get_all_no_results.json');
44+
$customer = $this->getApi()->customers()->getByEmail('[email protected]');
45+
46+
$this->assertNull($customer);
47+
}
48+
4149
public function testCanGetCustomerById()
4250
{
4351
$this->setReturnData('customers__get_all.json');

0 commit comments

Comments
 (0)