Skip to content

Commit e5958b1

Browse files
committed
LYNX-232: Fix unit tests
1 parent f986d18 commit e5958b1

File tree

2 files changed

+37
-50
lines changed

2 files changed

+37
-50
lines changed

app/code/Magento/Customer/Test/Unit/Model/SessionTest.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -250,51 +250,6 @@ protected function prepareLoginDataMock(int $customerId): MockObject
250250
return $customerDataMock;
251251
}
252252

253-
/**
254-
* @param bool $expectedResult
255-
* @param bool $isCustomerIdValid
256-
* @param bool $isCustomerEmulated
257-
*
258-
* @return void
259-
* @dataProvider getIsLoggedInDataProvider
260-
*/
261-
public function testIsLoggedIn(
262-
bool $expectedResult,
263-
bool $isCustomerIdValid,
264-
bool $isCustomerEmulated
265-
): void {
266-
$customerId = 1;
267-
$this->_storageMock->expects($this->any())->method('getData')->with('customer_id')
268-
->willReturn($customerId);
269-
270-
if ($isCustomerIdValid) {
271-
$this->customerRepositoryMock->expects($this->once())
272-
->method('getById')
273-
->with($customerId);
274-
} else {
275-
$this->customerRepositoryMock->expects($this->once())
276-
->method('getById')
277-
->with($customerId)
278-
->willThrowException(new \Exception('Customer ID is invalid.'));
279-
}
280-
$this->_storageMock->expects($this->any())->method('getIsCustomerEmulated')
281-
->willReturn($isCustomerEmulated);
282-
$this->assertEquals($expectedResult, $this->_model->isLoggedIn());
283-
}
284-
285-
/**
286-
* @return array
287-
*/
288-
public function getIsLoggedInDataProvider(): array
289-
{
290-
return [
291-
['expectedResult' => true, 'isCustomerIdValid' => true, 'isCustomerEmulated' => false],
292-
['expectedResult' => false, 'isCustomerIdValid' => true, 'isCustomerEmulated' => true],
293-
['expectedResult' => false, 'isCustomerIdValid' => false, 'isCustomerEmulated' => false],
294-
['expectedResult' => false, 'isCustomerIdValid' => false, 'isCustomerEmulated' => true]
295-
];
296-
}
297-
298253
/**
299254
* @return void
300255
*/

dev/tests/integration/testsuite/Magento/Customer/Model/SessionTest.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\App\PageCache\FormKey;
99
use Magento\Framework\App\Response\Http as HttpResponse;
1010
use Magento\Framework\App\ResponseInterface;
11+
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\Framework\Session\SidResolverInterface;
1213
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1314
use Magento\Framework\Stdlib\Cookie\PublicCookieMetadata;
@@ -32,11 +33,6 @@ class SessionTest extends \PHPUnit\Framework\TestCase
3233
/** @var PublicCookieMetadata $cookieMetadata */
3334
protected $cookieMetadata;
3435

35-
/**
36-
* @var HttpResponse
37-
*/
38-
private $response;
39-
4036
protected function setUp(): void
4137
{
4238
$this->_customerSession = Bootstrap::getObjectManager()->create(
@@ -66,6 +62,42 @@ public function testLoginById()
6662
$this->assertTrue($this->_customerSession->isLoggedIn());
6763
}
6864

65+
/**
66+
* @param bool $expectedResult
67+
* @param bool $isCustomerIdValid
68+
* @param bool $isCustomerEmulated
69+
*
70+
* @return void
71+
* @dataProvider getIsLoggedInDataProvider
72+
*/
73+
public function testIsLoggedIn(
74+
bool $expectedResult,
75+
bool $isCustomerIdValid,
76+
bool $isCustomerEmulated
77+
): void {
78+
if ($isCustomerIdValid) {
79+
$this->_customerSession->loginById(1);
80+
} else {
81+
$this->_customerSession->setCustomerId(1);
82+
$this->_customerSession->setId(2);
83+
}
84+
$this->_customerSession->setIsCustomerEmulated($isCustomerEmulated);
85+
$this->assertEquals($expectedResult, $this->_customerSession->isLoggedIn());
86+
}
87+
88+
/**
89+
* @return array
90+
*/
91+
public function getIsLoggedInDataProvider(): array
92+
{
93+
return [
94+
['expectedResult' => true, 'isCustomerIdValid' => true, 'isCustomerEmulated' => false],
95+
['expectedResult' => false, 'isCustomerIdValid' => true, 'isCustomerEmulated' => true],
96+
['expectedResult' => false, 'isCustomerIdValid' => false, 'isCustomerEmulated' => false],
97+
['expectedResult' => false, 'isCustomerIdValid' => false, 'isCustomerEmulated' => true]
98+
];
99+
}
100+
69101
public function testLoginByIdCustomerDataLoadedCorrectly()
70102
{
71103
$fixtureCustomerId = 1;

0 commit comments

Comments
 (0)