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
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:

# Unit tests back (phpunit)
Expand All @@ -23,27 +26,39 @@ jobs:
env:
LARAVEL: 12.*
TESTBENCH: 10.*
- php: 8.5
env:
LARAVEL: 12.*
TESTBENCH: 10.*
env: ${{ matrix.env }}
name: P${{ matrix.php }} - L${{ matrix.env.LARAVEL }} - TB${{ matrix.env.TESTBENCH }}
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, dom, fileinfo, mysql

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: |
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: Execute tests (Unit and Feature tests) via PHPUnit
run: ./vendor/bin/phpunit
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "antoine@code16.fr"
}],
"require": {
"php": "^8.2|^8.3|^8.4",
"php": "^8.2|^8.3|^8.4|^8.5",
"laravel/framework": "^10.0|^11.0|^12.0",
"nesbot/carbon": "^2.0|^3.0",
"maatwebsite/excel": "^3.1",
Expand All @@ -18,7 +18,7 @@
"require-dev": {
"fakerphp/faker": "^1.19.0",
"mockery/mockery": "^1.3.0",
"phpunit/phpunit": "^10.0|^11.0",
"phpunit/phpunit": "^10.0|^11.0|^12.0",
"doctrine/dbal": "^3.0",
"orchestra/testbench": "6.*|7.*|8.*|9.*|10.*",
"code16/sharp": "^9.0",
Expand Down
11 changes: 6 additions & 5 deletions tests/Feature/FormojAnswerControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
use Code16\Formoj\Models\Field;
use Code16\Formoj\Tests\FormojTestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;

class FormojAnswerControllerTest extends FormojTestCase
{
use RefreshDatabase;
/** @test */

#[Test]
function we_cant_get_a_non_existing_answer()
{
$this->get("/formoj/api/answer/1")
->assertStatus(404);
}

/** @test */
#[Test]
function we_can_get_a_answer_with_fields()
{
$this->withoutExceptionHandling();
Expand Down Expand Up @@ -54,7 +55,7 @@ function we_can_get_a_answer_with_fields()
]);
}

/** @test */
#[Test]
function we_allow_missing_fields()
{
$this->withoutExceptionHandling();
Expand All @@ -79,7 +80,7 @@ function we_allow_missing_fields()
->assertJsonCount(0, "data.fields");
}

/** @test */
#[Test]
function we_can_get_only_field_of_the_current_answer()
{
$this->withoutExceptionHandling();
Expand Down
23 changes: 12 additions & 11 deletions tests/Feature/FormojFormControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
use Code16\Formoj\Tests\FormojTestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use PHPUnit\Framework\Attributes\Test;

class FormojFormControllerTest extends FormojTestCase
{
use RefreshDatabase;

/** @test */
#[Test]
function we_cant_get_a_non_existing_form()
{
$this->get("/formoj/api/form/1")
->assertStatus(404);
}

/** @test */
#[Test]
function we_can_get_a_form_properly_formatted()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -64,7 +65,7 @@ function we_can_get_a_form_properly_formatted()
]);
}

/** @test */
#[Test]
function we_can_get_a_form_with_a_text_field()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -96,7 +97,7 @@ function we_can_get_a_form_with_a_text_field()
]);
}

/** @test */
#[Test]
function we_can_get_a_form_with_a_textarea_field()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -130,7 +131,7 @@ function we_can_get_a_form_with_a_textarea_field()
]);
}

/** @test */
#[Test]
function we_can_get_a_form_with_a_single_select_field()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -169,7 +170,7 @@ function we_can_get_a_form_with_a_single_select_field()
]);
}

/** @test */
#[Test]
function we_can_get_a_form_with_a_multiple_select_field()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -211,7 +212,7 @@ function we_can_get_a_form_with_a_multiple_select_field()
]);
}

/** @test */
#[Test]
function we_can_get_a_form_with_an_heading_field()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -239,7 +240,7 @@ function we_can_get_a_form_with_an_heading_field()
]);
}

/** @test */
#[Test]
function we_can_get_a_form_with_an_upload_field()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -273,7 +274,7 @@ function we_can_get_a_form_with_an_upload_field()
]);
}

