Skip to content

Commit

Permalink
Add smoke tests for basic exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Sep 23, 2016
1 parent 3566c6e commit a72e5be
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/Spryker/Zed/Customer/Business/Customer/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function getAddressTransferById($idAddress, $idCustomer = null)
$addressEntity = $addressQuery->findOne();

if ($addressEntity === null) {
throw new AddressNotFoundException(sprintf('Address not found for ID %s (and optional customer ID %s).', $idAddress, $idCustomer));
throw new AddressNotFoundException(sprintf('Address not found for ID `%s` (and optional customer ID `%s`).', $idAddress, $idCustomer));
}

$addressTransfer = $this->entityToAddressTransfer($addressEntity);
Expand Down Expand Up @@ -184,7 +184,7 @@ public function setDefaultShippingAddress(AddressTransfer $addressTransfer)

if (!$entity) {
throw new AddressNotFoundException(sprintf(
'Address not found for ID %s and customer email %s.',
'Address not found for ID `%s` and customer email `%s`.',
$addressTransfer->getIdCustomerAddress(),
$customer->getEmail()
));
Expand Down Expand Up @@ -212,7 +212,7 @@ public function setDefaultBillingAddress(AddressTransfer $addressTransfer)

if (!$entity) {
throw new AddressNotFoundException(sprintf(
'Address not found for ID %s and customer email %s.',
'Address not found for ID `%s` and customer email `%s`.',
$addressTransfer->getIdCustomerAddress(),
$customer->getEmail()
));
Expand Down Expand Up @@ -313,7 +313,7 @@ protected function getCustomerFromAddressTransfer(AddressTransfer $addressTransf

if ($customer === null) {
throw new CustomerNotFoundException(sprintf(
'Customer not found for email %s or ID %s.',
'Customer not found for email `%s` or ID `%s`.',
$addressTransfer->getEmail(),
$addressTransfer->getFkCustomer()
));
Expand Down Expand Up @@ -342,7 +342,7 @@ protected function getCustomerFromCustomerTransfer(CustomerTransfer $customerTra

if ($customer === null) {
throw new CustomerNotFoundException(sprintf(
'Customer not found for email %s or ID %s.',
'Customer not found for email `%s` or ID `%s`.',
$customerTransfer->getEmail(),
$customerTransfer->getIdCustomer()
));
Expand All @@ -362,7 +362,7 @@ protected function getCustomerCountryId()

if ($idCountry === null) {
throw new CountryNotFoundException(sprintf(
'Country not found for ISO code %s.',
'Country not found for ISO code `%s`.',
$this->getIsoCode()
));
}
Expand Down Expand Up @@ -427,7 +427,7 @@ public function deleteAddress(AddressTransfer $addressTransfer)

if (!$entity) {
throw new AddressNotFoundException(sprintf(
'Address not found for ID %s and customer email %s.',
'Address not found for ID `%s` and customer email `%s`.',
$addressTransfer->getIdCustomerAddress(),
$customer->getEmail()
));
Expand Down Expand Up @@ -583,7 +583,7 @@ protected function updateCustomerAddress(AddressTransfer $addressTransfer, SpyCu

if (!$addressEntity) {
throw new AddressNotFoundException(sprintf(
'Address not found for ID %s and customer email %s.',
'Address not found for ID `%s` and customer email `%s`.',
$addressTransfer->getIdCustomerAddress(),
$customer->getEmail()
));
Expand Down
4 changes: 2 additions & 2 deletions src/Spryker/Zed/Customer/Business/Customer/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function confirmRegistration(CustomerTransfer $customerTransfer)
$customerEntity = $this->queryContainer->queryCustomerByRegistrationKey($customerTransfer->getRegistrationKey())
->findOne();
if ($customerEntity === null) {
throw new CustomerNotFoundException(sprintf('Customer for registration key %s not found', $customerTransfer->getRegistrationKey()));
throw new CustomerNotFoundException(sprintf('Customer for registration key `%s` not found', $customerTransfer->getRegistrationKey()));
}

$customerEntity->setRegistered(new \DateTime());
Expand Down Expand Up @@ -527,7 +527,7 @@ protected function getCustomer(CustomerTransfer $customerTransfer)
}

throw new CustomerNotFoundException(sprintf(
'Customer not found by either ID %s, email %s or restore password key %s.',
'Customer not found by either ID `%s`, email `%s` or restore password key `%s`.',
$customerTransfer->getIdCustomer(),
$customerTransfer->getEmail(),
$customerTransfer->getRestorePasswordKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testIndexActionUpdateUser()
$customerData = $this->getFormData();
$customerData[CustomerForm::FIELD_FIRST_NAME] = self::NEW_FIRST_NAME;
$data = [
'customer' => $customerData
'customer' => $customerData,
];

$request = Request::create('/customer/edit?id-customer=' . $this->customer->getIdCustomer(), 'POST', $data);
Expand Down
75 changes: 75 additions & 0 deletions tests/Unit/Spryker/Zed/Customer/Business/Customer/AddressTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Unit\Spryker\Zed\Customer\Business\Customer;

use Codeception\TestCase\Test;
use Generated\Shared\Transfer\AddressTransfer;
use Spryker\Zed\Customer\Business\Customer\Address;
use Spryker\Zed\Customer\Business\Exception\CustomerNotFoundException;
use Spryker\Zed\Customer\Dependency\Facade\CustomerToCountryInterface;
use Spryker\Zed\Customer\Dependency\Facade\CustomerToLocaleInterface;
use Spryker\Zed\Customer\Persistence\CustomerQueryContainer;

/**
* @group Unit
* @group Spryker
* @group Zed
* @group Customer
* @group Business
* @group Customer
* @group AddressTest
*/
class AddressTest extends Test
{

/**
* @var \Spryker\Zed\Customer\Business\Customer\Address
*/
protected $address;

/**
* @return void
*/
public function setUp()
{
$queryContainer = new CustomerQueryContainer();
$countryFacade = $this->createCountryFacadeMock();
$localeFacade = $this->createLocaleFacadeMock();
$this->address = new Address($queryContainer, $countryFacade, $localeFacade);
}

/**
* @return void
*/
public function testDeleteAddressException()
{
$addressTransfer = new AddressTransfer();

$this->expectException(CustomerNotFoundException::class);
$this->expectExceptionMessage('Customer not found for email `` or ID ``.');

$this->address->deleteAddress($addressTransfer);
}

/**
* @return \Spryker\Zed\Customer\Dependency\Facade\CustomerToCountryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected function createCountryFacadeMock()
{
return $this->getMockBuilder(CustomerToCountryInterface::class)->getMock();
}

/**
* @return \Spryker\Zed\Customer\Dependency\Facade\CustomerToLocaleInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected function createLocaleFacadeMock()
{
return $this->getMockBuilder(CustomerToLocaleInterface::class)->getMock();
}

}
67 changes: 67 additions & 0 deletions tests/Unit/Spryker/Zed/Customer/Business/Customer/CustomerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Unit\Spryker\Zed\Customer\Business\Customer;

use Codeception\TestCase\Test;
use Generated\Shared\Transfer\CustomerTransfer;
use Spryker\Zed\Customer\Business\Customer\Customer;
use Spryker\Zed\Customer\Business\Exception\CustomerNotFoundException;
use Spryker\Zed\Customer\Business\ReferenceGenerator\CustomerReferenceGeneratorInterface;
use Spryker\Zed\Customer\CustomerConfig;
use Spryker\Zed\Customer\Persistence\CustomerQueryContainer;

/**
* @group Unit
* @group Spryker
* @group Zed
* @group Customer
* @group Business
* @group Customer
* @group CustomerTest
*/
class CustomerTest extends Test
{

/**
* @var \Spryker\Zed\Customer\Business\Customer\Customer
*/
protected $customer;

/**
* @return void
*/
public function setUp()
{
$queryContainer = new CustomerQueryContainer();
$customerReferenceGenerator = $this->createCustomerReferenceGeneratorMock();
$customerConfig = new CustomerConfig();
$this->customer = new Customer($queryContainer, $customerReferenceGenerator, $customerConfig);
}

/**
* @return void
*/
public function testUpdatePasswordException()
{
$customerTransfer = new CustomerTransfer();

$this->expectException(CustomerNotFoundException::class);
$this->expectExceptionMessage('Customer not found by either ID ``, email `` or restore password key ``.');

$this->customer->updatePassword($customerTransfer);
}

/**
* @return \Spryker\Zed\Customer\Business\ReferenceGenerator\CustomerReferenceGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected function createCustomerReferenceGeneratorMock()
{
return $this->getMockBuilder(CustomerReferenceGeneratorInterface::class)->getMock();
}

}

0 comments on commit a72e5be

Please sign in to comment.