Skip to content

Commit 1b72c47

Browse files
author
Kevin Buchholz
committed
Merge branch 'release/3.1.1'
2 parents 9830f90 + b85726d commit 1b72c47

36 files changed

+290
-146
lines changed

.gitattributes

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
# Path-based git attributes
3+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
4+
5+
# Ignore all test and configuration with "export-ignore".
6+
/.github export-ignore
7+
/tests export-ignore
8+
/.editorconfig export-ignore
9+
/.gitattributes export-ignore
10+
/.gitignore export-ignore
11+
/phpcs.xml export-ignore
12+
/phpmd.xml export-ignore
13+
/phpunit.xml export-ignore

.github/workflows/lint.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Lint PHP"
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
jobs:
9+
phpcs:
10+
name: PHPCS
11+
runs-on: ubuntu-20.04
12+
strategy:
13+
matrix:
14+
php-versions: ['7.4']
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Setup
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php-versions }}
23+
extensions: mbstring, curl, zip
24+
coverage: none
25+
tools: composer
26+
27+
- name: Install dependencies
28+
run: composer update --no-interaction --no-suggest --no-progress --optimize-autoloader
29+
30+
- name: Run
31+
run: composer run lint:phpcs

.github/workflows/test.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "Test PHP"
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
jobs:
9+
phpunit:
10+
name: PHPUnit
11+
runs-on: ubuntu-20.04
12+
strategy:
13+
matrix:
14+
php-versions: ['7.3', '7.4', '8.0']
15+
composer-arguments: ['--prefer-lowest', '']
16+
allowed-to-fail: [false]
17+
include:
18+
- php-versions: '8.1'
19+
composer-arguments: ''
20+
allowed-to-fail: false
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
26+
- name: Setup
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: ${{ matrix.php-versions }}
30+
extensions: mbstring, curl, zip
31+
coverage: xdebug
32+
tools: composer
33+
34+
- name: Install dependencies
35+
continue-on-error: ${{ matrix.allowed-to-fail }}
36+
run: composer update --no-interaction --no-suggest --no-progress --optimize-autoloader --quiet ${{ matrix.composer-arguments }}
37+
38+
- name: Run tests
39+
continue-on-error: ${{ matrix.allowed-to-fail }}
40+
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

.travis.yml

-25
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# laravel-enumeration
22

