Level 73
I use this package https://github.com/nektos/act to test GitHub actions locally. The environment that you use for testing does not match the GitHub actions one, so that might be one of the reasons.
3 likes
Hi all,
I'm trying to get a pipeline on GitHub actions working, but for some reason, I get 403 errors but not locally. These are the errors (I use Pest PHP for testing):
• Tests\Feature\Endpoints\EndpointTest > an endpoint detail page can be viewed when authenticated
PHPUnit\Framework\ExceptionWrapper
This action is unauthorized.
at vendor/laravel/framework/src/Illuminate/Auth/Access/Response.php:151
147▕ */
148▕ public function authorize()
149▕ {
150▕ if ($this->denied()) {
➜ 151▕ throw (new AuthorizationException($this->message(), $this->code()))
152▕ ->setResponse($this)
153▕ ->withStatus($this->status);
154▕ }
155▕
• Tests\Feature\Endpoints\EndpointTest > the endpoint editing page can be viewed when authenticated
Expected response status code [200] but received 403.
Failed asserting that 200 is identical to 403.
at tests/Feature/Endpoints/EndpointTest.php:61
57▕ $endpoint = createEndpoint($user = createUser());
58▕
59▕ $response = actingAs($user)->get(route('endpoints.edit', $endpoint));
60▕
➜ 61▕ $response->assertStatus(200);
62▕ });
63▕
64▕ test('an endpoint editing page can only be viewed by the endpoint owner', function () {
65▕ $endpoint = createEndpoint($user = createUser());
• Tests\Feature\Endpoints\EndpointTest > an endpoint can be updated when authenticated
Failed asserting that a row in the table [endpoints] matches the attributes {
"name": "Dr. Sonny Langosh IV",
"notify_email": "[email protected]"
}.
Found: [
{
"name": "Lavina Pollich",
"notify_email": null
}
].
at tests/Feature/Endpoints/EndpointTest.php:82
78▕ 'name' => faker()->name,
79▕ 'notify_email' => faker()->email
80▕ ]);
81▕
➜ 82▕ assertDatabaseHas('endpoints', $attributes);
83▕
84▕ $response->assertStatus(302);
85▕ });
86▕
• Tests\Feature\Endpoints\EndpointTest > an endpoint can be deleted when authenticated
Failed asserting that a row in the table [endpoints] does not match the attributes {
"id": 1
}.
Found similar results: [
{
"id": "1"
}
].
at tests/Feature/Endpoints/EndpointTest.php:107
103▕
104▕ $response = actingAs($user)->delete(route('endpoints.destroy', $endpoint));
105▕
106▕ assertDatabaseMissing('endpoints', [
➜ 107▕ 'id' => $endpoint->id
108▕ ]);
109▕
110▕ $response->assertStatus(302);
111▕ });
Tests: 4 failed, 7 skipped, 31 passed
Time: 2.07s
Error: Process completed with exit code 2.
I believe my laravel.yml file is correct:
name: Laravel
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
laravel-tests:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '8.0'
- uses: actions/checkout@v3
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Update Dependencies
run: composer update
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Install NPM
run: npm install
- name: Compile assets
run: npm run build
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Create Database
run: |
mkdir -p database
touch database/database.sqlite
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: vendor/bin/pest
What is happening here? Why are they failing on GitHub but not locally? If someone can help me a bit in the right direction that would be great.
Please or to participate in this conversation.