Skip to content

Commit 1d5ef93

Browse files
committed
v2
1 parent ba19361 commit 1d5ef93

15 files changed

+523
-215
lines changed

Diff for: .github/workflows/run-tests.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ jobs:
2323
fail-fast: true
2424
matrix:
2525
os: [ubuntu-latest]
26-
php: [8.1]
27-
laravel: [9.*]
26+
php: [8.3, 8.2, 8.1]
27+
laravel: [9.*,10.*,11.*]
2828
stability: [prefer-lowest, prefer-stable]
2929
include:
3030
- laravel: 9.*
3131
testbench: 7.*
32+
- laravel: 10.*
33+
testbench: 8.*
34+
- laravel: 11.*
35+
testbench: 8.*
3236

3337
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
3438

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ phpunit.xml
88
phpstan.neon
99
testbench.yaml
1010
vendor
11+
.env.testing
1112
node_modules

Diff for: .phpactor.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "/Applications/Tinkerwell.app/Contents/Resources/phpactor/phpactor.schema.json",
3+
"language_server_phpstan.enabled": false
4+
}

Diff for: .phpunit.cache/test-results

+1
Large diffs are not rendered by default.

Diff for: README.md

+84-29
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
# Laravel Enum Collections
33

44
[![Latest Version on Packagist](https://img.shields.io/packagist/v/datomatic/laravel-enum-collections.svg?style=for-the-badge)](https://packagist.org/packages/datomatic/laravel-enum-collections)
5-
[![Pest Tests number](https://img.shields.io/static/v1?label=%23tests&message=44&color=FF88FA&style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAMAAABF0y+mAAABiVBMVEUAAAD/iPv9yP3Xm+j/mP//wfVj67Je6bP/h/pVx6p6175d57WQycf+iPn/iPrsnezArd3+t/qpvNJd6LP/jPpu6rv/lPr/kPpc57T/rvtc57Np6rj3oPl37cL/tfn/wv9d6brX//L/g/rYn+n/gvrWm+di6LX+jPrskfGWzMpt6bln4bdd57Jk6LWSycj+vPquwNVo6rde6bP7nvvYnup91b/+vfv/lvtc57OqvNTFs9//t/td57L9t/r/iPpd6LPapej/ovp26bxy67v9lfld6LJr4Ljwsvb/xv3/jv39zv1t6buG5cTDreH5ivlc5rJy676V4cxb57D/y/h50MOy4OCUxcVa77X/iPpe6LP/jP+pu9L8t///tvuQycfArNxp6LzArd151r7/i/9n4bb/j/9e6rT/ifr7ifrskvLYnuhi87tg8blg7bf/vv//lP+wxNtj9b3/qv//oP/+ivz/l/r8ifryn/fvlPTfpPDeofDKtujHtOWX1NF/4seC3cR82sFu7cBo5LiMwPMrAAAAWHRSTlMA/Wv8FAIC/dME/Wj+3tEG/Pv798G1oHRjS0k1LBsWDgsJ/v36+fTy8ezn4+Lh29XNzMzLysLAwLSwr66opJqakY+Ni4J7end0bGlpY11XU048KicmIR8fizl+vwAAAVdJREFUKM9tz2VXAlEQgOFBBURpkE67u7u7E1YFYQl1SbvrlztDiLvss+fc/fCemXMvAEhhKqU759P1rLoxUDUyEh9fPH0z7ALiVrEY+SSNtxNS2upouYv7hOL191aKVsZHUTgbnQPQgDkq4ctHdoQmTWmW4WFzlVUDVpNKXf2fWpWbZIwUq/hcmjWGYnSa1pZZjEoomrEdVAisD7CX6GEb40rqTODxCj21OjDOvjRV8l2jhudBDchg/FUbDIZCITzwQyH6a9+2AMDbm9GfltFnxgAdtQWUgQJl4VQq37uPcSnsfYZzav6Ew18fQ4fUYPM7Qn4uSiIdyx5saJ6T+/3+5KSltshicwI2UpfAKE/aoARTvnn7KMYMdlAUyWRSyHN2JeU42HlCi4TszTHcmuj3iMVdP5JzoyAWNzi6T3ZGrMFCliK3BAqRSC/B2+6IxvYYNcO+2Npfv+yFi10LfBUAAAAASUVORK5CYII=)](https://github.com/datomatic/laravel-enum-collections/tree/main/tests)
6-
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/datomatic/laravel-enum-collections/run-tests.yml?branch=main&label=tests&color=5FE8B3&style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAMAAABF0y+mAAABiVBMVEUAAAD/iPv9yP3Xm+j/mP//wfVj67Je6bP/h/pVx6p6175d57WQycf+iPn/iPrsnezArd3+t/qpvNJd6LP/jPpu6rv/lPr/kPpc57T/rvtc57Np6rj3oPl37cL/tfn/wv9d6brX//L/g/rYn+n/gvrWm+di6LX+jPrskfGWzMpt6bln4bdd57Jk6LWSycj+vPquwNVo6rde6bP7nvvYnup91b/+vfv/lvtc57OqvNTFs9//t/td57L9t/r/iPpd6LPapej/ovp26bxy67v9lfld6LJr4Ljwsvb/xv3/jv39zv1t6buG5cTDreH5ivlc5rJy676V4cxb57D/y/h50MOy4OCUxcVa77X/iPpe6LP/jP+pu9L8t///tvuQycfArNxp6LzArd151r7/i/9n4bb/j/9e6rT/ifr7ifrskvLYnuhi87tg8blg7bf/vv//lP+wxNtj9b3/qv//oP/+ivz/l/r8ifryn/fvlPTfpPDeofDKtujHtOWX1NF/4seC3cR82sFu7cBo5LiMwPMrAAAAWHRSTlMA/Wv8FAIC/dME/Wj+3tEG/Pv798G1oHRjS0k1LBsWDgsJ/v36+fTy8ezn4+Lh29XNzMzLysLAwLSwr66opJqakY+Ni4J7end0bGlpY11XU048KicmIR8fizl+vwAAAVdJREFUKM9tz2VXAlEQgOFBBURpkE67u7u7E1YFYQl1SbvrlztDiLvss+fc/fCemXMvAEhhKqU759P1rLoxUDUyEh9fPH0z7ALiVrEY+SSNtxNS2upouYv7hOL191aKVsZHUTgbnQPQgDkq4ctHdoQmTWmW4WFzlVUDVpNKXf2fWpWbZIwUq/hcmjWGYnSa1pZZjEoomrEdVAisD7CX6GEb40rqTODxCj21OjDOvjRV8l2jhudBDchg/FUbDIZCITzwQyH6a9+2AMDbm9GfltFnxgAdtQWUgQJl4VQq37uPcSnsfYZzav6Ew18fQ4fUYPM7Qn4uSiIdyx5saJ6T+/3+5KSltshicwI2UpfAKE/aoARTvnn7KMYMdlAUyWRSyHN2JeU42HlCi4TszTHcmuj3iMVdP5JzoyAWNzi6T3ZGrMFCliK3BAqRSC/B2+6IxvYYNcO+2Npfv+yFi10LfBUAAAAASUVORK5CYII=)](https://github.com/datomatic/laravel-enum-collections/actions/workflows/run-tests.yml)
7-
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/datomatic/laravel-enum-collections/phpstan.yml?label=code%20style&color=5FE8B3&style=for-the-badge)](https://github.com/datomatic/laravel-enum-collections/actions/workflows/fix-php-code-style-issues.yml)
5+
[![Pest Tests number](https://img.shields.io/static/v1?label=%23tests&message=112&color=D1529F&style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAZCAMAAAAVHr4VAAACylBMVEUAAABGv+ZGwOZHv+ZQwOhHwOdfrt2WistGvuZoqNpsptp5ndSCmNLkV69yoteehchVtuJ4ndVGv+dpqNmAmdCjgMRjq9xupdhNuuSlgMVvo9dLvORpp9l9m9Ncsd+Dl9GNkM5Gv+ZGwOe5c75kq9x5ndWIlM+ehci0d8FHv+dGv+dGveRFv+eSjcq2csDFa7rJabpVtuE8tPFXtOFWtOBbsd6Lkc7uUayCl9HVYLRjq9uGldCNkM6UjMybh8migsaqfcOxeMG4dL6/b7zGarrOZrf3SqlirNz0TKnbXLJNu+RtpdlzodaYicqfhMamgMSte8K0dr+8cb3DbbtGv+VlqtulgsXKaLhUt+FVtOBlq9xHwOeAmdH9R6d6nNSsfMJgrt5csN5Gv+ZGwOfYX7OIk87/RaVGvubhWrFas+BvpNiTjMyof8NSuOJKvOVkq9tUt+JxoddLuuSQjsxZs+G9cr1Hv+ZTteBXteFFv+Ztp9hHvuTpUq1IveSWh8lQt+NcsODyT6t0oddIvOOhgMhvotVGueX1R6N6m9Oqd7tGv+ZGv+dMzvlIveVN0v1Ixe2IlNCPj81KyfJPuuRYs+Bird1N0fxHwupUt+NRuO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oPBKZN65mepAOWYyi+bjF/rvishJKCImYoqGyG+Tj1qiDQmRsqsAZHzBa+OWJXZtQDjcEAHYI3OafOvujVhk2y6RonMILWRmM1tWojKPImJWPTyJB/RgAYeZM0GYywSCauk+jq6l5TjVUy4jwweqaz6mAzFgCjl8baxN3bSgAAAABJRU5ErkJggg==)](https://github.com/datomatic/laravel-enum-collections/tree/main/tests)
6+
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/datomatic/laravel-enum-collections/run-tests.yml?branch=main&label=tests&color=7DDFA8&style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAZCAMAAAAVHr4VAAACylBMVEUAAABGv+ZGwOZHv+ZQwOhHwOdfrt2WistGvuZoqNpsptp5ndSCmNLkV69yoteehchVtuJ4ndVGv+dpqNmAmdCjgMRjq9xupdhNuuSlgMVvo9dLvORpp9l9m9Ncsd+Dl9GNkM5Gv+ZGwOe5c75kq9x5ndWIlM+ehci0d8FHv+dGv+dGveRFv+eSjcq2csDFa7rJabpVtuE8tPFXtOFWtOBbsd6Lkc7uUayCl9HVYLRjq9uGldCNkM6UjMybh8migsaqfcOxeMG4dL6/b7zGarrOZrf3SqlirNz0TKnbXLJNu+RtpdlzodaYicqfhMamgMSte8K0dr+8cb3DbbtGv+VlqtulgsXKaLhUt+FVtOBlq9xHwOeAmdH9R6d6nNSsfMJgrt5csN5Gv+ZGwOfYX7OIk87/RaVGvubhWrFas+BvpNiTjMyof8NSuOJKvOVkq9tUt+JxoddLuuSQjsxZs+G9cr1Hv+ZTteBXteFFv+Ztp9hHvuTpUq1IveSWh8lQt+NcsODyT6t0oddIvOOhgMhvotVGueX1R6N6m9Oqd7tGv+ZGv+dMzvlIveVN0v1Ixe2IlNCPj81KyfJPuuRYs+Bird1N0fxHwupUt+NRuOJqsOJcsd9qp9p0odd3n9V9m9OAmdKLks+vhM2TjcyYicq8cb3DbLvSYrbXX7TeWrJSzvtpxPdIxu9NxO9YwO1GwOh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RmM1tWojKPImJWPTyJB/RgAYeZM0GYywSCauk+jq6l5TjVUy4jwweqaz6mAzFgCjl8baxN3bSgAAAABJRU5ErkJggg==)](https://github.com/datomatic/laravel-enum-collections/actions/workflows/run-tests.yml)
7+
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/datomatic/laravel-enum-collections/phpstan.yml?label=code%20style&color=7DDFA8&style=for-the-badge)](https://github.com/datomatic/laravel-enum-collections/actions/workflows/fix-php-code-style-issues.yml)
88
[![Total Downloads](https://img.shields.io/packagist/dt/datomatic/laravel-enum-collections.svg?style=for-the-badge)](https://packagist.org/packages/datomatic/laravel-enum-collections)
99

10-
Save a collection of Enums in an Eloquent field and interact with it.
10+
A Laravel Collection extension to store enums with a useful eloquent fields cast.
11+
Take your interaction with enums to the next level.
1112
Compatible with `PureEnum`, `BackedEnum` and [`datomatic/laravel-enum-helper`](https://github.com/datomatic/laravel-enum-helper) package.
1213

1314
## Installation
@@ -18,9 +19,69 @@ You can install the package via composer:
1819
composer require datomatic/laravel-enum-collections
1920
```
2021

21-
## Set up
22+
## EnumCollection
2223

23-
Before you can use this package you must setup the eloquent Model.
24+
`EnumCollection` is an extension of base [Laravel collection](https://laravel.com/docs/collections) that expand his functionalities and overload the `contains` method to add the compatibility with:
25+
- enum object instance
26+
- enum case name string
27+
- enum case value (only for `BackedEnum`)
28+
- enum case (string) value (only for `IntBackedEnum`)
29+
30+
### Creating an EnumCollection
31+
32+
You can set enum collection field passing in 4 ways:
33+
```php
34+
use \Datomatic\EnumCollections\EnumCollection;
35+
36+
EnumCollection::of(Enum::class)->from($data);
37+
EnumCollection::of(Enum::class)->tryFrom($data);
38+
EnumCollection::from($data, Enum::class);
39+
EnumCollection::tryFrom($data, Enum::class);
40+
```
41+
`from` method throw an `ValueError` Exception if an element in `$data` is wrong, instead `tryFrom` skips bad data without raise exceptions.
42+
`$data` can be a single element or a `collection`, `array`,... of elements.
43+
44+
If `$data` contains only Enum elements you can also omit the `EnumClass` (the collection take the EnumClass of the first element).
45+
```php
46+
EnumCollection::from(Enum::CASE1); // ✅ EnumCollection<Enum::CASE1>
47+
EnumCollection::from('CASE1', Enum::class); // ✅ EnumCollection<Enum::CASE1>
48+
EnumCollection::from(1, Enum::class); // ✅ EnumCollection<Enum::CASE1>
49+
EnumCollection::from('1', Enum::class); // ✅ EnumCollection<Enum::CASE1>
50+
EnumCollection::from([Enum::CASE1,Enum::CASE2]); // ✅ EnumCollection<Enum>
51+
EnumCollection::from(collect([Enum::CASE1,Enum::CASE2])); // ✅ EnumCollection<Enum>
52+
```
53+
54+
### `Contains' method
55+
56+
```php
57+
use \Datomatic\EnumCollections\EnumCollection;
58+
59+
$enumCollection = EnumCollection::from([Enum::CASE1,Enum::CASE2]); // [1,2]
60+
61+
$enumCollection->contains(Enum::CASE1); // true
62+
$enumCollection->contains(Enum::CASE3); // false
63+
$enumCollection->doesntContain(Enum::CASE3); // true
64+
$enumCollection->contains(1); // true
65+
$enumCollection->contains('1'); // true
66+
$enumCollection->contains('PRIVATE'); // true
67+
$enumCollection->doesntContain('PRIVATE'); // false
68+
```
69+
70+
### `toValues' method
71+
`toValues` method serialize the collection content, if the element is a `PureEnum` will be pass the `name` of the case, otherwise the `value`.
72+
73+
```php
74+
use \Datomatic\EnumCollections\EnumCollection;
75+
76+
EnumCollection::from([Enum::CASE1,Enum::CASE2,Enum::CASE2])->toValues(); // [1,2,2]
77+
EnumCollection::from(['CASE1','CASE2','CASE2'],Enum::class)->toValues(); // [1,2,2]
78+
EnumCollection::from([1,2,2],Enum::class)->toValues(); // [1,2,2]
79+
EnumCollection::from(['1','2','2'],Enum::class)->toValues(); // [1,2,2]
80+
```
81+
82+
## Casting
83+
84+
Before you can use this casting option you must config the eloquent Model.
2485

2586
### 1. Database Migration
2687
```php
@@ -32,48 +93,41 @@ Schema::table('table', function (Blueprint $table) {
3293
### 2. Model set up
3394

3495
To set up your model you must:
35-
- add a custom cast `EnumCollections::class`
36-
- add an `$enumCollections` array containing the fields and relative enum classes
96+
- add a custom cast `AsEnumCollections::class` with the enumClass as attribute
3797
- add an optional `HasEnumCollections` trait to make query on enum collections fields
3898

3999
You can also set more than one field if you need.
40100

41101
```php
42102

43-
use Datomatic\EnumCollections\Casts\EnumCollections;
103+
use Datomatic\EnumCollections\Casts\AsEnumCollection;
44104
use Datomatic\EnumCollections\EnumCollection;
45105
use Illuminate\Database\Eloquent\Model;
46106

47107
class TestModel extends Model
48108
{
49109
use HasEnumCollections;
50110

111+
//Laravel 9/10
51112
protected $casts = [
52-
'field_name' => EnumCollections::class,
113+
'field_name' => AsEnumCollection::class.':'.FieldEnum::class,
53114
];
54115

55-
public array $enumCollections = [
56-
'field_name' => FieldEnum::class,
57-
];
116+
//Laravel 11
117+
protected function casts(): array
118+
{
119+
return [
120+
'field_name' => AsEnumCollection::of(FieldEnum::class),
121+
];
122+
}
58123
}
59124
```
60125

61-
## Usage
62-
63-
After model set up you can use the package potentials.
64-
65-
66126
### Set the enum collection field
67127

68128
You can set enum collection field passing a single element, a collection or an array of elements.
69129
After the setting, the field will become an `EnumCollection`.
70130

71-
Each element can be an:
72-
- enum object instance
73-
- enum case name string
74-
- enum case value (only for `BackedEnum`)
75-
- enum case (string) value (only for `IntBackedEnum`)
76-
77131
```php
78132
enum FieldEnum: int
79133
{
@@ -91,12 +145,11 @@ $model->field_name = [FieldEnum::PRIVATE,FieldEnum::PUBLIC]; // ✅ EnumCollecti
91145
$model->field_name = collect([FieldEnum::PRIVATE,FieldEnum::PUBLIC]); // ✅ EnumCollection<FieldEnum>
92146
```
93147

148+
### Database saved data
149+
A serialization of enumCollection is saved in the database, if the element is a `PureEnum` will be saved the `name` of the case, otherwise the `value`.
150+
94151
### EnumCollection
95-
The `EnumCollection` extend the [Laravel collection](https://laravel.com/docs/collections) and overload the `contains` method to add the compatibility with:
96-
- enum object instance
97-
- enum case name string
98-
- enum case value (only for `BackedEnum`)
99-
- enum case (string) value (only for `IntBackedEnum`)
152+
Thanks to casting you can interact with `field_name` like a normal `EnumCollection` with all functionalities showed before.
100153

101154
```php
102155

@@ -108,6 +161,8 @@ $model->field_name->contains(FieldEnum::PROTECTED); // false
108161
$model->field_name->contains(1); // true
109162
$model->field_name->contains('1'); // true
110163
$model->field_name->contains('PRIVATE'); // true
164+
$model->field_name->doesntContain('PRIVATE'); // false
165+
$model->field_name->doesntContain(FieldEnum::PROTECTED); // true
111166
```
112167

113168
### HasEnumCollections trait

Diff for: UPGRADE.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Upgrading
2+
3+
## From v1 to v2
4+
5+
Simply update the Models casts definition from
6+
7+
```php
8+
protected $casts = [
9+
'field_name' => EnumCollections::class,
10+
];
11+
12+
public array $enumCollections = [
13+
'field_name' => FieldEnum::class,
14+
];
15+
```
16+
to
17+
```php
18+
//Laravel 9/10
19+
protected $casts = [
20+
'field_name' => AsEnumCollection::class.':'.FieldEnum::class,
21+
];
22+
23+
//Laravel 11
24+
protected function casts(): array
25+
{
26+
return [
27+
'field_name' => AsEnumCollection::of(FieldEnum::class),
28+
];
29+
}
30+
```

Diff for: composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
"require": {
1919
"php": "^8.1",
2020
"spatie/laravel-package-tools": "^1.13.0",
21-
"illuminate/contracts": "^9.0|^10.0"
21+
"illuminate/contracts": "^9.0|^10.0|^11.0"
2222
},
2323
"require-dev": {
2424
"laravel/pint": "^1.0",
25-
"nunomaduro/collision": "^6.0",
25+
"nunomaduro/collision": "^7.0",
2626
"nunomaduro/larastan": "^2.0.1",
27-
"orchestra/testbench": "^7.0",
28-
"pestphp/pest": "^1.21",
29-
"pestphp/pest-plugin-laravel": "^1.1",
27+
"orchestra/testbench": "^8.0",
28+
"pestphp/pest": "^2.0",
29+
"pestphp/pest-plugin-laravel": "^2.1",
3030
"phpstan/extension-installer": "^1.1",
3131
"phpstan/phpstan-deprecation-rules": "^1.0",
3232
"phpstan/phpstan-phpunit": "^1.0",
33-
"phpunit/phpunit": "^9.5"
33+
"phpunit/phpunit": "^10.0"
3434
},
3535
"autoload": {
3636
"psr-4": {

Diff for: phpunit.xml.dist

+30-45
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,32 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5-
backupGlobals="false"
6-
backupStaticAttributes="false"
7-
bootstrap="vendor/autoload.php"
8-
colors="true"
9-
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
12-
processIsolation="false"
13-
stopOnFailure="true"
14-
executionOrder="random"
15-
failOnWarning="true"
16-
failOnRisky="true"
17-
failOnEmptyTestSuite="true"
18-
beStrictAboutOutputDuringTests="true"
19-
verbose="true"
20-
>
21-
<testsuites>
22-
<testsuite name="Datomatic Test Suite">
23-
<directory>tests</directory>
24-
</testsuite>
25-
</testsuites>
26-
<coverage>
27-
<include>
28-
<directory suffix=".php">./src</directory>
29-
</include>
30-
<report>
31-
<html outputDirectory="build/coverage"/>
32-
<text outputFile="build/coverage.txt"/>
33-
<clover outputFile="build/logs/clover.xml"/>
34-
</report>
35-
</coverage>
36-
<logging>
37-
<junit outputFile="build/report.junit.xml"/>
38-
</logging>
39-
<php>
40-
<env name="DB_CONNECTION" value="mysql"/>
41-
<env name="DB_DATABASE" value="laravel_enum_collection"/>
42-
<env name="DB_USERNAME" value="root"/>
43-
<env name="DB_PASSWORD" value="password"/>
44-
<env name="DB_HOST" value="127.0.0.1" />
45-
<env name="DB_PORT" value="3306" />
46-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="true" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="Datomatic Test Suite">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<coverage>
9+
<report>
10+
<html outputDirectory="build/coverage"/>
11+
<text outputFile="build/coverage.txt"/>
12+
<clover outputFile="build/logs/clover.xml"/>
13+
</report>
14+
</coverage>
15+
<logging>
16+
<junit outputFile="build/report.junit.xml"/>
17+
</logging>
18+
<php>
19+
<server name="APP_ENV" value="testing"/>
20+
<env name="DB_CONNECTION" value="mysql"/>
21+
<env name="DB_DATABASE" value="test"/>
22+
<env name="DB_USERNAME" value="root"/>
23+
<env name="DB_PASSWORD" value=""/>
24+
<env name="DB_HOST" value="127.0.0.1"/>
25+
<env name="DB_PORT" value="3306"/>
26+
</php>
27+
<source>
28+
<include>
29+
<directory suffix=".php">./src</directory>
30+
</include>
31+
</source>
4732
</phpunit>

0 commit comments

Comments
 (0)