Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:
strategy:
matrix:
include:
- php: 8.5
env:
laravel: 12.*
testbench: 10.*
- php: 8.4
env:
laravel: 10.*
Expand Down Expand Up @@ -51,6 +55,9 @@ jobs:
composer require "laravel/framework:${laravel}" "orchestra/testbench:${testbench}" --no-interaction --no-update --prefer-dist
composer update --prefer-stable --prefer-dist --no-interaction

- name: Run Security Audit
run: composer audit

- name: List Installed Dependencies
run: composer show -D

Expand Down
15 changes: 8 additions & 7 deletions tests/Feature/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Code16\Machina\Tests\Feature;

use Code16\Machina\Tests\MachinaTestCase;
use PHPUnit\Framework\Attributes\Test;

class AuthenticationTest extends MachinaTestCase
{
Expand All @@ -15,7 +16,7 @@ public function setUp(): void
})->middleware('auth:machina');
}

/** @test */
#[Test]
function client_can_access_a_protected_route_with_a_valid_token_in_header()
{
$client = $this->createClient("1234");
Expand All @@ -34,7 +35,7 @@ function client_can_access_a_protected_route_with_a_valid_token_in_header()
$response->assertStatus(200);
}

/** @test */
#[Test]
function client_can_access_a_protected_route_with_a_valid_token_in_url()
{
$client = $this->createClient("1234");
Expand All @@ -50,14 +51,14 @@ function client_can_access_a_protected_route_with_a_valid_token_in_url()
$response->assertStatus(200);
}

/** @test */
#[Test]
function accessing_a_protected_route_without_a_token_returns_400()
{
$response = $this->json('get', '/protected');
$response->assertStatus(400);
}

/** @test */
#[Test]
function accessing_a_protected_route_with_an_invalid_token_returns_401()
{
$headers = [
Expand All @@ -67,7 +68,7 @@ function accessing_a_protected_route_with_an_invalid_token_returns_401()
$response->assertStatus(400);
}

/** @test */
#[Test]
function user_is_authenticated_when_a_protected_route_is_accessed()
{
$client = $this->createClient("1234");
Expand All @@ -88,7 +89,7 @@ function user_is_authenticated_when_a_protected_route_is_accessed()
$this->assertEquals($client->id, auth()->user()->id);
}

/** @test */
#[Test]
function token_is_not_returned_inside_response_headers_when_not_refreshed_by_middleware()
{
$client = $this->createClient("1234");
Expand All @@ -108,7 +109,7 @@ function token_is_not_returned_inside_response_headers_when_not_refreshed_by_mid
$this->assertFalse(array_key_exists("authorization", $response->headers->all()));
}

/** @test */
#[Test]
function user_is_set_after_a_successful_authentication()
{
$this->app->make('router')->get('user', function() {
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/GenerateKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Artisan;
use Code16\Machina\Tests\MachinaTestCase;
use PHPUnit\Framework\Attributes\Test;

class GenerateKeyTest extends MachinaTestCase
{

/** @test */
#[Test]
function we_can_call_the_artisan_command_to_generate_keys()
{
Artisan::call('machina:keys');
Expand Down
9 changes: 5 additions & 4 deletions tests/Feature/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Code16\Machina\Tests\Feature;

use Code16\Machina\Tests\MachinaTestCase;
use PHPUnit\Framework\Attributes\Test;

class LoginTest extends MachinaTestCase
{
/** @test */
#[Test]
function login_with_valid_credentials_returns_a_jwt_token()
{
$client = $this->createClient("1234");
Expand All @@ -18,7 +19,7 @@ function login_with_valid_credentials_returns_a_jwt_token()
$response->assertStatus(200);
}

/** @test */
#[Test]
function login_with_invalid_credentials_returns_a_401()
{
$client = $this->createClient("1234");
Expand All @@ -28,9 +29,9 @@ function login_with_invalid_credentials_returns_a_401()
];
$response = $this->json('post', '/auth/login', $data);
$response->assertStatus(401);
}
}

/** @test */
#[Test]
function login_with_no_credentials_parameters_returns_a_401()
{
$client = $this->createClient("1234");
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/RefreshTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Code16\Machina\Middleware\RefreshToken;
use Code16\Machina\Tests\MachinaTestCase;
use PHPUnit\Framework\Attributes\Test;

class RefreshTest extends MachinaTestCase
{

/** @test */
#[Test]
function we_can_refresh_the_token_using_middleware()
{
$this->app
Expand Down