3-
[![Build Status](https://travis-ci.org/sourceboat/laravel-enumeration.svg?branch=master)](https://travis-ci.org/sourceboat/laravel-enumeration)
3+
[![Tests](https://github.com/sourceboat/laravel-enumeration/actions/workflows/test.yaml/badge.svg?branch=develop)](https://github.com/sourceboat/laravel-enumeration/actions/workflows/test.yaml)
44
[![Latest Version on Packagist](https://img.shields.io/packagist/v/sourceboat/laravel-enumeration.svg?style=flat-square)](https://packagist.org/packages/sourceboat/laravel-enumeration)
55
[![Packagist Stable Version](https://img.shields.io/packagist/v/sourceboat/laravel-enumeration.svg?style=flat-square&label=stable)](https://packagist.org/packages/sourceboat/laravel-enumeration)
66
[![Packagist downloads](https://img.shields.io/packagist/dt/sourceboat/laravel-enumeration.svg?style=flat-square)](https://packagist.org/packages/sourceboat/laravel-enumeration)

composer.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
],
2929
"require": {
3030
"php": ">=7.3",
31-
"illuminate/console": "^8.0",
32-
"illuminate/contracts": "^8.0",
33-
"illuminate/support": "^8.0"
31+
"illuminate/console": "^8.0|^9.0",
32+
"illuminate/contracts": "^8.0|^9.0",
33+
"illuminate/support": "^8.0|^9.0"
3434
},
3535
"require-dev": {
36-
"orchestra/testbench": "^6.0",
36+
"orchestra/testbench": "^6.0|^7.0",
3737
"phpmd/phpmd": "^2.6",
3838
"phpunit/phpunit": "9.*",
39-
"slevomat/coding-standard": "6.4.1",
39+
"slevomat/coding-standard": "7.1",
4040
"squizlabs/php_codesniffer": "^3.5"
4141
},
4242
"autoload": {
@@ -67,6 +67,9 @@
6767
}
6868
},
6969
"config": {
70-
"sort-packages": true
70+
"sort-packages": true,
71+
"allow-plugins": {
72+
"dealerdirect/phpcodesniffer-composer-installer": true
73+
}
7174
}
7275
}

phpcs.xml

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
<property name="linesCountBeforeClosingBrace" value="0"/>
114114
</properties>
115115
</rule>
116-
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements"/>
117116
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
118117
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
119118
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/>

phpunit.xml

+15-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false">
11-
<testsuites>
12-
<testsuite name="Unit">
13-
<directory suffix="Test.php">./tests</directory>
14-
</testsuite>
15-
</testsuites>
16-
<filter>
17-
<whitelist>
18-
<directory suffix=".php">src/</directory>
19-
</whitelist>
20-
</filter>
21-
<php>
22-
<env name="APP_ENV" value="testing"/>
23-
<env name="BCRYPT_ROUNDS" value="4"/>
24-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" 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+
</coverage>
8+
<testsuites>
9+
<testsuite name="Unit">
10+
<directory suffix="Test.php">./tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<php>
14+
<env name="APP_ENV" value="testing"/>
15+
<env name="BCRYPT_ROUNDS" value="4"/>
16+
</php>
2517
</phpunit>

tests/feature/ModelCastsEnumsTest.php renamed to tests/Feature/ModelCastsEnumsTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?php
22

3-
namespace Sourceboat\Enumeration\Tests;
3+
namespace Sourceboat\Enumeration\Tests\Feature;
44

55
use Sourceboat\Enumeration\Exceptions\UndefinedMemberException;
6+
use Sourceboat\Enumeration\Tests\FruitType;
7+
use Sourceboat\Enumeration\Tests\TestCase;
8+
use Sourceboat\Enumeration\Tests\TestModel;
9+
use Sourceboat\Enumeration\Tests\UserRole;
610

711
class ModelCastsEnumsTest extends TestCase
812
{

tests/unit/Configurable/ConfigTest.php renamed to tests/Unit/Configurable/ConfigTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3-
namespace Sourceboat\Enumeration\Tests;
3+
namespace Sourceboat\Enumeration\Tests\Unit\Configurable;
44

5-
use Orchestra\Testbench\TestCase;
5+
use Sourceboat\Enumeration\Tests\ConfigurableEnum;
6+
use Sourceboat\Enumeration\Tests\TestCase;
67

78
class ConfigTest extends TestCase
89
{
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Sourceboat\Enumeration\Tests\Unit;
4+
5+
use Sourceboat\Enumeration\Rules\EnumerationValue;
6+
use Sourceboat\Enumeration\Tests\FruitType;
7+
use Sourceboat\Enumeration\Tests\TestCase;
8+
use Sourceboat\Enumeration\Tests\UserRole;
9+
10+
class EnumerationValueMethodsTest extends TestCase
11+
{
12+
/**
13+
* @var array<\Sourceboat\Enumeration\Rules\EnumerationValue>
14+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
15+
*/
16+
private static $rules;
17+
18+
public static function setUpBeforeClass(): void
19+
{
20+
parent::setUpBeforeClass();
21+
22+
self::$rules = [
23+
'role' => new EnumerationValue(UserRole::class, UserRole::membersByBlacklist([UserRole::ADMIN()])),
24+
'fruit' => new EnumerationValue(FruitType::class),
25+
];
26+
}
27+
28+
/** @return array<array<mixed>> */
29+
public function passesDataprovider(): array
30+
{
31+
return [
32+
['role', UserRole::MODERATOR()->value(), true],
33+
['role', UserRole::ADMIN()->value(), false],
34+
['role', UserRole::SUPER_ADMIN()->value(), true],
35+
['role', UserRole::USER()->value(), true],
36+
['role', 'reporter', false],
37+
['role', 5, false],
38+
39+
['fruit', FruitType::BERRY()->value(), true],
40+
['fruit', FruitType::NUT()->value(), true],
41+
['fruit', FruitType::LEGUME()->value(), true],
42+
['fruit', FruitType::ACCESSORY_FRUIT()->value(), true],
43+
['fruit', 'test', false],
44+
['fruit', 5, false],
45+
];
46+
}
47+
48+
/**
49+
* @dataProvider passesDataProvider
50+
* @param string $ruleKey
51+
* @param string|int $value
52+
* @param bool $expectation
53+
* @return void
54+
*/
55+
public function testPasses(string $ruleKey, $value, bool $expectation): void
56+
{
57+
$this->assertEquals($expectation, self::$rules[$ruleKey]->passes(null, $value));
58+
}
59+
60+
public function testMessage(): void
61+
{
62+
$this->assertEquals('The given value is not suitable for :attribute.', self::$rules['role']->message());
63+
}
64+
65+
/** @return array<array<mixed>> */
66+
public function sensitivityDataProvider(): array
67+
{
68+
return [
69+
['moderator', false, true],
70+
['ModerATor', false, true],
71+
['moderator', true, true],
72+
['ModerATor', true, false],
73+
];
74+
}
75+
76+
/**
77+
* @dataProvider sensitivityDataProvider
78+
* @param string $value
79+
* @param bool $caseSensitivity
80+
* @param bool $expectation
81+
* @return void
82+
*/
83+
public function testSetCaseSensitivity(string $value, bool $caseSensitivity, bool $expectation): void
84+
{
85+
self::$rules['role']->setCaseSensitivity($caseSensitivity);
86+
$this->assertEquals($expectation, self::$rules['role']->passes(null, $value));
87+
}
88+
}

tests/unit/GetKeysTest.php renamed to tests/Unit/GetKeysTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22

3-
namespace Sourceboat\Enumeration\Tests;
3+
namespace Sourceboat\Enumeration\Tests\Unit;
4+
5+
use Sourceboat\Enumeration\Tests\FruitType;
6+
use Sourceboat\Enumeration\Tests\TestCase;
7+
use Sourceboat\Enumeration\Tests\UserRole;
48

59
class GetKeysTest extends TestCase
610
{

tests/unit/GetMembersByBlacklistTest.php renamed to tests/Unit/GetMembersByBlacklistTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3-
namespace Sourceboat\Enumeration\Tests;
3+
namespace Sourceboat\Enumeration\Tests\Unit;
4+
5+
use Sourceboat\Enumeration\Tests\TestCase;
6+
use Sourceboat\Enumeration\Tests\UserRole;
47

58
class GetMembersByBlacklistTest extends TestCase
69
{

tests/unit/GetRandomMemberTest.php renamed to tests/Unit/GetRandomMemberTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3-
namespace Sourceboat\Enumeration\Tests;
3+
namespace Sourceboat\Enumeration\Tests\Unit;
4+
5+
use Sourceboat\Enumeration\Tests\TestCase;
6+
use Sourceboat\Enumeration\Tests\UserRole;
47

58
class GetRandomMemberTest extends TestCase
69
{

tests/unit/GetRuleTest.php renamed to tests/Unit/GetRuleTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3-
namespace Sourceboat\Enumeration\Tests;
3+
namespace Sourceboat\Enumeration\Tests\Unit;
4+
5+
use Sourceboat\Enumeration\Tests\TestCase;
6+
use Sourceboat\Enumeration\Tests\UserRole;
47

58
class GetRuleTest extends TestCase
69
{

tests/unit/GetSelectArrayTest.php renamed to tests/Unit/GetSelectArrayTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22

3-
namespace Sourceboat\Enumeration\Tests;
3+
namespace Sourceboat\Enumeration\Tests\Unit;
4+
5+
use Sourceboat\Enumeration\Tests\FruitType;
6+
use Sourceboat\Enumeration\Tests\TestCase;
7+
use Sourceboat\Enumeration\Tests\UserRole;
48

59
class GetSelectArrayTest extends TestCase
610
{

tests/unit/GetValuesTest.php renamed to tests/Unit/GetValuesTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22

3-
namespace Sourceboat\Enumeration\Tests;
3+
namespace Sourceboat\Enumeration\Tests\Unit;
4+
5+
use Sourceboat\Enumeration\Tests\FruitType;
6+
use Sourceboat\Enumeration\Tests\TestCase;
7+
use Sourceboat\Enumeration\Tests\UserRole;
48

59
class GetValuesTest extends TestCase
610
{

tests/unit/IsEnumKeyTest.php renamed to tests/Unit/IsEnumKeyTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3-
namespace Sourceboat\Enumeration\Tests;
3+
namespace Sourceboat\Enumeration\Tests\Unit;
44

55
use Sourceboat\Enumeration\Exceptions\UndefinedMemberException;
6+
use Sourceboat\Enumeration\Tests\TestCase;
7+
use Sourceboat\Enumeration\Tests\UserRole;
68

79
class IsEnumKeyTest extends TestCase
810
{

0 commit comments

Comments
 (0)