/** @test */
#[Test]
function we_can_not_get_a_not_published_already_form()
{
$form = Form::factory()->create([
Expand All @@ -285,7 +286,7 @@ function we_can_not_get_a_not_published_already_form()
->assertStatus(409);
}

/** @test */
#[Test]
function we_can_not_get_a_to_be_published_in_the_future_form()
{
$form = Form::factory()->create([
Expand All @@ -297,7 +298,7 @@ function we_can_not_get_a_to_be_published_in_the_future_form()
->assertStatus(409);
}

/** @test */
#[Test]
function we_can_get_a_form_with_valid_publish_dates()
{
$form = Form::factory()->create([
Expand Down
25 changes: 13 additions & 12 deletions tests/Feature/FormojFormFillControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use PHPUnit\Framework\Attributes\Test;

class FormojFormFillControllerTest extends FormojTestCase
{
use RefreshDatabase;

/** @test */
#[Test]
function we_can_fill_a_form_with_one_section()
{
Notification::fake();
Expand Down Expand Up @@ -59,7 +60,7 @@ function we_can_fill_a_form_with_one_section()
]);
}

/** @test */
#[Test]
function we_cant_fill_an_outdated_form()
{
Notification::fake();
Expand Down Expand Up @@ -97,7 +98,7 @@ function we_cant_fill_an_outdated_form()
->assertStatus(403);
}

/** @test */
#[Test]
function the_last_section_of_the_form_is_validated()
{
Notification::fake();
Expand Down Expand Up @@ -125,7 +126,7 @@ function the_last_section_of_the_form_is_validated()
]);
}

/** @test */
#[Test]
function we_store_only_the_form_data_with_the_answer()
{
$this->withoutExceptionHandling();
Expand Down Expand Up @@ -167,7 +168,7 @@ function we_store_only_the_form_data_with_the_answer()
]);
}

/** @test */
#[Test]
function we_can_update_an_existing_answer()
{
$this->withoutExceptionHandling();
Expand Down Expand Up @@ -207,7 +208,7 @@ function we_can_update_an_existing_answer()
$this->assertCount(1, $field->section->form->answers);
}

/** @test */
#[Test]
function we_dont_store_headings_with_the_answer()
{
Notification::fake();
Expand Down Expand Up @@ -244,7 +245,7 @@ function we_dont_store_headings_with_the_answer()
]);
}

/** @test */
#[Test]
function we_store_select_values_with_the_answer()
{
Notification::fake();
Expand Down Expand Up @@ -276,7 +277,7 @@ function we_store_select_values_with_the_answer()
]);
}

/** @test */
#[Test]
function we_store_multiple_select_values_with_the_answer()
{
Notification::fake();
Expand Down Expand Up @@ -309,7 +310,7 @@ function we_store_multiple_select_values_with_the_answer()
]);
}

/** @test */
#[Test]
function we_move_uploads_and_store_filename_with_the_answer()
{
$this->withoutExceptionHandling();
Expand Down Expand Up @@ -356,7 +357,7 @@ function we_move_uploads_and_store_filename_with_the_answer()
->assertExists("formoj/forms/{$field->section->form_id}/answers/{$answer->id}/image.jpg");
}

/** @test */
#[Test]
function posting_a_new_answer_sends_a_notification_if_configured()
{
Notification::fake();
Expand Down Expand Up @@ -386,7 +387,7 @@ function($notification, $channels, $notifiable) {
);
}

/** @test */
#[Test]
function posting_a_new_answer_does_not_sends_a_notification_if_not_configured()
{
Notification::fake();
Expand All @@ -410,7 +411,7 @@ function posting_a_new_answer_does_not_sends_a_notification_if_not_configured()
Notification::assertNotSentTo(new AnonymousNotifiable, FormojFormWasJustAnswered::class);
}

/** @test */
#[Test]
function all_sections_of_the_form_are_validated_if_validate_all_argument_is_passed()
{
Notification::fake();
Expand Down
13 changes: 7 additions & 6 deletions tests/Feature/FormojSectionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use Code16\Formoj\Models\Section;
use Code16\Formoj\Tests\FormojTestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;

class FormojSectionControllerTest extends FormojTestCase
{
use RefreshDatabase;

/** @test */
#[Test]
function we_get_a_422_when_posting_null_for_a_required_field()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -42,7 +43,7 @@ function we_get_a_422_when_posting_null_for_a_required_field()
->assertJsonMissingValidationErrors("f" . $field2->id);
}

/** @test */
#[Test]
function we_get_a_422_when_posting_a_too_long_text_with_a_max_length_property()
{
$field = Field::factory()->create([
Expand All @@ -67,7 +68,7 @@ function we_get_a_422_when_posting_a_too_long_text_with_a_max_length_property()
->assertJsonValidationErrors("f" . $field->id);
}

/** @test */
#[Test]
function we_get_a_422_when_posting_a_non_existing_value_to_a_single_select()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -108,7 +109,7 @@ function we_get_a_422_when_posting_a_non_existing_value_to_a_single_select()
->assertStatus(200);
}

/** @test */
#[Test]
function we_get_a_422_when_posting_a_non_existing_value_to_a_multiple_select()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -156,7 +157,7 @@ function we_get_a_422_when_posting_a_non_existing_value_to_a_multiple_select()
->assertStatus(200);
}

/** @test */
#[Test]
function we_get_a_422_when_posting_to_much_values_to_a_multiple_select_with_max_options()
{
$field = Field::factory()->create([
Expand Down Expand Up @@ -191,7 +192,7 @@ function we_get_a_422_when_posting_to_much_values_to_a_multiple_select_with_max_
->assertStatus(200);
}

/** @test */
#[Test]
function we_cant_validate_a_section_of_an_outdated_form()
{
$field = Field::factory()->create([
Expand Down
Loading
Loading