Skip to content

Commit 04d3d4c

Browse files
authored
Clean tests files for latest dependencies (#59)
* Add github workflow (wip) * Add `composer require nesbot/carbon:^2.68.1 --dev` * wip * Drop PHP 7.3 and laravel below v8 * Manage test files Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * Use pestphp Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * Allow using pest v1 for a lower laravel version Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * wip Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * Install laravel/pint, then run it on test folder Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * Use laravel/pint:^1.5 Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * Convert test to pest Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * wip Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * Use defineDatabaseMigrations() Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * Make database test migration realtime Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * Make model dynamic Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * ide helper Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> * ide helper Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com> --------- Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com>
1 parent ffbdeee commit 04d3d4c

38 files changed

+888
-1007
lines changed

.github/workflows/run-tests.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
os: [ubuntu-latest, windows-latest]
12+
php: [8.0, 8.1, 8.2]
13+
laravel: [^8.83.27, ^9.51.0, ^10.0.0]
14+
stability: [prefer-lowest, prefer-stable]
15+
include:
16+
- laravel: ^10.0.0
17+
testbench: ^8.0.0
18+
- laravel: ^9.51.0
19+
testbench: ^7.22.0
20+
- laravel: ^8.83.27
21+
testbench: ^6.25.1
22+
exclude:
23+
- php: 8.0
24+
laravel: ^10.0.0
25+
- php: 8.1
26+
laravel: ^8.83.27
27+
28+
29+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
30+
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v3
34+
35+
- name: Setup PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: ${{ matrix.php }}
39+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
40+
coverage: xdebug
41+
42+
- name: Setup problem matchers
43+
run: |
44+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
45+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
46+
47+
- name: Install dependencies
48+
run: |
49+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
50+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
51+
composer require nesbot/carbon:^2.68.1
52+
53+
- name: List Installed Dependencies
54+
run: composer show -D
55+
56+
- name: Execute test
57+
run: composer test -- --ci

composer.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
}
2323
],
2424
"require": {
25-
"php": "^7.3|^8.0",
26-
"laravel/framework": "~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0"
25+
"php": "^8.0",
26+
"illuminate/contracts": "^8.83.27|^9.51.0|^10.0.0",
27+
"spatie/laravel-package-tools": "^1.12"
2728
},
2829
"require-dev": {
29-
"orchestra/testbench": "~3.8|^4.0|^5.0|^7.0|^8.0",
30+
"orchestra/testbench": "^6.25.1|^7.22.0|^8.0.0",
3031
"mockery/mockery": "^0.9.4 || ~1.0",
31-
"phpunit/phpunit": "~8.5|^9.0"
32+
"pestphp/pest": "^1.23.1|^2.11",
33+
"pestphp/pest-plugin-laravel": "^1.4|^2.1",
34+
"laravel/pint": "^1.5"
3235
},
3336
"autoload": {
3437
"psr-4": {
@@ -51,6 +54,13 @@
5154
}
5255
},
5356
"scripts": {
54-
"test": "vendor/bin/phpunit"
57+
"test": "vendor/bin/pest",
58+
"format": "vendor/bin/pint",
59+
"format-dryrun": "vendor/bin/pint --test"
60+
},
61+
"config": {
62+
"allow-plugins": {
63+
"pestphp/pest-plugin": true
64+
}
5565
}
5666
}

src/config/gamify.php renamed to config/gamify.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
return [
46
// Model which will be having points, generally it will be User
57
'payee_model' => '\App\User',
@@ -33,5 +35,5 @@
3335
],
3436

3537
// Default level
36-
'badge_default_level' => 1
38+
'badge_default_level' => 1,
3739
];

src/migrations/add_reputation_on_user_table.php.stub renamed to database/migrations/add_reputation_on_user_table.php.stub

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Illuminate\Support\Facades\Schema;
46
use Illuminate\Database\Schema\Blueprint;
57
use Illuminate\Database\Migrations\Migration;
68

