Skip to content

Commit 535692e

Browse files
committed
Update PHPUnit and fix tests
1 parent f90670c commit 535692e

40 files changed

+209
-177
lines changed

.github/workflows/phpqa.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ jobs:
88
steps:
99
- uses: actions/checkout@master
1010
- name: PHPStan
11-
uses: docker://jakzal/phpqa:php8.1
11+
uses: docker://jakzal/phpqa:php8.4
1212
with:
1313
args: phpstan analyze src/ -l 1
1414
- name: PHP-CS-Fixer
15-
uses: docker://jakzal/phpqa:php8.1
15+
uses: docker://jakzal/phpqa:php8.4
1616
with:
1717
args: php-cs-fixer --dry-run --allow-risky=yes --no-interaction --ansi fix
1818
- name: Deptrac
19-
uses: docker://jakzal/phpqa:php8.1
19+
uses: docker://jakzal/phpqa:php8.4
2020
with:
2121
args: deptrac --no-interaction --ansi --formatter-graphviz-display=0

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tools:
3737
build:
3838
image: default-bionic
3939
environment:
40-
php: 8.1.0
40+
php: 8.4.0
4141
nodes:
4242
analysis:
4343
tests:

.styleci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
preset: psr2
33
risky: true
4-
version: 8.1
4+
version: 8.4
55
finder:
66
name:
77
- "*.php"

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: php
22

33
php:
4-
- 8.1
4+
- 8.4
55

66
script:
77
- composer install --dev

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
## PHP Rule Engine
22

