Skip to content

Commit 34f7c1f

Browse files
authored
Merge pull request #7 from pixelpeter/laravel_11_compatibility
UPDATE: add Laravel 11 compatibility
2 parents fb93a0c + cd10f74 commit 34f7c1f

File tree

8 files changed

+161
-191
lines changed

8 files changed

+161
-191
lines changed

.github/workflows/run-tests.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ ubuntu-latest ]
16-
php: [ 8.2, 8.1, 8.0 ]
17-
laravel: [ 9.*, 8.* ]
16+
php: [ 8.3, 8.2, 8.1 ]
17+
laravel: [ 10.*, 11.* ]
1818
stability: [ prefer-stable ]
1919
include:
20-
- laravel: 9.*
21-
testbench: 7.*
22-
carbon: 2.*
23-
- laravel: 8.*
24-
testbench: 6.*
20+
- laravel: 11.*
21+
testbench: 9.*
22+
carbon: 3.*
23+
- laravel: 10.*
24+
testbench: 8.*
2525
carbon: 2.*
26+
exclude:
27+
- laravel: 11.*
28+
php: 8.1
2629
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2730
steps:
2831
- name: Checkout code

composer.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
}
1919
],
2020
"require": {
21-
"php": "^8.0|^8.1|^8.2",
22-
"laravel/laravel": "^8.0|^9.0",
21+
"php": "^8.1|^8.2|^8.3",
22+
"laravel/laravel": "^10.0|^11.0",
2323
"ronanguilloux/isocodes": "^2.3.5"
2424
},
2525
"autoload": {
@@ -29,14 +29,11 @@
2929
},
3030
"autoload-dev": {
3131
"psr-4": {
32-
"Pixelpeter\\IsoCodesValidation\\Test\\": "tests"
33-
},
34-
"classmap": [
35-
"tests/TestCase.php"
36-
]
32+
"Pixelpeter\\IsoCodesValidation\\Tests\\": "tests"
33+
}
3734
},
3835
"require-dev": {
39-
"phpunit/phpunit": "^9.5",
36+
"phpunit/phpunit": "^10.5|^11.0",
4037
"mockery/mockery": "^1.2",
4138
"php-coveralls/php-coveralls": "^2.7",
4239
"phpstan/extension-installer": "^1.4"

phpunit.xml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage>
4-
<include>
5-
<directory suffix=".php">src/</directory>
6-
</include>
7-
<exclude>
8-
<file>./src/WoocommerceServiceProvider.php</file>
9-
<file>./src/Facades/Woocommerce.php</file>
10-
</exclude>
11-
</coverage>
12-
<testsuites>
13-
<testsuite name="Package Test Suite">
14-
<directory suffix=".php">./tests/</directory>
15-
</testsuite>
16-
</testsuites>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true"
3+
processIsolation="false" stopOnFailure="true"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache"
5+
backupStaticProperties="false">
6+
<testsuites>
7+
<testsuite name="Unit">
8+
<directory suffix=".php">./tests/Unit</directory>
9+
</testsuite>
10+
</testsuites>
11+
<source>
12+
<include>
13+
<directory suffix=".php">src/</directory>
14+
</include>
15+
</source>
1716
</phpunit>

tests/IsoCodesValidatorTest.php

Lines changed: 0 additions & 157 deletions
This file was deleted.

tests/TestCase.php

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

3-
namespace Pixelpeter\IsoCodesValidation;
3+
namespace Pixelpeter\IsoCodesValidation\Tests;
44

5-
abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
5+
use Illuminate\Foundation\Console\Kernel;
6+
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
7+
use Pixelpeter\IsoCodesValidation\IsoCodesValidationServiceProvider;
8+
9+
abstract class TestCase extends BaseTestCase
610
{
711
/**
812
* The base URL to use while testing the application.
@@ -20,9 +24,9 @@ public function createApplication()
2024
{
2125
$app = require __DIR__.'/../vendor/laravel/laravel/bootstrap/app.php';
2226

23-
$app->register(\Pixelpeter\IsoCodesValidation\IsoCodesValidationServiceProvider::class);
27+
$app->register(IsoCodesValidationServiceProvider::class);
2428

25-
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
29+
$app->make(Kernel::class)->bootstrap();
2630

2731
return $app;
2832
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
namespace Pixelpeter\IsoCodesValidation\Tests\Unit;
4+
5+
use Illuminate\Support\Facades\Validator;
6+
use PHPUnit\Framework\Attributes\DataProvider;
7+
use Pixelpeter\IsoCodesValidation\Tests\TestCase;
8+
9+
class IsoCodesValidatorTest extends TestCase
10+
{
11+
/**
12+
* DataProvider for failing tests
13+
*
14+
* @return array
15+
*/
16+
public static function invalidDataProvider()
17+
{
18+
return include_once __DIR__.'/../fixtures/invalid.php';
19+
}
20+
21+
/**
22+
* DataProvider for simple rules
23+
*
24+
* @return array
25+
*/
26+
public static function validDataProvider()
27+
{
28+
return include_once __DIR__.'/../fixtures/valid.php';
29+
}
30+
31+
/**
32+
* DataProvider for rules with references
33+
*
34+
* @return array
35+
*/
36+
public static function validDataWithReferencesProvider()
37+
{
38+
return include_once __DIR__.'/../fixtures/valid_with_references.php';
39+
}
40+
41+
/**
42+
* DataProvider for arrays with dot notation
43+
*
44+
* @return array
45+
*/
46+
public static function validDataWithDotNotationProvider()
47+
{
48+
return include_once __DIR__.'/../fixtures/valid_with_dot_notation.php';
49+
}
50+
51+
/**
52+
* DataProvider for arrays with dot notation
53+
*
54+
* @return array
55+
*/
56+
public static function invalidDataWithDotNotationProvider()
57+
{
58+
return include_once __DIR__.'/../fixtures/invalid_with_dot_notation.php';
59+
}
60+
61+
#[DataProvider('invalidDataProvider')]
62+
public function test_validator_returns_correct_error_message($payload, $rules, $message)
63+
{
64+
$validator = Validator::make($payload, $rules);
65+
66+
$this->assertEquals($message, $validator->errors()->first());
67+
}
68+
69+
#[DataProvider('validDataProvider')]
70+
public function test_it_validates_correctly($field, $value)
71+
{
72+
$validator = Validator::make([$field => $value], [$field => $field]);
73+
74+
$this->assertTrue($validator->passes());
75+
}
76+
77+
#[DataProvider('validDataWithReferencesProvider')]
78+
public function test_it_validates_correctly_with_references(
79+
$field,
80+
$value,
81+
$referenceField = '',
82+
$referenceValue = ''
83+
) {
84+
$payload = [
85+
$field => $value,
86+
$referenceField => $referenceValue,
87+
];
88+
89+
$rules = [
90+
$field => "{$field}:{$referenceField}",
91+
];
92+
93+
$validator = Validator::make($payload, $rules);
94+
95+
$this->assertTrue($validator->passes());
96+
}
97+
98+
#[DataProvider('validDataWithDotNotationProvider')]
99+
public function test_it_validates_correctly_with_dot_notation($data, $rule)
100+
{
101+
$payload = [
102+
'data' => $data,
103+
];
104+
105+
$validator = Validator::make($payload, $rule);
106+
107+
$this->assertTrue($validator->passes());
108+
$this->assertEmpty($validator->errors()->all());
109+
}
110+
111+
#[DataProvider('invalidDataWithDotNotationProvider')]
112+
public function test_validator_returns_correct_error_message_with_dot_notation($data, $rule, $errors)
113+
{
114+
$payload = [
115+
'data' => $data,
116+
];
117+
118+
$validator = Validator::make($payload, $rule);
119+
120+
$this->assertTrue($validator->fails());
121+
$this->assertCount(2, $validator->errors()->all());
122+
$this->assertEquals($errors[0], $validator->errors()->first());
123+
}
124+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)