Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rpWhittington committed Aug 17, 2018
1 parent 1943e25 commit 120d737
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 6 deletions.
150 changes: 144 additions & 6 deletions Tests/Functional/Component/Model/ShopwareCustomerWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@
class ShopwareCustomerWrapperTest extends TestCase
{

public function testGetBilling__fresh()
public function testGetBilling()
{
$mock = $this->getCustomerBillingFreshMock();
$this->_testGetBilling__fresh();
$this->_testGetBillingCountry__fresh();

if (!class_exists('Shopware\Models\Customer\Billing')) {
return;
}

$this->_testGetBilling__rotten();
$this->_testGetBillingCountry__rotten();
}

private function _testGetBilling__fresh()
{
$mock = $this->getCustomerFreshMock();
$wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());

$this->assertEquals(
Expand All @@ -26,21 +39,120 @@ public function testGetBilling__fresh()
);
}

public function testGetBillingCountry__fresh()
private function _testGetBillingCountry__fresh()
{
$mock = $this->getCustomerFreshMock();
$wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());

$country = $wrapper->getBillingCountry();

$this->assertEquals(
$country->getIso(),
'BC'
);
}

private function _testGetBilling__rotten()
{
$mock = $this->getCustomerBillingFreshMock();
$mock = $this->getCustomerRottenMock();
$wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());

$this->assertEquals(
$wrapper->getBilling('phone'),
'1111111111'
);

$billing = $wrapper->getBilling();
$this->assertNotNull($billing->getCountryId());

}

private function _testGetBillingCountry__rotten()
{
return;
$mock = $this->getCustomerRottenMock();
$wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());

$country = $wrapper->getBillingCountry();

$this->assertEquals(
$country->getIso(),
'DE'
);
}

public function _testGetShipping__fresh()
{
$mock = $this->getCustomerFreshMock(false);
$wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());

$this->assertEquals(
$wrapper->getShipping('phone'),
'015106483257'
);

$shipping = $wrapper->getShipping();

$this->assertEquals(
$shipping->getCountry()->getIso(),
'BC'
);
}

public function _testGetShippingCountry__fresh()
{
$mock = $this->getCustomerFreshMock(false);
$wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());

$country = $wrapper->getShippingCountry();

$this->assertEquals(
$country->getIso(),
'BC'
);
}

private function getCustomerBillingFreshMock()
public function testGetShipping()
{
$this->_testGetShipping__fresh();
$this->_testGetShippingCountry__fresh();

if (!class_exists('Shopware\Models\Customer\Billing')) {
return;
}

$this->_testGetShipping__rotten();
$this->_testGetShippingCountry__rotten();
}

private function _testGetShipping__rotten()
{
$mock = $this->getCustomerRottenMock(false);
$wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());

$this->assertEquals(
$wrapper->getShipping('phone'),
'1111111111'
);

$shipping = $wrapper->getShipping();
$this->assertNotNull($shipping->getCountryId());
}

private function _testGetShippingCountry__rotten()
{
$mock = $this->getCustomerRottenMock(false);
$wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());

$country = $wrapper->getShippingCountry();

$this->assertEquals(
$country->getIso(),
'DE'
);
}

private function getCustomerFreshMock($billingTest = true)
{
$country = new \Shopware\Models\Country\Country();
$country->setIso('BC');
Expand All @@ -51,9 +163,35 @@ private function getCustomerBillingFreshMock()

$stub = $this->createMock('Shopware\Models\Customer\Customer');

$stub->method('getDefaultBillingAddress')
$method = $billingTest ? 'getDefaultBillingAddress' : 'getDefaultShippingAddress';

$stub->method($method)
->willReturn($defaultBillingAddress);

return $stub;
}

private function getCustomerRottenMock($billingTest = true)
{
$country = new \Shopware\Models\Country\Country();
$country->setIso('BC');

$defaultBilling = new \Shopware\Models\Customer\Billing();
$defaultBilling->setPhone('1111111111');


$country = Shopware()->Models()->getRepository('Shopware\Models\Country\Country')
->findOneBy(['iso' => 'DE']);

$defaultBilling->setCountryId($country->getId());

$stub = $this->createMock('Shopware\Models\Customer\Customer');

$method = $billingTest ? 'getBilling' : 'getShipping';

$stub->method($method)
->willReturn($defaultBilling);

return $stub;
}
}
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
</filter>
<logging>
<log type="coverage-text" target="php://stdout"/>
<log type="coverage-html" target="/tmp/report"/>
</logging>
</phpunit>

0 comments on commit 120d737

Please sign in to comment.