@@ -126,6 +126,48 @@ public function testAttemptReturnsFalseIfUserNotGiven()
126
126
$ this ->assertFalse ($ mock ->attempt (['foo ' ]));
127
127
}
128
128
129
+ public function testAttemptAndWithCallbacks ()
130
+ {
131
+ [$ session , $ provider , $ request , $ cookie ] = $ this ->getMocks ();
132
+ $ mock = $ this ->getMockBuilder (SessionGuard::class)->onlyMethods (['getName ' ])->setConstructorArgs (['default ' , $ provider , $ session , $ request ])->getMock ();
133
+ $ mock ->setDispatcher ($ events = m::mock (Dispatcher::class));
134
+ $ user = m::mock (Authenticatable::class);
135
+ $ events ->shouldReceive ('dispatch ' )->times (3 )->with (m::type (Attempting::class));
136
+ $ events ->shouldReceive ('dispatch ' )->once ()->with (m::type (Login::class));
137
+ $ events ->shouldReceive ('dispatch ' )->once ()->with (m::type (Authenticated::class));
138
+ $ events ->shouldReceive ('dispatch ' )->twice ()->with (m::type (Validated::class));
139
+ $ events ->shouldReceive ('dispatch ' )->twice ()->with (m::type (Failed::class));
140
+ $ mock ->expects ($ this ->once ())->method ('getName ' )->willReturn ('foo ' );
141
+ $ user ->shouldReceive ('getAuthIdentifier ' )->once ()->andReturn ('bar ' );
142
+ $ mock ->getSession ()->shouldReceive ('put ' )->with ('foo ' , 'bar ' )->once ();
143
+ $ session ->shouldReceive ('migrate ' )->once ();
144
+ $ mock ->getProvider ()->shouldReceive ('retrieveByCredentials ' )->times (3 )->with (['foo ' ])->andReturn ($ user );
145
+ $ mock ->getProvider ()->shouldReceive ('validateCredentials ' )->twice ()->andReturnTrue ();
146
+ $ mock ->getProvider ()->shouldReceive ('validateCredentials ' )->once ()->andReturnFalse ();
147
+
148
+ $ this ->assertTrue ($ mock ->attemptWith (['foo ' ], false , function ($ user , $ guard ) {
149
+ static ::assertInstanceOf (Authenticatable::class, $ user );
150
+ static ::assertInstanceOf (SessionGuard::class, $ guard );
151
+
152
+ return true ;
153
+ }));
154
+
155
+ $ this ->assertFalse ($ mock ->attemptWith (['foo ' ], false , function ($ user , $ guard ) {
156
+ static ::assertInstanceOf (Authenticatable::class, $ user );
157
+ static ::assertInstanceOf (SessionGuard::class, $ guard );
158
+
159
+ return false ;
160
+ }));
161
+
162
+ $ executed = false ;
163
+
164
+ $ this ->assertFalse ($ mock ->attemptWith (['foo ' ], false , function () use (&$ executed ) {
165
+ return $ executed = true ;
166
+ }));
167
+
168
+ $ this ->assertFalse ($ executed );
169
+ }
170
+
129
171
public function testLoginStoresIdentifierInSession ()
130
172
{
131
173
[$ session , $ provider , $ request , $ cookie ] = $ this ->getMocks ();
0 commit comments