• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daycry / auth / 16344800892

17 Jul 2025 12:13PM UTC coverage: 66.494% (+6.6%) from 59.854%
16344800892

push

github

daycry
Add comprehensive unit tests for helpers and services

This commit introduces extensive unit tests for helper functions (auth, checkEndpoint, checkIp, email), libraries (CheckIpInRange, Logger), and service classes (AttemptHandler, ExceptionHandler, RequestLogger). Also fixes ReflectionProperty usage in ExceptionHandler to correctly pass the exception object. These tests improve code coverage and ensure reliability of authentication, endpoint, IP checking, email, logging, and exception handling features.

1 of 1 new or added line in 1 file covered. (100.0%)

136 existing lines in 8 files now uncovered.

2177 of 3274 relevant lines covered (66.49%)

32.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Controllers/LoginController.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Auth.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Daycry\Auth\Controllers;
15

16
use CodeIgniter\HTTP\RedirectResponse;
17
use CodeIgniter\HTTP\ResponseInterface;
18
use Daycry\Auth\Validation\ValidationRules;
19

20
class LoginController extends BaseAuthController
21
{
22
    /**
23
     * Displays the form the login to the site.
24
     */
25
    public function loginView(): ResponseInterface
26
    {
27
        // Check if already logged in
UNCOV
28
        if ($redirect = $this->redirectIfLoggedIn()) {
×
UNCOV
29
            return $redirect;
×
30
        }
31

32
        // Check if there's a pending post-auth action
UNCOV
33
        if ($this->hasPostAuthAction()) {
×
UNCOV
34
            return $this->redirectToAuthAction();
×
35
        }
36

37
        $content = $this->view(setting('Auth.views')['login']);
×
38

UNCOV
39
        return $this->response->setBody($content);
×
40
    }
41

42
    /**
43
     * Attempts to log the user in.
44
     */
45
    public function loginAction(): RedirectResponse
46
    {
47
        // Validate input
48
        $rules    = $this->getValidationRules();
×
UNCOV
49
        $postData = $this->request->getPost();
×
50

UNCOV
51
        if (! $this->validateRequest($postData, $rules)) {
×
UNCOV
52
            return $this->handleValidationError(config('Auth')->loginRoute());
×
53
        }
54

55
        // Extract credentials and remember preference
UNCOV
56
        $credentials = $this->extractLoginCredentials();
×
UNCOV
57
        $remember    = $this->shouldRememberUser();
×
58

59
        // Attempt authentication
60
        $authenticator = $this->getSessionAuthenticator();
×
61
        $result        = $authenticator->remember($remember)->attempt($credentials);
×
62

UNCOV
63
        return $this->handleAuthResult($result, config('Auth')->loginRoute());
×
64
    }
65

66
    /**
67
     * Returns the rules that should be used for validation.
68
     *
69
     * @return         array<string, array<string, list<string>|string>>
70
     * @phpstan-return array<string, array<string, string|list<string>>>
71
     */
72
    protected function getValidationRules(): array
73
    {
74
        $rules = new ValidationRules();
×
75

76
        return $rules->getLoginRules();
×
77
    }
78

79
    /**
80
     * Logs the current user out.
81
     */
82
    public function logoutAction(): RedirectResponse
83
    {
84
        // Capture logout redirect URL before auth logout
UNCOV
85
        $url = config('Auth')->logoutRedirect();
×
86

UNCOV
87
        auth()->logout();
×
88

UNCOV
89
        return $this->handleSuccess($url, lang('Auth.successLogout'));
×
90
    }
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc