-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from magento-south/BUGS
[South] Sprint #52
- Loading branch information
Showing
48 changed files
with
304 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/code/Magento/Customer/Model/Plugin/CustomerRepository/TransactionWrapper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Plugin for \Magento\Customer\Api\CustomerRepositoryInterface | ||
* | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Model\Plugin\CustomerRepository; | ||
|
||
class TransactionWrapper | ||
{ | ||
/** | ||
* @var \Magento\Customer\Model\ResourceModel\Customer | ||
*/ | ||
protected $resourceModel; | ||
|
||
/** | ||
* @param \Magento\Customer\Model\ResourceModel\Customer $resourceModel | ||
*/ | ||
public function __construct( | ||
\Magento\Customer\Model\ResourceModel\Customer $resourceModel | ||
) { | ||
$this->resourceModel = $resourceModel; | ||
} | ||
|
||
/** | ||
* @param \Magento\Customer\Api\CustomerRepositoryInterface $subject | ||
* @param callable $proceed | ||
* @param \Magento\Customer\Api\Data\CustomerInterface $customer | ||
* @param string $passwordHash | ||
* @return \Magento\Customer\Api\Data\CustomerInterface | ||
* @throws \Exception | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function aroundSave( | ||
\Magento\Customer\Api\CustomerRepositoryInterface $subject, | ||
\Closure $proceed, | ||
\Magento\Customer\Api\Data\CustomerInterface $customer, | ||
$passwordHash = null | ||
) { | ||
$this->resourceModel->beginTransaction(); | ||
try { | ||
/** @var $result \Magento\Customer\Api\Data\CustomerInterface */ | ||
$result = $proceed($customer, $passwordHash); | ||
$this->resourceModel->commit(); | ||
return $result; | ||
} catch (\Exception $e) { | ||
$this->resourceModel->rollBack(); | ||
throw $e; | ||
} | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...ode/Magento/Customer/Test/Unit/Model/Plugin/CustomerRepository/TransactionWrapperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Test\Unit\Model\Plugin\CustomerRepository; | ||
|
||
class TransactionWrapperTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Customer\Model\Plugin\CustomerRepository\TransactionWrapper | ||
*/ | ||
protected $model; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Model\ResourceModel\Customer | ||
*/ | ||
protected $resourceMock; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Api\CustomerRepositoryInterface | ||
*/ | ||
protected $subjectMock; | ||
|
||
/** | ||
* @var \Closure | ||
*/ | ||
protected $closureMock; | ||
|
||
/** | ||
* @var \Closure | ||
*/ | ||
protected $rollbackClosureMock; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $customerMock; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $passwordHash = true; | ||
|
||
const ERROR_MSG = "error occurred"; | ||
|
||
protected function setUp() | ||
{ | ||
$this->resourceMock = $this->getMock('Magento\Customer\Model\ResourceModel\Customer', [], [], '', false); | ||
$this->subjectMock = $this->getMock('Magento\Customer\Api\CustomerRepositoryInterface', [], [], '', false); | ||
$this->customerMock = $this->getMock('Magento\Customer\Api\Data\CustomerInterface', [], [], '', false); | ||
$customerMock = $this->customerMock; | ||
$this->closureMock = function () use ($customerMock) { | ||
return $customerMock; | ||
}; | ||
$this->rollbackClosureMock = function () use ($customerMock) { | ||
throw new \Exception(self::ERROR_MSG); | ||
}; | ||
|
||
$this->model = new \Magento\Customer\Model\Plugin\CustomerRepository\TransactionWrapper($this->resourceMock); | ||
} | ||
|
||
public function testAroundSaveCommit() | ||
{ | ||
$this->resourceMock->expects($this->once())->method('beginTransaction'); | ||
$this->resourceMock->expects($this->once())->method('commit'); | ||
|
||
$this->assertEquals( | ||
$this->customerMock, | ||
$this->model->aroundSave($this->subjectMock, $this->closureMock, $this->customerMock, $this->passwordHash) | ||
); | ||
} | ||
|
||
/** | ||
* @expectedException \Exception | ||
* @expectedExceptionMessage error occurred | ||
*/ | ||
public function testAroundSaveRollBack() | ||
{ | ||
$this->resourceMock->expects($this->once())->method('beginTransaction'); | ||
$this->resourceMock->expects($this->once())->method('rollBack'); | ||
|
||
$this->model->aroundSave( | ||
$this->subjectMock, | ||
$this->rollbackClosureMock, | ||
$this->customerMock, | ||
$this->passwordHash | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.