codesniffer fixes

This commit is contained in:
2023-10-20 11:10:33 +10:00
parent ba6f67798d
commit 8233afa825
67 changed files with 608 additions and 394 deletions

View File

@@ -9,6 +9,8 @@ trait CreatesApplication
{
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication(): Application
{

View File

@@ -1,5 +1,7 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Models\User;
@@ -11,15 +13,29 @@ final class ArticlesApiTest extends TestCase
{
use RefreshDatabase;
/**
* Faker Factory instance.
* @var Faker\Factory
*/
protected $faker;
/**
* {@inheritDoc}
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->faker = FakerFactory::create();
}
/**
* Tests that any user can view an article if it's published and not in the future.
*
* @return void
*/
public function testAnyUserCanViewArticle(): void
{
// Create an event
@@ -51,6 +67,11 @@ final class ArticlesApiTest extends TestCase
]);
}
/**
* Tests that an admin can create, update, and delete articles.
*
* @return void
*/
public function testAdminCanCreateUpdateDeleteArticle(): void
{
// Create a user with the admin/events permission
@@ -102,6 +123,11 @@ final class ArticlesApiTest extends TestCase
]);
}
/**
* Tests that a non-admin user cannot create, update, or delete articles.
*
* @return void
*/
public function testNonAdminCannotCreateUpdateDeleteArticle(): void
{
// Create a user without admin/events permission

View File

@@ -1,5 +1,7 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Models\User;
@@ -9,6 +11,20 @@ final class AuthApiTest extends TestCase
use RefreshDatabase;
/**
* Tests the login, user retrieval, and logout functionality of the Auth API.
*
* This test performs the following steps:
* 1. Creates a new user using a factory.
* 2. Attempts a successful login with the correct credentials,
* checks for a 200 status code, and verifies the structure of the returned token.
* 3. Retrieves the authenticated user's data using the token,
* checks for a 200 status code, and verifies the returned user data.
* 4. Logs out the authenticated user using the token and checks for a 204 status code.
* 5. Attempts a failed login with incorrect credentials and checks for a 422 status code.
*
* @return void
*/
public function testLogin(): void
{
$user = User::factory()->create([

View File

@@ -1,5 +1,7 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
@@ -8,6 +10,17 @@ final class ContactFormTest extends TestCase
use RefreshDatabase;
/**
* Tests the contact form submission API endpoint.
*
* This test performs two POST requests to the '/api/contact' endpoint
* using the `postJson` method. The first request contains valid data and
* should return a 201 status code, indicating a successful creation.
* The second request omits the 'email' field, which should cause a
* validation error and return a 422 status code.
*
* @return void
*/
public function testContactForm(): void
{
$formData = [

View File

@@ -1,5 +1,7 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Models\User;
@@ -12,15 +14,29 @@ final class EventsApiTest extends TestCase
{
use RefreshDatabase;
/**
* Faker Factory instance.
* @var Faker\Factory
*/
protected $faker;
/**
* {@inheritDoc}
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->faker = FakerFactory::create();
}
/**
* Tests that any user can view an event if it's published and not in the future.
*
* @return void
*/
public function testAnyUserCanViewEvent(): void
{
// Create an event
@@ -52,6 +68,11 @@ final class EventsApiTest extends TestCase
]);
}
/**
* Tests that any user cannot see draft events.
*
* @return void
*/
public function testAnyUserCannotSeeDraftEvent(): void
{
// Create a draft event
@@ -85,6 +106,11 @@ final class EventsApiTest extends TestCase
]);
}
/**
* Tests that an admin can create, update, and delete events.
*
* @return void
*/
public function testAdminCanCreateUpdateDeleteEvent(): void
{
// Create a user with the admin/events permission
@@ -139,6 +165,11 @@ final class EventsApiTest extends TestCase
]);
}
/**
* Tests that a non-admin user cannot create, update, or delete events.
*
* @return void
*/
public function testNonAdminCannotCreateUpdateDeleteEvent(): void
{
// Create a user without admin/events permission

View File

@@ -1,5 +1,7 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
@@ -10,6 +12,11 @@ final class UsersApiTest extends TestCase
use RefreshDatabase;
/**
* Tests that non-admin users can only view basic user info.
*
* @return void
*/
public function testNonAdminUsersCanOnlyViewBasicUserInfo(): void
{
// create a non-admin user
@@ -67,6 +74,11 @@ final class UsersApiTest extends TestCase
]);
}
/**
* Tests that guests cannot create a user via the API.
*
* @return void
*/
public function testGuestCannotCreateUser(): void
{
$userData = [
@@ -81,6 +93,11 @@ final class UsersApiTest extends TestCase
]);
}
/**
* Tests that guests can register a user via the API.
*
* @return void
*/
public function testGuestCanRegisterUser(): void
{
$userData = [
@@ -98,6 +115,11 @@ final class UsersApiTest extends TestCase
]);
}
/**
* Tests that duplicate email or display name entries cannot be created.
*
* @return void
*/
public function testCannotCreateDuplicateEmailOrDisplayName(): void
{
$userData = [
@@ -121,6 +143,11 @@ final class UsersApiTest extends TestCase
$response->assertJsonValidationErrors(['display_name', 'email']);
}
/**
* Tests that a user can only update their own user info.
*
* @return void
*/
public function testUserCanOnlyUpdateOwnUser(): void
{
$user = User::factory()->create();
@@ -149,6 +176,11 @@ final class UsersApiTest extends TestCase
$response->assertStatus(403);
}
/**
* Tests that a user cannot delete users via the API.
*
* @return void
*/
public function testUserCannotDeleteUsers(): void
{
$user = User::factory()->create();
@@ -165,6 +197,11 @@ final class UsersApiTest extends TestCase
$this->assertDatabaseHas('users', ['id' => $otherUser->id]);
}
/**
* Tests that an admin can update any user's info.
*
* @return void
*/
public function testAdminCanUpdateAnyUser(): void
{
$admin = User::factory()->create();
@@ -200,6 +237,11 @@ final class UsersApiTest extends TestCase
]);
}
/**
* Tests that an admin can delete any user via the API.
*
* @return void
*/
public function testAdminCanDeleteAnyUser(): void
{
$admin = User::factory()->create();

View File

@@ -9,6 +9,11 @@ abstract class TestCase extends BaseTestCase
use CreatesApplication;
/**
* {@inheritDoc}
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();

View File

@@ -8,6 +8,8 @@ final class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function test_that_true_is_true(): void
{