3-
43
[![Latest Stable Version](https://travis-ci.org/nicoSWD/php-rule-parser.svg?branch=master)](https://travis-ci.org/nicoSWD/php-rule-parser)
54
[![Build status][Master coverage image]][Master coverage]
65
[![Code Quality][Master quality image]][Master quality]
@@ -13,7 +12,6 @@ You're looking at a standalone PHP library to parse and evaluate text based rule
1312

1413
This library has initially been used to change and configure the behavior of certain "Workflows" (without changing actual code) in an intranet application, but it may serve a purpose elsewhere.
1514

16-
1715
Find me on Twitter: @[nicoSWD](https://twitter.com/nicoSWD)
1816

1917
(If you're using PHP 5, you might want to take a look at [version 0.4.0](https://github.com/nicoSWD/php-rule-parser/tree/0.4.0))
@@ -39,7 +37,7 @@ This library works best with one of these bundles below, but they're not require
3937
Test if a value is in a given array
4038
```php
4139
$variables = [
42-
'coupon_code' => $_POST['coupon_code'],
40+
'coupon_code' => (string) $_POST['coupon_code'],
4341
];
4442

4543
$rule = new Rule('coupon_code in ["summer_discount", "summer21"]', $variables);
@@ -49,7 +47,7 @@ var_dump($rule->isTrue()); // bool(true)
4947
Performing a regular expression
5048
```php
5149
$variables = [
52-
'coupon_code' => $_POST['coupon_code'],
50+
'coupon_code' => (string) $_POST['coupon_code'],
5351
];
5452

5553
$rule = new Rule('coupon_code.test(/^summer20[0-9]{2}$/) == true', $variables);

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{
2020
"name": "Nicolas Oelgart",
2121
"role": "Developer",
22-
"homepage": "https://nicoswd.com"
22+
"homepage": "https://nico.es"
2323
}
2424
],
2525
"autoload": {
@@ -33,11 +33,11 @@
3333
}
3434
},
3535
"require": {
36-
"php": ">=8.1"
36+
"php": ">=8.4"
3737
},
3838
"require-dev": {
39-
"phpunit/phpunit": "^9.5",
40-
"mockery/mockery": "^1.4"
39+
"phpunit/phpunit": "^12.3",
40+
"mockery/mockery": "^1.6"
4141
},
4242
"scripts": {
4343
"test": "vendor/bin/phpunit"

tests/integration/HighlighterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use nicoSWD\Rule\Tokenizer\Tokenizer;
1414
use nicoSWD\Rule\TokenStream\Token\TokenFactory;
1515
use PHPUnit\Framework\TestCase;
16+
use PHPUnit\Framework\Attributes\Test;
1617

1718
final class HighlighterTest extends TestCase
1819
{
@@ -23,7 +24,7 @@ protected function setUp(): void
2324
$this->highlighter = new Highlighter(new Tokenizer(new JavaScript(), new TokenFactory()));
2425
}
2526

26-
/** @test */
27+
#[Test]
2728
public function givenAStyleForATokenGroupItShouldBeUsed(): void
2829
{
2930
$this->highlighter->setStyle(

tests/integration/ObjectTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
use nicoSWD\Rule\Parser\Exception\ParserException;
1111
use nicoSWD\Rule\Rule;
12+
use PHPUnit\Framework\Attributes\Test;
1213

1314
final class ObjectTest extends AbstractTestBase
1415
{
15-
/** @test */
16+
#[Test]
1617
public function givenAnObjectHasMethodsWhenPublicTheyShouldBeAccessible(): void
1718
{
1819
$myObj = new class {
@@ -40,7 +41,7 @@ public function cat()
4041
$this->assertTrue($this->evaluate('my_obj.test2().cat() === "meow"', $variables));
4142
}
4243

43-
/** @test */
44+
#[Test]
4445
public function givenAnObjectHasPropertiesWhenPublicTheyShouldBeAccessible(): void
4546
{
4647
$myObj = new class {
@@ -54,7 +55,7 @@ public function givenAnObjectHasPropertiesWhenPublicTheyShouldBeAccessible(): vo
5455
$this->assertTrue($this->evaluate('my_obj.test() === "my string"', $variables));
5556
}
5657

57-
/** @test */
58+
#[Test]
5859
public function publicMethodsShouldBeAccessibleMagicallyViaGet(): void
5960
{
6061
$myObj = new class {
@@ -71,7 +72,7 @@ public function getString()
7172
$this->assertTrue($this->evaluate('my_obj.string() === "some string"', $variables));
7273
}
7374

74-
/** @test */
75+
#[Test]
7576
public function publicMethodsShouldBeAccessibleMagicallyViaIs(): void
7677
{
7778
$myObj = new class {
@@ -93,7 +94,7 @@ public function yes()
9394
$this->assertTrue($this->evaluate('my_obj.string(my_obj.yes()) === "yes"', $variables));
9495
}
9596

96-
/** @test */
97+
#[Test]
9798
public function givenAnObjectWhenMagicMethodCallIsAvailableItShouldBeAccessible(): void
9899
{
99100
$myObj = new class {
@@ -129,7 +130,7 @@ public function givenAnObjectWhenMagicMethodsAreCalledDirectlyItShouldThrowAnExc
129130
$this->evaluate("my_obj.{$magicMethod}()", $variables);
130131
}
131132

132-
/** @test */
133+
#[Test]
133134
public function undefinedMethodsShouldThrowAnError(): void
134135
{
135136
$myObj = new class() {
@@ -145,7 +146,7 @@ public function undefinedMethodsShouldThrowAnError(): void
145146
$this->assertSame('Undefined method "nope" at position 6', $rule->getError());
146147
}
147148

148-
/** @test */
149+
#[Test]
149150
public function givenAnObjectWithMagicMethodGetWhenPropertyDoesNotExistItShouldNotBeCalled(): void
150151
{
151152
$myObj = new class {

tests/integration/ParserTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
*/
88
namespace nicoSWD\Rule\tests\integration;
99

10+
use PHPUnit\Framework\Attributes\Test;
11+
1012
final class ParserTest extends AbstractTestBase
1113
{
12-
/** @test */
14+
#[Test]
1315
public function multipleAnds(): void
1416
{
1517
$rule = 'foo=="MA" && bar=="EGP" && baz>50000';
@@ -37,7 +39,7 @@ public function multipleAnds(): void
3739
]));
3840
}
3941

40-
/** @test */
42+
#[Test]
4143
public function mixedOrsAndAnds(): void
4244
{
4345
$rule = '
@@ -53,14 +55,14 @@ public function mixedOrsAndAnds(): void
5355
]));
5456
}
5557

56-
/** @test */
58+
#[Test]
5759
public function emptyOrIncompleteRuleReturnsFalse(): void
5860
{
5961
$rule = '';
6062
$this->assertFalse($this->evaluate($rule));
6163
}
6264

63-
/** @test */
65+
#[Test]
6466
public function freakingLongRule(): void
6567
{
6668
$rule = '
@@ -87,7 +89,7 @@ public function freakingLongRule(): void
8789
]));
8890
}
8991

90-
/** @test */
92+
#[Test]
9193
public function negativeComparison(): void
9294
{
9395
$rule = '
@@ -107,7 +109,7 @@ public function negativeComparison(): void
107109
]));
108110
}
109111

110-
/** @test */
112+
#[Test]
111113
public function spacesBetweenStuff(): void
112114
{
113115
$rule = 'foo != 3
@@ -120,7 +122,7 @@ public function spacesBetweenStuff(): void
120122
$this->assertTrue($this->evaluate($rule, ['foo' => '-1']));
121123
}
122124

123-
/** @test */
125+
#[Test]
124126
public function singleLineCommentDoesNotKillTheRest(): void
125127
{
126128
$rule = ' 2 > 3

tests/integration/RuleTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
use nicoSWD\Rule;
1111
use PHPUnit\Framework\TestCase;
12+
use PHPUnit\Framework\Attributes\Test;
1213

1314
final class RuleTest extends TestCase
1415
{
15-
/** @test */
16+
#[Test]
1617
public function basicRuleWithCommentsEvaluatesCorrectly(): void
1718
{
1819
$string = '
@@ -39,7 +40,7 @@ public function basicRuleWithCommentsEvaluatesCorrectly(): void
3940
$this->assertTrue(!$rule->isFalse());
4041
}
4142

42-
/** @test */
43+
#[Test]
4344
public function isValidReturnsFalseOnInvalidSyntax(): void
4445
{
4546
$ruleStr = '(2 == 2) && (1 < 3 && 3 > 2 (1 == 1))';
@@ -50,7 +51,7 @@ public function isValidReturnsFalseOnInvalidSyntax(): void
5051
$this->assertSame('Unexpected "(" at position 28', $rule->getError());
5152
}
5253

53-
/** @test */
54+
#[Test]
5455
public function isValidReturnsTrueOnValidSyntax(): void
5556
{
5657
$ruleStr = '(2 == 2) && (1 < 3 && 3 > 2 || (1 == 1))';
@@ -61,7 +62,7 @@ public function isValidReturnsTrueOnValidSyntax(): void
6162
$this->assertEmpty($rule->getError());
6263
$this->assertTrue($rule->isTrue());
6364
}
64-
/** @test */
65+
#[Test]
6566
public function basicInRule(): void
6667
{
6768
$ruleStr = '4 in [4, 6, 7]';
@@ -81,7 +82,7 @@ public function basicInRule(): void
8182
$this->assertFalse($rule->isTrue());
8283
}
8384

84-
/** @test */
85+
#[Test]
8586
public function basicNotInRule(): void
8687
{
8788
$ruleStr = '5 not

0 commit comments

Comments
 (0)