79
class AddReputationFieldOnUserTable extends Migration
810
{
9-
/**
10-
* Run the migrations.
11-
*
12-
* @return void
13-
*/
14-
public function up()
11+
public function up(): void
1512
{
16-
Schema::table('users', function (Blueprint $table) {
13+
Schema::table(app(config('gamify.payee_model'))->getTable(), function (Blueprint $table) {
1714
$table->unsignedInteger('reputation')->default(0)->after('remember_token');
1815
});
1916
}
2017

21-
/**
22-
* Reverse the migrations.
23-
*
24-
* @return void
25-
*/
26-
public function down()
18+
public function down(): void
2719
{
28-
Schema::table('users', function (Blueprint $table) {
20+
Schema::table(app(config('gamify.payee_model'))->getTable(), function (Blueprint $table) {
2921
$table->dropColumn('reputation');
3022
});
3123
}

src/migrations/create_gamify_tables.php.stub renamed to database/migrations/create_gamify_tables.php.stub

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Illuminate\Support\Facades\Schema;
46
use Illuminate\Database\Schema\Blueprint;
57
use Illuminate\Database\Migrations\Migration;
68

79
class CreateGamifyTables extends Migration
810
{
9-
/**
10-
* Run the migrations.
11-
*
12-
* @return void
13-
*/
14-
public function up()
11+
public function up(): void
1512
{
16-
// reputations table
1713
Schema::create('reputations', function (Blueprint $table) {
1814
$table->increments('id');
1915
$table->string('name');
@@ -25,7 +21,6 @@ class CreateGamifyTables extends Migration
2521
$table->timestamps();
2622
});
2723

28-
// badges table
2924
Schema::create('badges', function (Blueprint $table) {
3025
$table->increments('id');
3126
$table->string('name');
@@ -35,7 +30,6 @@ class CreateGamifyTables extends Migration
3530
$table->timestamps();
3631
});
3732

38-
// user_badges pivot
3933
Schema::create('user_badges', function (Blueprint $table) {
4034
$table->primary(['user_id', 'badge_id']);
4135
$table->unsignedInteger('user_id');
@@ -44,12 +38,7 @@ class CreateGamifyTables extends Migration
4438
});
4539
}
4640

47-
/**
48-
* Reverse the migrations.
49-
*
50-
* @return void
51-
*/
52-
public function down()
41+
public function down(): void
5342
{
5443
Schema::dropIfExists('user_badges');
5544
Schema::dropIfExists('badges');

phpunit.xml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
backupGlobals="false"
44
bootstrap="vendor/autoload.php"
55
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
96
processIsolation="false"
107
stopOnFailure="false"
8+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
9+
cacheDirectory=".phpunit.cache"
10+
backupStaticProperties="false"
1111
>
12-
<testsuites>
13-
<testsuite name="Package Test Suite">
14-
<directory suffix=".php">./tests/</directory>
15-
</testsuite>
16-
</testsuites>
17-
18-
<php>
19-
<env name="APP_KEY" value="AckfSECs434SFXIvnK5r28GVIWUAxmbBSjTsmF"/>
20-
</php>
12+
<testsuites>
13+
<testsuite name="Feature">
14+
<directory suffix="Test.php">./tests/Feature</directory>
15+
</testsuite>
16+
</testsuites>
17+
<php>
18+
<env name="APP_KEY" value="AckfSECs434SFXIvnK5r28GVIWUAxmbBSjTsmF"/>
19+
</php>
2120
</phpunit>

pint.json

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"preset": "psr12",
3+
"exclude": [
4+
"src"
5+
],
6+
"notPath": [
7+
".phpunit.result.cache"
8+
],
9+
"rules": {
10+
"align_multiline_comment": true,
11+
"array_indentation": true,
12+
"array_syntax": true,
13+
"assign_null_coalescing_to_coalesce_equal": true,
14+
"binary_operator_spaces": true,
15+
"blank_line_before_statement": {
16+
"statements": [
17+
"break",
18+
"continue",
19+
"declare",
20+
"return",
21+
"throw",
22+
"try"
23+
]
24+
},
25+
"cast_spaces": true,
26+
"class_attributes_separation": {
27+
"elements": {
28+
"method": "one"
29+
}
30+
},
31+
"clean_namespace": true,
32+
"combine_consecutive_issets": true,
33+
"combine_consecutive_unsets": true,
34+
"declare_strict_types": true,
35+
"doctrine_annotation_indentation": true,
36+
"doctrine_annotation_spaces": true,
37+
"fully_qualified_strict_types": true,
38+
"function_typehint_space": true,
39+
"global_namespace_import": true,
40+
"heredoc_indentation": true,
41+
"include": true,
42+
"lambda_not_used_import": true,
43+
"linebreak_after_opening_tag": true,
44+
"list_syntax": true,
45+
"magic_constant_casing": true,
46+
"magic_method_casing": true,
47+
"method_argument_space": {
48+
"on_multiline": "ensure_fully_multiline",
49+
"keep_multiple_spaces_after_comma": true
50+
},
51+
"method_chaining_indentation": true,
52+
"multiline_comment_opening_closing": true,
53+
"multiline_whitespace_before_semicolons": true,
54+
"native_function_casing": true,
55+
"native_function_type_declaration_casing": true,
56+
"no_alias_language_construct_call": true,
57+
"no_alternative_syntax": true,
58+
"no_empty_comment": true,
59+
"no_empty_statement": true,
60+
"no_extra_blank_lines": true,
61+
"no_leading_namespace_whitespace": true,
62+
"no_mixed_echo_print": true,
63+
"no_multiline_whitespace_around_double_arrow": true,
64+
"no_multiple_statements_per_line": true,
65+
"no_singleline_whitespace_before_semicolons": true,
66+
"no_spaces_around_offset": true,
67+
"no_unneeded_import_alias": true,
68+
"no_unused_imports": true,
69+
"no_whitespace_before_comma_in_array": true,
70+
"no_whitespace_in_blank_line": true,
71+
"not_operator_with_space": true,
72+
"not_operator_with_successor_space": true,
73+
"php_unit_fqcn_annotation": true,
74+
"phpdoc_line_span": {
75+
"const": "single",
76+
"method": "single",
77+
"property": "single"
78+
},
79+
"phpdoc_scalar": true,
80+
"phpdoc_single_line_var_spacing": true,
81+
"phpdoc_var_without_name": true,
82+
"simple_to_complex_string_variable": true,
83+
"simplified_if_return": true,
84+
"single_quote": true,
85+
"standardize_not_equals": true,
86+
"trailing_comma_in_multiline": true,
87+
"trim_array_spaces": true,
88+
"types_spaces": true,
89+
"unary_operator_spaces": true,
90+
"whitespace_after_comma_in_array": true
91+
}
92+
}

0 commit comments

Comments
 (0)