pull/885/head
Kei 1 year ago committed by GitHub
parent ebcde5a5c3
commit b1a5091ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,7 +29,7 @@
"mockery/mockery": "^1.5",
"nunomaduro/collision": "^7.0",
"nunomaduro/larastan": "^2.4",
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^10.0",
"psalm/plugin-laravel": "^2.7",
"realodix/relax": "dev-main",
"spatie/laravel-ignition": "^2.0"

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".tmp/PHPUnit/.phpunit.result.cache"
colors="true"
verbose="true"
>
<testsuites>
<testsuite name="Unit">
@ -16,10 +15,7 @@
</testsuite>
</testsuites>
<coverage
cacheDirectory=".tmp/PHPUnit"
processUncoveredFiles="true"
>
<coverage cacheDirectory=".tmp/PHPUnit">
<include>
<directory suffix=".php">./app</directory>
</include>

@ -10,7 +10,7 @@ class ConfirmPasswordTest extends TestCase
* @test
* @group f-auth
*/
public function userCanViewPasswordConfirm()
public function userCanViewPasswordConfirm(): void
{
$response = $this->actingAs($this->normalUser())
->get(route('password.confirm'));
@ -24,7 +24,7 @@ class ConfirmPasswordTest extends TestCase
* @test
* @group f-auth
*/
public function guestCantViewPasswordConfirm()
public function guestCantViewPasswordConfirm(): void
{
$response = $this->get(route('password.confirm'));
$response->assertRedirectToRoute('login');

@ -11,17 +11,17 @@ use Tests\TestCase;
class ForgotPasswordTest extends TestCase
{
protected function requestRoute()
protected function requestRoute(): string
{
return route('password.request');
}
protected function getRoute()
protected function getRoute(): string
{
return route('password.email');
}
protected function postRoute()
protected function postRoute(): string
{
return route('password.email');
}
@ -30,7 +30,7 @@ class ForgotPasswordTest extends TestCase
* @test
* @group f-auth
*/
public function userCanViewAnEmailPasswordForm()
public function userCanViewAnEmailPasswordForm(): void
{
$response = $this->get($this->requestRoute());
@ -43,7 +43,7 @@ class ForgotPasswordTest extends TestCase
* @test
* @group f-auth
*/
public function userReceivesAnEmailWithAPasswordResetLink()
public function userReceivesAnEmailWithAPasswordResetLink(): void
{
Notification::fake();
@ -67,7 +67,7 @@ class ForgotPasswordTest extends TestCase
* @test
* @group f-auth
*/
public function userDoesNotReceiveEmailWhenNotRegistered()
public function userDoesNotReceiveEmailWhenNotRegistered(): void
{
Notification::fake();
@ -87,7 +87,7 @@ class ForgotPasswordTest extends TestCase
* @test
* @group f-auth
*/
public function emailIsRequired()
public function emailIsRequired(): void
{
$response = $this->from($this->getRoute())
->post($this->postRoute(), []);
@ -101,7 +101,7 @@ class ForgotPasswordTest extends TestCase
* @test
* @group f-api
*/
public function emailIsAValidEmail()
public function emailIsAValidEmail(): void
{
$response = $this->from($this->getRoute())
->post($this->postRoute(), [

@ -8,22 +8,22 @@ use Tests\TestCase;
class LoginTest extends TestCase
{
protected function successfulLoginRoute()
protected function successfulLoginRoute(): string
{
return route('home');
}
protected function getRoute()
protected function getRoute(): string
{
return route('login');
}
protected function postRoute()
protected function postRoute(): string
{
return route('login');
}
protected function guestMiddlewareRoute()
protected function guestMiddlewareRoute(): string
{
return route('home');
}
@ -32,7 +32,7 @@ class LoginTest extends TestCase
* @test
* @group f-auth
*/
public function userCanViewALoginForm()
public function userCanViewALoginForm(): void
{
$response = $this->get($this->getRoute());
@ -45,7 +45,7 @@ class LoginTest extends TestCase
* @test
* @group f-auth
*/
public function userCannotViewALoginFormWhenAuthenticated()
public function userCannotViewALoginFormWhenAuthenticated(): void
{
$response = $this->actingAs($this->normalUser())
->get($this->getRoute());
@ -57,7 +57,7 @@ class LoginTest extends TestCase
* @test
* @group f-auth
*/
public function userCanLoginWithCorrectCredentials()
public function userCanLoginWithCorrectCredentials(): void
{
$user = User::factory()->create([
'password' => Hash::make($password = 'i-love-laravel'),
@ -76,7 +76,7 @@ class LoginTest extends TestCase
* @test
* @group f-auth
*/
public function userCannotLoginWithIncorrectPassword()
public function userCannotLoginWithIncorrectPassword(): void
{
$user = User::factory()->create([
'password' => Hash::make('i-love-laravel'),
@ -101,7 +101,7 @@ class LoginTest extends TestCase
* @test
* @group f-auth
*/
public function unauthenticatedUsersCantAccessTheDashboard()
public function unauthenticatedUsersCantAccessTheDashboard(): void
{
$this->get('/admin')->assertRedirect('/login');
}
@ -110,7 +110,7 @@ class LoginTest extends TestCase
* @test
* @group f-auth
*/
public function userCannotLoginWithEmailThatDoesNotExist()
public function userCannotLoginWithEmailThatDoesNotExist(): void
{
$response = $this->from($this->getRoute())
->post($this->postRoute(), [

@ -10,22 +10,22 @@ use Tests\TestCase;
class RegisterTest extends TestCase
{
protected function successfulRegistrationRoute()
protected function successfulRegistrationRoute(): string
{
return route('home');
}
protected function getRoute()
protected function getRoute(): string
{
return route('register');
}
protected function postRoute()
protected function postRoute(): string
{
return route('register');
}
protected function guestMiddlewareRoute()
protected function guestMiddlewareRoute(): string
{
return route('home');
}
@ -34,7 +34,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function userCanViewARegistrationForm()
public function userCanViewARegistrationForm(): void
{
$response = $this->get($this->getRoute());
@ -47,7 +47,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function userCannotViewARegistrationFormWhenAuthenticated()
public function userCannotViewARegistrationFormWhenAuthenticated(): void
{
$response = $this->actingAs($this->normalUser())
->get($this->getRoute());
@ -59,7 +59,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function userCanRegister()
public function userCanRegister(): void
{
Event::fake();
@ -88,7 +88,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function nameShouldNotBeTooLong()
public function nameShouldNotBeTooLong(): void
{
$response = $this->post('/register', [
'name' => str_repeat('a', 51),
@ -103,7 +103,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function userCannotRegisterWithoutName()
public function userCannotRegisterWithoutName(): void
{
$response = $this->from($this->getRoute())
->post($this->postRoute(), [
@ -127,7 +127,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function userCannotRegisterWithoutEmail()
public function userCannotRegisterWithoutEmail(): void
{
$response = $this->from($this->getRoute())
->post($this->postRoute(), [
@ -151,7 +151,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function userCannotRegisterWithInvalidEmail()
public function userCannotRegisterWithInvalidEmail(): void
{
$response = $this->from($this->getRoute())
->post($this->postRoute(), [
@ -176,7 +176,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function emailShouldNotBeTooLong()
public function emailShouldNotBeTooLong(): void
{
$response = $this->post('/register', [
'email' => str_repeat('a', 247).'@test.com', // 256
@ -190,7 +190,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function userCannotRegisterWithoutPassword()
public function userCannotRegisterWithoutPassword(): void
{
$response = $this->from($this->getRoute())
->post($this->postRoute(), [
@ -215,7 +215,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function userCannotRegisterWithoutPasswordConfirmation()
public function userCannotRegisterWithoutPasswordConfirmation(): void
{
$response = $this->from($this->getRoute())
->post($this->postRoute(), [
@ -240,7 +240,7 @@ class RegisterTest extends TestCase
* @test
* @group f-auth
*/
public function userCannotRegisterWithPasswordsNotMatching()
public function userCannotRegisterWithPasswordsNotMatching(): void
{
$response = $this->from($this->getRoute())
->post($this->postRoute(), [

@ -11,7 +11,7 @@ class AllUrlsPageTest extends TestCase
* @test
* @group f-allurl
*/
public function auAdminCanAccessThisPage()
public function auAdminCanAccessThisPage(): void
{
$response = $this->actingAs($this->adminUser())
->get(route('dashboard.allurl'));
@ -23,7 +23,7 @@ class AllUrlsPageTest extends TestCase
* @test
* @group f-allurl
*/
public function auNormalUserCantAccessThisPage()
public function auNormalUserCantAccessThisPage(): void
{
$response = $this->actingAs($this->normalUser())
->get(route('dashboard.allurl'));
@ -35,7 +35,7 @@ class AllUrlsPageTest extends TestCase
* @test
* @group f-allurl
*/
public function auAdminCanDelete()
public function auAdminCanDelete(): void
{
$url = Url::factory()->create();
@ -53,7 +53,7 @@ class AllUrlsPageTest extends TestCase
* @test
* @group f-allurl
*/
public function auNormalUserCantDelete()
public function auNormalUserCantDelete(): void
{
$url = Url::factory()->create();

@ -11,7 +11,7 @@ class DashboardPageTest extends TestCase
* @test
* @group f-dashboard
*/
public function dCanAccessPage()
public function dCanAccessPage(): void
{
$response = $this->actingAs($this->normalUser())
->get(route('dashboard'));
@ -23,7 +23,7 @@ class DashboardPageTest extends TestCase
* @test
* @group f-dashboard
*/
public function dCanDelete()
public function dCanDelete(): void
{
$url = Url::factory()->create();
@ -42,7 +42,7 @@ class DashboardPageTest extends TestCase
* @test
* @group f-dashboard
*/
public function dCanDuplicate()
public function dCanDuplicate(): void
{
$url = Url::factory()->create();
@ -61,7 +61,7 @@ class DashboardPageTest extends TestCase
* @test
* @group f-dashboard
*/
public function dAuthorizedUserCanAccessEditUrlPage()
public function dAuthorizedUserCanAccessEditUrlPage(): void
{
$url = Url::factory()->create();
@ -75,7 +75,7 @@ class DashboardPageTest extends TestCase
* @test
* @group f-dashboard
*/
public function dCanUpdateUrl()
public function dCanUpdateUrl(): void
{
$url = Url::factory()->create();

@ -7,12 +7,12 @@ use Tests\TestCase;
class ChangePasswordTest extends TestCase
{
protected function getRoute($value)
protected function getRoute(mixed $value): string
{
return route('user.change-password', $value);
}
protected function postRoute($value)
protected function postRoute(mixed $value): string
{
return $this->secureRoute('user.change-password.post', $value);
}
@ -21,14 +21,14 @@ class ChangePasswordTest extends TestCase
* @test
* @group f-user
*/
public function changePasswordWithCorrectCredentials()
public function changePasswordWithCorrectCredentials(): void
{
$user = $this->adminUser();
$response = $this->actingAs($user)
->from($this->getRoute($user->name))
->post($this->postRoute($user->id), [
'current-password' => $this->adminPass,
'current-password' => self::$adminPass,
'new-password' => 'new-awesome-password',
'new-password_confirmation' => 'new-awesome-password',
]);
@ -46,14 +46,14 @@ class ChangePasswordTest extends TestCase
* @test
* @group f-user
*/
public function adminCanChangeThePasswordOfAllUsers()
public function adminCanChangeThePasswordOfAllUsers(): void
{
$user = $this->normalUser();
$response = $this->actingAs($this->adminUser())
->from($this->getRoute($user->name))
->post($this->postRoute($user->id), [
'current-password' => $this->adminPass,
'current-password' => self::$adminPass,
'new-password' => 'new-awesome-password',
'new-password_confirmation' => 'new-awesome-password',
]);
@ -71,7 +71,7 @@ class ChangePasswordTest extends TestCase
* @test
* @group f-user
*/
public function currentPasswordDoesNotMatch()
public function currentPasswordDoesNotMatch(): void
{
$user = $this->adminUser();
@ -100,14 +100,14 @@ class ChangePasswordTest extends TestCase
* @param mixed $data1
* @param mixed $data2
*/
public function newPasswordValidateFail($data1, $data2)
public function newPasswordValidateFail($data1, $data2): void
{
$user = $this->normalUser();
$response = $this->actingAs($user)
->from($this->getRoute($user->name))
->post($this->postRoute($user->id), [
'current-password' => $this->adminPass,
'current-password' => self::$adminPass,
'new-password' => $data1,
'new-password_confirmation' => $data2,
]);
@ -121,11 +121,11 @@ class ChangePasswordTest extends TestCase
);
}
public function newPasswordFailProvider()
public static function newPasswordFailProvider(): array
{
return [
['', ''], // required
[$this->adminPass, $this->adminPass], // different
[self::$adminPass, self::$adminPass], // different
[null, null], // string
['new-password', 'new-pass-word'], // confirmed

@ -7,12 +7,12 @@ use Tests\TestCase;
class ProfileTest extends TestCase
{
protected function getRoute($value)
protected function getRoute(mixed $value): string
{
return route('user.edit', $value);
}
protected function postRoute($value)
protected function postRoute(mixed $value): string
{
return $this->secureRoute('user.update', $value);
}
@ -21,7 +21,7 @@ class ProfileTest extends TestCase
* @test
* @group f-user
*/
public function usersCanAccessTheirOwnProfilePage()
public function usersCanAccessTheirOwnProfilePage(): void
{
$user = $this->normalUser();
$response = $this->actingAs($user)
@ -34,7 +34,7 @@ class ProfileTest extends TestCase
* @test
* @group f-user
*/
public function adminCanAccessOtherUsersProfilePages()
public function adminCanAccessOtherUsersProfilePages(): void
{
$response = $this->actingAs($this->adminUser())
->get($this->getRoute($this->normalUser()->name));
@ -46,7 +46,7 @@ class ProfileTest extends TestCase
* @test
* @group f-user
*/
public function adminUserCantAccessOtherUsersProfilePages()
public function adminUserCantAccessOtherUsersProfilePages(): void
{
$response = $this->actingAs($this->normalUser())
->get($this->getRoute($this->adminUser()->name));
@ -58,7 +58,7 @@ class ProfileTest extends TestCase
* @test
* @group f-user
*/
public function adminCanChangeOtherUsersEmail()
public function adminCanChangeOtherUsersEmail(): void
{
$user = User::factory()->create(['email' => 'user_email@urlhub.test']);
@ -79,7 +79,7 @@ class ProfileTest extends TestCase
* @test
* @group f-user
*/
public function normalUserCantChangeOtherUsersEmail()
public function normalUserCantChangeOtherUsersEmail(): void
{
$user = User::factory()->create(['email' => 'user2@urlhub.test']);
@ -97,7 +97,7 @@ class ProfileTest extends TestCase
* @test
* @group f-user
*/
public function validationEmailRequired()
public function validationEmailRequired(): void
{
$user = $this->normalUser();
@ -116,7 +116,7 @@ class ProfileTest extends TestCase
* @test
* @group f-user
*/
public function validationEmailInvalidFormat()
public function validationEmailInvalidFormat(): void
{
$user = $this->normalUser();
@ -135,7 +135,7 @@ class ProfileTest extends TestCase
* @test
* @group f-user
*/
public function validationEmailMaxLength()
public function validationEmailMaxLength(): void
{
$user = $this->normalUser();
@ -155,7 +155,7 @@ class ProfileTest extends TestCase
* @test
* @group f-user
*/
public function validationEmailUnique()
public function validationEmailUnique(): void
{
$user = $this->normalUser();

@ -10,7 +10,7 @@ class UserListPageTest extends TestCase
* @test
* @group f-userlist
*/
public function ulpAdminCanAccessThisPage()
public function ulpAdminCanAccessThisPage(): void
{
$response = $this->actingAs($this->adminUser())
->get(route('user.index'));
@ -22,7 +22,7 @@ class UserListPageTest extends TestCase
* @test
* @group f-userlist
*/
public function ulpNormalUserCantAccessThisPage()
public function ulpNormalUserCantAccessThisPage(): void
{
$response = $this->actingAs($this->normalUser())
->get(route('user.index'));

@ -13,7 +13,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function shortenUrl()
public function shortenUrl(): void
{
$longUrl = 'https://laravel.com';
$response = $this->post(route('su_create'), [
@ -33,7 +33,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function shortenUrlWithCustomKeyword()
public function shortenUrlWithCustomKeyword(): void
{
$longUrl = 'https://laravel.com';
$customKey = 'laravel';
@ -59,7 +59,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function urlsWithOrWithoutSlashesWillBeConsideredTheSame()
public function urlsWithOrWithoutSlashesWillBeConsideredTheSame(): void
{
$longUrl_1 = 'https://example.com/';
$longUrl_2 = 'https://example.com';
@ -87,7 +87,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function longUrlAlreadyExist()
public function longUrlAlreadyExist(): void
{
$url = Url::factory()->create();
@ -110,7 +110,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function urlAlreadyExist_guestWithAnotherGuest()
public function urlAlreadyExist_guestWithAnotherGuest(): void
{
$url = Url::factory()->create([
'user_id' => Url::GUEST_ID,
@ -134,7 +134,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function longUrlAlreadyExistsButStillAccepted1()
public function longUrlAlreadyExistsButStillAccepted1(): void
{
$user = $this->normalUser();
$urlFromOtherUsers = Url::factory()->create();
@ -158,7 +158,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function longUrlAlreadyExistsButStillAccepted2()
public function longUrlAlreadyExistsButStillAccepted2(): void
{
$url = Url::factory()->create();
@ -180,7 +180,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function longUrlAlreadyExistsButStillAccepted3()
public function longUrlAlreadyExistsButStillAccepted3(): void
{
$user = $this->normalUser();
@ -210,7 +210,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function customKeyAlreadyExist()
public function customKeyAlreadyExist(): void
{
$url = Url::factory()->create([
'user_id' => Url::GUEST_ID,
@ -234,7 +234,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function customKeyAlreadyExist2()
public function customKeyAlreadyExist2(): void
{
$url = Url::factory()->create();
@ -256,7 +256,7 @@ class CreateShortLinkTest extends TestCase
*
* @test
*/
public function customKeyAlreadyExist3()
public function customKeyAlreadyExist3(): void
{
$url = Url::factory()->create();

@ -8,7 +8,7 @@ use Tests\TestCase;
class DeleteShortLinkTest extends TestCase
{
/** @test */
public function userCanDelete()
public function userCanDelete(): void
{
$url = Url::factory()->create();
@ -21,7 +21,7 @@ class DeleteShortLinkTest extends TestCase
}
/** @test */
public function adminCanDeleteUrlsCreatedByOtherUsers()
public function adminCanDeleteUrlsCreatedByOtherUsers(): void
{
$url = Url::factory()->create();
$response = $this->actingAs($this->adminUser())
@ -33,7 +33,7 @@ class DeleteShortLinkTest extends TestCase
}
/** @test */
public function adminCanDeleteUrlsCreatedByGuest()
public function adminCanDeleteUrlsCreatedByGuest(): void
{
$url = Url::factory()->create(['user_id' => Url::GUEST_ID]);
$response = $this->actingAs($this->adminUser())
@ -45,7 +45,7 @@ class DeleteShortLinkTest extends TestCase
}
/** @test */
public function userCannotDeleteUrlsCreatedByOtherUsers()
public function userCannotDeleteUrlsCreatedByOtherUsers(): void
{
$url = Url::factory()->create();
$response = $this->actingAs($this->normalUser())
@ -57,7 +57,7 @@ class DeleteShortLinkTest extends TestCase
}
/** @test */
public function userCannotDeleteUrlsCreatedByGuest()
public function userCannotDeleteUrlsCreatedByGuest(): void
{
$url = Url::factory()->create(['user_id' => Url::GUEST_ID]);
$response = $this->actingAs($this->normalUser())
@ -69,7 +69,7 @@ class DeleteShortLinkTest extends TestCase
}
/** @test */
public function guestCannotDelete()
public function guestCannotDelete(): void
{
$url = Url::factory()->create(['user_id' => Url::GUEST_ID]);
$response = $this->from(route('su_detail', $url->keyword))

@ -8,7 +8,7 @@ use Tests\TestCase;
class DuplicateShortLinkTest extends TestCase
{
/** @test */
public function duplicate()
public function duplicate(): void
{
$url = Url::factory()->create([
'user_id' => $this->adminUser()->id,
@ -25,7 +25,7 @@ class DuplicateShortLinkTest extends TestCase
}
/** @test */
public function duplicateUrlCreatedByGuest()
public function duplicateUrlCreatedByGuest(): void
{
$url = Url::factory()->create([
'user_id' => Url::GUEST_ID,
@ -43,7 +43,7 @@ class DuplicateShortLinkTest extends TestCase
}
/** @test */
public function guestCannotDuplicateUrl()
public function guestCannotDuplicateUrl(): void
{
$url = Url::factory()->create([
'user_id' => Url::GUEST_ID,

@ -7,7 +7,7 @@ use Tests\TestCase;
class ValidationTest extends TestCase
{
/** @test */
public function createShortUrlWithWrongUrlFormat()
public function createShortUrlWithWrongUrlFormat(): void
{
$response = $this->post(route('su_create'), [
'long_url' => 'wrong-url-format',
@ -19,7 +19,7 @@ class ValidationTest extends TestCase
}
/** @test */
public function customKeyValidation()
public function customKeyValidation(): void
{
$component = \Livewire\Livewire::test(\App\Http\Livewire\UrlCheck::class);

@ -11,7 +11,7 @@ class VisitTest extends TestCase
const BOT_UA = 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)';
/** @test */
public function logBotVisits()
public function logBotVisits(): void
{
config(['urlhub.track_bot_visits' => true]);
@ -23,7 +23,7 @@ class VisitTest extends TestCase
}
/** @test */
public function dontLogBotVisits()
public function dontLogBotVisits(): void
{
config(['urlhub.track_bot_visits' => false]);

@ -8,33 +8,33 @@ use Spatie\Permission\Models\Role;
trait Auth
{
protected $adminRole = 'admin';
protected static string $adminRole = 'admin';
protected $adminPass = 'admin';
protected static string $adminPass = 'admin';
protected function setUp(): void
{
parent::setUp();
// create permissions
Permission::create(['name' => $this->adminRole]);
Permission::create(['name' => self::$adminRole]);
// create roles and assign created permissions
$adminRole = Role::create(['name' => $this->adminRole]);
$adminRole = Role::create(['name' => self::$adminRole]);
$adminRole->givePermissionTo(Permission::all());
}
protected function adminUser()
protected function adminUser(): User
{
$admin = User::factory()->create([
'password' => bcrypt($this->adminPass),
'password' => bcrypt(self::$adminPass),
]);
$admin->assignRole($this->adminRole);
$admin->assignRole(self::$adminRole);
return $admin;
}
protected function normalUser()
protected function normalUser(): User
{
return User::factory()->create();
}

@ -2,14 +2,16 @@
namespace Tests\Support;
use Illuminate\Validation\Validator;
class Helper
{
public static function validator(array $data, array $rules)
public static function validator(array $data, array $rules): Validator
{
$trans = new \Illuminate\Translation\Translator(
new \Illuminate\Translation\ArrayLoader, 'en'
);
$validator = new \Illuminate\Validation\Validator($trans, $data, $rules);
$validator = new Validator($trans, $data, $rules);
return $validator;
}

@ -12,7 +12,7 @@ abstract class TestCase extends BaseTestCase
use RefreshDatabase;
use Auth, CreatesApplication;
protected function secureRoute($routeName, $url_id)
protected function secureRoute(array|string $routeName, mixed $url_id): string
{
return route($routeName, encrypt($url_id));
}

@ -14,7 +14,7 @@ class UrlControllerTest extends TestCase
* @test
* @group u-controller
*/
public function guestShortenURL()
public function guestShortenURL(): void
{
$longUrl = 'https://laravel.com';
@ -33,7 +33,7 @@ class UrlControllerTest extends TestCase
* @test
* @group u-controller
*/
public function userShortenURL()
public function userShortenURL(): void
{
$user = $this->normalUser();
$longUrl = 'https://laravel.com';

@ -12,7 +12,7 @@ class UrlRedirectControllerTest extends TestCase
* @test
* @group u-controller
*/
public function urlRedirection()
public function urlRedirection(): void
{
$url = Url::factory()->create();

@ -7,10 +7,8 @@ use Tests\TestCase;
class HelperTest extends TestCase
{
/**
* @test
*/
public function urlDisplay()
/** @test */
public function urlDisplay(): void
{
$this->assertSame(
'https://example.com/abcde/',
@ -35,12 +33,12 @@ class HelperTest extends TestCase
* @param mixed $expected
* @param mixed $actual
*/
public function urlDisplayWithoutScheme($expected, $actual)
public function urlDisplayWithoutScheme($expected, $actual): void
{
$this->assertSame($expected, Helper::urlDisplay($actual, scheme: false));
}
public function urlDisplayWithoutSchemeProvider()
public static function urlDisplayWithoutSchemeProvider(): array
{
return [
['example.com', 'example.com'],
@ -61,7 +59,7 @@ class HelperTest extends TestCase
* @param mixed $expected
* @param mixed $actual
*/
public function compactNumber($expected, $actual)
public function compactNumber($expected, $actual): void
{
$this->assertSame($expected, Helper::compactNumber($actual));
}
@ -70,13 +68,13 @@ class HelperTest extends TestCase
* @test
* @group u-helper
*/
public function numberFormatPrecision()
public function numberFormatPrecision(): void
{
$this->assertSame(19.12, Helper::numberFormatPrecision(19.123456));
$this->assertSame(19.123, Helper::numberFormatPrecision(19.123456, 3));
}
public function toAmountShortProvider()
public static function toAmountShortProvider(): array
{
return [
['12', 12],

@ -12,7 +12,7 @@ class UrlHubLinkCheckerTest extends TestCase
*
* @param array $value
*/
public function keywordBlacklistFail($value)
public function keywordBlacklistFail($value): void
{
$response = $this->post(route('su_create'), [
'long_url' => 'https://laravel.com',
@ -30,7 +30,7 @@ class UrlHubLinkCheckerTest extends TestCase
*
* @test
*/
public function idleCapacityZero()
public function idleCapacityZero(): void
{
config(['urlhub.hash_length' => 0]);
@ -43,7 +43,7 @@ class UrlHubLinkCheckerTest extends TestCase
->assertSessionHas('flash_error');
}
public function keywordBlacklistFailDataProvider()
public static function keywordBlacklistFailDataProvider(): array
{
return [
['login'],

@ -25,7 +25,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function belongsToUserModel()
public function belongsToUserModel(): void
{
$url = Url::factory()->create();
@ -40,7 +40,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function hasManyUrlModel()
public function hasManyUrlModel(): void
{
$v = Visit::factory()->create();
@ -54,7 +54,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function defaultGuestName()
public function defaultGuestName(): void
{
$url = Url::factory()->create([
'user_id' => Url::GUEST_ID,
@ -69,7 +69,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function defaultGuestId()
public function defaultGuestId(): void
{
$longUrl = 'https://example.com';
@ -86,7 +86,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function setUserIdAttributeMustBeNull()
public function setUserIdAttributeMustBeNull(): void
{
$url = Url::factory()->create([
'user_id' => 0,
@ -99,7 +99,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function setLongUrlAttribute()
public function setLongUrlAttribute(): void
{
$url = Url::factory()->create([
'destination' => 'http://example.com/',
@ -114,7 +114,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function getShortUrlAttribute()
public function getShortUrlAttribute(): void
{
$url = Url::factory()->create();
$url->whereUserId($url->author->id)->first();
@ -128,7 +128,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function setMetaTitleAttributeWhenWebTitleSetToFalse()
public function setMetaTitleAttributeWhenWebTitleSetToFalse(): void
{
config()->set('urlhub.web_title', false);
@ -143,7 +143,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function totalShortUrlByGuest()
public function totalShortUrlByGuest(): void
{
Url::factory()->create([
'user_id' => Url::GUEST_ID,
@ -157,7 +157,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function totalClicks()
public function totalClicks(): void
{
Visit::factory()->create();
@ -170,7 +170,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function numberOfClicks()
public function numberOfClicks(): void
{
$v = Visit::factory()->create([
'is_first_click' => true,
@ -190,7 +190,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function numberOfClicksAndUnique()
public function numberOfClicksAndUnique(): void
{
$v = Visit::factory()->create([
'is_first_click' => true,
@ -212,7 +212,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function numberOfClicksPerAuthor()
public function numberOfClicksPerAuthor(): void
{
$visit = Visit::factory()
->for(Url::factory())
@ -231,7 +231,7 @@ class UrlTest extends TestCase
* @test
* @group u-model
*/
public function numberOfClicksFromGuests()
public function numberOfClicksFromGuests(): void
{
$visit = Visit::factory()
->for(

@ -12,7 +12,7 @@ class UserTest extends TestCase
* @test
* @group u-model
*/
public function hasManyUrlModel()
public function hasManyUrlModel(): void
{
$user = User::factory()
->has(Url::factory())
@ -28,7 +28,7 @@ class UserTest extends TestCase
* @test
* @group u-model
*/
public function totalGuestUsers()
public function totalGuestUsers(): void
{
$this->assertSame(0, (new User)->totalGuestUsers());
}

@ -17,7 +17,7 @@ class VisitTest extends TestCase
* @test
* @group u-model
*/
public function belongsToUrlModel()
public function belongsToUrlModel(): void
{
$visit = Visit::factory()
->create();

@ -13,7 +13,7 @@ class UrlPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function forceDeleteAdmin()
public function forceDeleteAdmin(): void
{
$admin = $this->adminUser();
$url = Url::factory()->create([
@ -31,7 +31,7 @@ class UrlPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function forceDeleteNormalUser()
public function forceDeleteNormalUser(): void
{
$url = Url::factory()->create();

@ -13,7 +13,7 @@ class UserPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function viewAsAdmin()
public function viewAsAdmin(): void
{
$admin = $this->adminUser();
@ -27,7 +27,7 @@ class UserPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function viewAsNormalUser()
public function viewAsNormalUser(): void
{
$user = $this->normalUser();
@ -41,7 +41,7 @@ class UserPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function updateAsAdmin()
public function updateAsAdmin(): void
{
$admin = $this->adminUser();
@ -55,7 +55,7 @@ class UserPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function updateAsNormalUser()
public function updateAsNormalUser(): void
{
$user = $this->normalUser();
@ -69,7 +69,7 @@ class UserPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function updatePassAsAdmin()
public function updatePassAsAdmin(): void
{
$admin = $this->adminUser();
@ -83,7 +83,7 @@ class UserPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function updatePassAsNormalUser()
public function updatePassAsNormalUser(): void
{
$user = $this->normalUser();
@ -94,7 +94,8 @@ class UserPolicyTest extends TestCase
//
// Change Password.
//
protected function getCPRoute($value)
protected function getCPRoute(mixed $value): string
{
return route('user.change-password', $value);
}
@ -103,7 +104,7 @@ class UserPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function adminCanAccessChangePasswordPage()
public function adminCanAccessChangePasswordPage(): void
{
$response = $this->actingAs($this->adminUser())
->get($this->getCPRoute($this->normalUser()->name));
@ -117,7 +118,7 @@ class UserPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function normalUserCantAccessOtherUsersChangePasswordPage()
public function normalUserCantAccessOtherUsersChangePasswordPage(): void
{
$response = $this->actingAs($this->normalUser())
->get($this->getCPRoute($this->adminUser()->name));
@ -126,7 +127,7 @@ class UserPolicyTest extends TestCase
}
/** @test */
public function normalUserCanAccessTheirOwnChangePasswordPage()
public function normalUserCanAccessTheirOwnChangePasswordPage(): void
{
$response =$this->actingAs($this->adminUser())
->get($this->getCPRoute($this->adminUser()->name));
@ -142,7 +143,7 @@ class UserPolicyTest extends TestCase
* @test
* @group u-policy
*/
public function adminCanAccessAllUsersPage()
public function adminCanAccessAllUsersPage(): void
{
$response = $this->actingAs($this->adminUser())
->get(route('user.index'));
@ -150,10 +151,8 @@ class UserPolicyTest extends TestCase
$response->assertOk();
}
/**
* @test
*/
public function normalUserCantAccessAllUsersPage()
/** @test */
public function normalUserCantAccessAllUsersPage(): void
{
$response = $this->actingAs($this->normalUser())
->get(route('user.index'));

@ -18,9 +18,9 @@ class PwdCurrentTest extends TestCase
/**
* @group u-rule
*/
public function testPwdCurrentPass()
public function testPwdCurrentPass(): void
{
$val = Helper::validator(['foo' => $this->adminPass], ['foo' => new PwdCurrent]);
$val = Helper::validator(['foo' => self::$adminPass], ['foo' => new PwdCurrent]);
$this->assertTrue($val->passes());
$this->assertSame([], $val->messages()->messages());
@ -29,7 +29,7 @@ class PwdCurrentTest extends TestCase
/**
* @group u-rule
*/
public function testPwdCurrentFail()
public function testPwdCurrentFail(): void
{
$val = Helper::validator(['foo' => 'bar'], ['foo' => new PwdCurrent]);

@ -12,7 +12,7 @@ class StrAlphaUnderscoreTest extends TestCase
* @test
* @group u-rule
*/
public function strAlphaUnderscorePass()
public function strAlphaUnderscorePass(): void
{
$val = Helper::validator(['foo' => 'foo_bar'], ['foo' => new StrAlphaUnderscore]);
@ -24,7 +24,7 @@ class StrAlphaUnderscoreTest extends TestCase
* @test
* @group u-rule
*/
public function strAlphaUnderscoreFail()
public function strAlphaUnderscoreFail(): void
{
$val = Helper::validator(['foo' => 'foo-bar'], ['foo' => new StrAlphaUnderscore]);
$this->assertTrue($val->fails());

@ -23,7 +23,7 @@ class UrlTest extends TestCase
*
* @param mixed $value
*/
public function domainBlacklistPass($value)
public function domainBlacklistPass($value): void
{
$val = Helper::validator(['foo' => $value], ['foo' => new DomainBlacklist]);
@ -38,7 +38,7 @@ class UrlTest extends TestCase
*
* @param mixed $value
*/
public function domainBlacklistFail($value)
public function domainBlacklistFail($value): void
{
$val = Helper::validator(['foo' => $value], ['foo' => new DomainBlacklist]);
@ -51,7 +51,7 @@ class UrlTest extends TestCase
], $val->messages()->messages());
}
public function domainBlacklistPassDataProvider()
public static function domainBlacklistPassDataProvider(): array
{
return [
['http://t.com/about'],
@ -61,7 +61,7 @@ class UrlTest extends TestCase
];
}
public function domainBlacklistFailDataProvider()
public static function domainBlacklistFailDataProvider(): array
{
return [
['https://github.com/laravel/laravel'],
@ -76,7 +76,7 @@ class UrlTest extends TestCase
*
* @param string $value
*/
public function customKeywordBlacklistPass($value)
public function customKeywordBlacklistPass($value): void
{
$val = Helper::validator(['foo' => $value], ['foo' => new KeywordBlacklist]);
@ -91,7 +91,7 @@ class UrlTest extends TestCase
*
* @param array $value
*/
public function customKeywordContainsRegisteredRouteWillFail($value)
public function customKeywordContainsRegisteredRouteWillFail($value): void
{
$val = Helper::validator(['foo' => $value], ['foo' => new KeywordBlacklist]);
@ -99,7 +99,7 @@ class UrlTest extends TestCase
$this->assertSame(['foo' => ['Not available.']], $val->messages()->messages());
}
public function customKeywordContainsReservedKeywordWillFail()
public function customKeywordContainsReservedKeywordWillFail(): void
{
$value = 'css';
config(['urlhub.reserved_keyword' => $value]);
@ -110,7 +110,7 @@ class UrlTest extends TestCase
$this->assertSame(['foo' => ['Not available.']], $val->messages()->messages());
}
public function customKeywordBlacklistPassDataProvider()
public static function customKeywordBlacklistPassDataProvider(): array
{
return [
['hello'],
@ -118,7 +118,7 @@ class UrlTest extends TestCase
];
}
public function customKeywordContainsRegisteredRouteWillFailDataProvider()
public static function customKeywordContainsRegisteredRouteWillFailDataProvider(): array
{
return [
['login'],

@ -36,7 +36,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function urlKey_default_value()
public function urlKey_default_value(): void
{
$length = 3;
config(['urlhub.hash_length' => $length]);
@ -54,7 +54,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function urlKey_generated_string()
public function urlKey_generated_string(): void
{
$length = 3;
config(['urlhub.hash_length' => $length]);
@ -74,7 +74,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function urlKey_specified_hash_length()
public function urlKey_specified_hash_length(): void
{
config(['urlhub.hash_length' => 6]);
$actual = 'https://github.com/realodix';
@ -99,7 +99,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function urlKey_specified_character()
public function urlKey_specified_character(): void
{
$url = 'https://example.com/abc';
config(['urlhub.hash_length' => 3]);
@ -122,7 +122,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function urlKey_prevent_reserved_keyword()
public function urlKey_prevent_reserved_keyword(): void
{
$actual = 'https://example.com/css';
$expected = 'css';
@ -141,7 +141,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function urlKey_prevent_generating_strings_that_are_in_registered_route_path()
public function urlKey_prevent_generating_strings_that_are_in_registered_route_path(): void
{
$actual = 'https://example.com/admin';
$expected = 'admin';
@ -155,7 +155,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function generateSimpleString()
public function generateSimpleString(): void
{
config(['urlhub.hash_length' => 3]);
@ -167,7 +167,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function assertStringCanBeUsedAsKey()
public function assertStringCanBeUsedAsKey(): void
{
$this->assertTrue($this->keyGeneratorService->assertStringCanBeUsedAsKey('foo'));
$this->assertFalse($this->keyGeneratorService->assertStringCanBeUsedAsKey('login'));
@ -177,7 +177,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function maxCapacity()
public function maxCapacity(): void
{
$hashLength = config('urlhub.hash_length');
$hashCharLength = strlen(config('urlhub.hash_char'));
@ -192,7 +192,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function usedCapacity()
public function usedCapacity(): void
{
config(['urlhub.hash_length' => config('urlhub.hash_length') + 1]);
@ -228,7 +228,7 @@ class KeyGeneratorServiceTest extends TestCase
* @test
* @group u-model
*/
public function usedCapacity2()
public function usedCapacity2(): void
{
config(['urlhub.hash_length' => 3]);
@ -272,7 +272,7 @@ class KeyGeneratorServiceTest extends TestCase
* @param mixed $ku
* @param mixed $expected
*/
public function idleCapacity($kc, $ku, $expected)
public function idleCapacity($kc, $ku, $expected): void
{
$mock = \Mockery::mock(KeyGeneratorService::class)->makePartial();
$mock->shouldReceive([
@ -284,7 +284,7 @@ class KeyGeneratorServiceTest extends TestCase
$this->assertSame($expected, $actual);
}
public function idleCapacityProvider()
public static function idleCapacityProvider(): array
{
// maxCapacity(), usedCapacity(), expected_result
return [
@ -305,7 +305,7 @@ class KeyGeneratorServiceTest extends TestCase
* @param mixed $ku
* @param mixed $expected
*/
public function idleCapacityInPercent($kc, $ku, $expected)
public function idleCapacityInPercent($kc, $ku, $expected): void
{
// https://ralphjsmit.com/laravel-mock-dependencies
$mock = \Mockery::mock(KeyGeneratorService::class)->makePartial();
@ -318,7 +318,7 @@ class KeyGeneratorServiceTest extends TestCase
$this->assertSame($expected, $actual);
}
public function idleCapacityInPercentProvider()
public static function idleCapacityInPercentProvider(): array
{
// maxCapacity(), usedCapacity(), expected_result
return [

@ -17,7 +17,7 @@ class QrCodeServiceTest extends TestCase
* @test
* @group u-actions
*/
public function QrCodeService()
public function QrCodeService(): void
{
$QrCode = $this->getQrCode()->execute('foo');
@ -28,7 +28,7 @@ class QrCodeServiceTest extends TestCase
* @test
* @group u-actions
*/
public function sizeMin()
public function sizeMin(): void
{
$size = QrCodeService::MIN_SIZE - 1;
config(['urlhub.qrcode_size' => $size]);
@ -43,7 +43,7 @@ class QrCodeServiceTest extends TestCase
* @test
* @group u-actions
*/
public function sizeMax()
public function sizeMax(): void
{
$size = QrCodeService::MAX_SIZE + 1;
config(['urlhub.qrcode_size' => $size]);

@ -16,10 +16,8 @@ class UHubLinkServiceTest extends TestCase
$this->uHubLinkService = app(UHubLinkService::class);
}
/**
* @test
*/
public function title()
/** @test */
public function title(): void
{
$expected = 'example123456789.com - Untitled';
$actual = $this->uHubLinkService->title('https://example123456789.com');

Loading…
Cancel
Save