|
7 | 7 | use Closure; |
8 | 8 | use Codeception\Configuration; |
9 | 9 | use Codeception\Exception\ModuleConfigException; |
10 | | -use Codeception\Exception\ModuleException; |
11 | 10 | use Codeception\Lib\Connector\Laravel as LaravelConnector; |
12 | 11 | use Codeception\Lib\Framework; |
13 | 12 | use Codeception\Lib\Interfaces\ActiveRecord; |
14 | 13 | use Codeception\Lib\Interfaces\PartedModule; |
15 | 14 | use Codeception\Lib\ModuleContainer; |
| 15 | +use Codeception\Module\Laravel\InteractsWithAuthentication; |
16 | 16 | use Codeception\Subscriber\ErrorHandler; |
17 | 17 | use Codeception\TestInterface; |
18 | 18 | use Codeception\Util\ReflectionHelper; |
19 | 19 | use Exception; |
20 | | -use Illuminate\Contracts\Auth\Authenticatable; |
21 | | -use Illuminate\Contracts\Auth\Factory as AuthContract; |
22 | 20 | use Illuminate\Contracts\Console\Kernel; |
23 | 21 | use Illuminate\Contracts\Routing\UrlGenerator; |
24 | 22 | use Illuminate\Contracts\Session\Session; |
|
132 | 130 | */ |
133 | 131 | class Laravel extends Framework implements ActiveRecord, PartedModule |
134 | 132 | { |
| 133 | + use InteractsWithAuthentication; |
| 134 | + |
135 | 135 | /** |
136 | 136 | * @var Application |
137 | 137 | */ |
@@ -791,81 +791,6 @@ public function seeFormErrorMessage(string $field, $errorMessage = null): void |
791 | 791 | } |
792 | 792 | } |
793 | 793 |
|
794 | | - /** |
795 | | - * Set the currently logged in user for the application. |
796 | | - * Takes either an object that implements the User interface or |
797 | | - * an array of credentials. |
798 | | - * |
799 | | - * ``` php |
800 | | - * <?php |
801 | | - * // provide array of credentials |
802 | | - * $I->amLoggedAs(['username' => 'jane@example.com', 'password' => 'password']); |
803 | | - * |
804 | | - * // provide User object |
805 | | - * $I->amLoggedAs( new User ); |
806 | | - * |
807 | | - * // can be verified with $I->seeAuthentication(); |
808 | | - * ``` |
809 | | - * @param Authenticatable|array $user |
810 | | - * @param string|null $guardName The guard name |
811 | | - */ |
812 | | - public function amLoggedAs($user, ?string $guardName = null): void |
813 | | - { |
814 | | - /** @var AuthContract $auth */ |
815 | | - $auth = $this->app['auth']; |
816 | | - |
817 | | - $guard = $auth->guard($guardName); |
818 | | - |
819 | | - if ($user instanceof Authenticatable) { |
820 | | - $guard->login($user); |
821 | | - return; |
822 | | - } |
823 | | - |
824 | | - $this->assertTrue($guard->attempt($user), 'Failed to login with credentials ' . json_encode($user)); |
825 | | - } |
826 | | - |
827 | | - /** |
828 | | - * Logout user. |
829 | | - */ |
830 | | - public function logout(): void |
831 | | - { |
832 | | - $this->app['auth']->logout(); |
833 | | - } |
834 | | - |
835 | | - /** |
836 | | - * Checks that a user is authenticated. |
837 | | - * You can specify the guard that should be use as second parameter. |
838 | | - * |
839 | | - * @param string|null $guard |
840 | | - */ |
841 | | - public function seeAuthentication($guard = null): void |
842 | | - { |
843 | | - /** @var AuthContract $auth */ |
844 | | - $auth = $this->app['auth']; |
845 | | - |
846 | | - $auth = $auth->guard($guard); |
847 | | - |
848 | | - $this->assertTrue($auth->check(), 'There is no authenticated user'); |
849 | | - } |
850 | | - |
851 | | - /** |
852 | | - * Check that user is not authenticated. |
853 | | - * You can specify the guard that should be use as second parameter. |
854 | | - * |
855 | | - * @param string|null $guard |
856 | | - */ |
857 | | - public function dontSeeAuthentication(?string $guard = null): void |
858 | | - { |
859 | | - /** @var AuthContract $auth */ |
860 | | - $auth = $this->app['auth']; |
861 | | - |
862 | | - if (is_string($guard)) { |
863 | | - $auth = $auth->guard($guard); |
864 | | - } |
865 | | - |
866 | | - $this->assertNotTrue($auth->check(), 'There is an user authenticated'); |
867 | | - } |
868 | | - |
869 | 794 | /** |
870 | 795 | * Return an instance of a class from the Laravel service container. |
871 | 796 | * (https://laravel.com/docs/master/container) |
|
0 commit comments