7
7
8
8
namespace Magento \Customer \Test \Unit \Model \ForgotPasswordToken ;
9
9
10
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
10
11
use Magento \Customer \Api \Data \CustomerInterface ;
11
- use Magento \Customer \Model \ForgotPasswordToken \GetCustomerByToken ;
12
- use Magento \Customer \Model \ResourceModel \Customer as CustomerResource ;
13
- use Magento \Customer \Model \ResourceModel \Customer ;
14
12
use Magento \Customer \Model \ForgotPasswordToken \ConfirmCustomerByToken ;
13
+ use Magento \Customer \Model \ForgotPasswordToken \GetCustomerByToken ;
15
14
use PHPUnit \Framework \MockObject \MockObject ;
16
15
use PHPUnit \Framework \TestCase ;
17
16
@@ -33,22 +32,26 @@ class ConfirmCustomerByTokenTest extends TestCase
33
32
private $ customerMock ;
34
33
35
34
/**
36
- * @var CustomerResource |MockObject
35
+ * @var CustomerRepositoryInterface |MockObject
37
36
*/
38
- private $ customerResourceMock ;
37
+ private $ customerRepositoryMock ;
39
38
40
39
/**
41
40
* @inheritDoc
42
41
*/
43
42
protected function setUp (): void
44
43
{
45
- $ this ->customerMock = $ this ->getMockForAbstractClass (CustomerInterface::class);
46
- $ this ->customerResourceMock = $ this ->createMock (CustomerResource::class);
44
+ $ this ->customerMock = $ this ->getMockBuilder (CustomerInterface::class)
45
+ ->disableOriginalConstructor ()
46
+ ->addMethods (['setData ' ])
47
+ ->getMockForAbstractClass ();
48
+
49
+ $ this ->customerRepositoryMock = $ this ->createMock (CustomerRepositoryInterface::class);
47
50
48
51
$ getCustomerByTokenMock = $ this ->createMock (GetCustomerByToken::class);
49
52
$ getCustomerByTokenMock ->method ('execute ' )->willReturn ($ this ->customerMock );
50
53
51
- $ this ->model = new ConfirmCustomerByToken ($ getCustomerByTokenMock , $ this ->customerResourceMock );
54
+ $ this ->model = new ConfirmCustomerByToken ($ getCustomerByTokenMock , $ this ->customerRepositoryMock );
52
55
}
53
56
54
57
/**
@@ -58,17 +61,18 @@ protected function setUp(): void
58
61
*/
59
62
public function testExecuteWithConfirmation (): void
60
63
{
61
- $ customerId = 777 ;
62
-
63
64
$ this ->customerMock ->expects ($ this ->once ())
64
65
->method ('getConfirmation ' )
65
66
->willReturn ('GWz2ik7Kts517MXAgrm4DzfcxKayGCm4 ' );
66
67
$ this ->customerMock ->expects ($ this ->once ())
67
- ->method ('getId ' )
68
- ->willReturn ($ customerId );
69
- $ this ->customerResourceMock ->expects ($ this ->once ())
70
- ->method ('updateColumn ' )
71
- ->with ($ customerId , 'confirmation ' , null );
68
+ ->method ('setData ' )
69
+ ->with ('ignore_validation_flag ' , true );
70
+ $ this ->customerMock ->expects ($ this ->once ())
71
+ ->method ('setConfirmation ' )
72
+ ->with (null );
73
+ $ this ->customerRepositoryMock ->expects ($ this ->once ())
74
+ ->method ('save ' )
75
+ ->with ($ this ->customerMock );
72
76
73
77
$ this ->model ->execute (self ::STUB_RESET_PASSWORD_TOKEN );
74
78
}
@@ -83,8 +87,8 @@ public function testExecuteWithoutConfirmation(): void
83
87
$ this ->customerMock ->expects ($ this ->once ())
84
88
->method ('getConfirmation ' )
85
89
->willReturn (null );
86
- $ this ->customerResourceMock ->expects ($ this ->never ())
87
- ->method ('updateColumn ' );
90
+ $ this ->customerRepositoryMock ->expects ($ this ->never ())
91
+ ->method ('save ' );
88
92
89
93
$ this ->model ->execute (self ::STUB_RESET_PASSWORD_TOKEN );
90
94
}
0 commit comments