Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"
# Widen the version constraints instead of raising the lower bound.
# This library must stay installable on all supported PHP versions.
versioning-strategy: "widen"
open-pull-requests-limit: 10
commit-message:
prefix: "chore(deps)"
groups:
symfony:
patterns:
- "symfony/*"
dev-tools:
patterns:
- "friendsofphp/php-cs-fixer"
- "phpstan/*"
- "phpunit/phpunit"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "ci"
29 changes: 24 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ on:
schedule:
- cron: "37 13 * * 1"

permissions:
contents: "read"

concurrency:
group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}"
cancel-in-progress: "${{ github.event_name == 'pull_request' }}"

jobs:
tests:
name: "Run tests"
name: "Run tests (PHP ${{ matrix.php-version }}, ${{ matrix.dependency-versions }} dependencies)"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
php-version:
- "8.2"
- "8.3"
- "8.4"
- "8.5"
dependency-versions:
- "highest"
include:
# Test the lowest allowed dependencies only on the lowest supported PHP version.
# The oldest releases of some dependencies predate newer PHP versions.
- php-version: "8.2"
dependency-versions: "lowest"
services:
redis:
image: "redis:7"
Expand All @@ -35,12 +50,12 @@ jobs:
with:
php-version: "${{ matrix.php-version }}"
coverage: "none"
env:
fail-fast: true
- name: "Validate composer.json and composer.lock"
- name: "Validate composer.json"
run: "composer validate --strict --no-interaction --ansi"
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v4"
with:
dependency-versions: "${{ matrix.dependency-versions }}"
- name: "Run tests"
run: "make test"

Expand All @@ -57,6 +72,8 @@ jobs:
coverage: "none"
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v4"
with:
dependency-versions: "highest"
- name: "Check coding standards"
run: "make php-cs-fixer-ci"

Expand All @@ -73,5 +90,7 @@ jobs:
coverage: "none"
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v4"
with:
dependency-versions: "highest"
- name: "Run PHPStan"
run: "make phpstan"
run: "vendor/bin/phpstan analyse --no-progress --error-format=github"
4 changes: 4 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'@autoPHPUnitMigration:risky' => true,
'php_unit_attributes' => true,
'php_unit_data_provider_return_type' => true,
'void_return' => true,
'declare_strict_types' => true,
'php_unit_method_casing' => ['case' => 'snake_case'],
])
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ dependencies:
test:
vendor/bin/phpunit --testdox --exclude-group=none --colors=always

.PHONY: coverage
coverage:
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text

.PHONY: qa
qa: php-cs-fixer phpstan

Expand All @@ -19,9 +23,9 @@ php-cs-fixer:
php-cs-fixer-ci:
vendor/bin/php-cs-fixer fix --dry-run --no-interaction --allow-risky=yes --diff --verbose

PHONY: phpstan
.PHONY: phpstan
phpstan:
vendor/bin/phpstan analyse --level=max lib/
vendor/bin/phpstan analyse

.PHONY: changelog
changelog:
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
"require-dev": {
"predis/predis": "^3.5",
"symfony/expression-language": "^6.4 || ^7.4 || ^8.0",
"phpunit/phpunit": "^11.5",
"phpunit/phpunit": "^11.5 || ^12.5 || ^13.4",
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^2.0"
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"psr/http-message": "^1.1 || ^2.0"
},
"suggest": {
"predis/predis": "To use the PredisCollection to persist toggles in redis",
Expand Down
10 changes: 10 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon

parameters:
level: max
paths:
- lib
- test
2 changes: 0 additions & 2 deletions phpstan.neon

This file was deleted.

17 changes: 16 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
requireCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
failOnNotice="true"
failOnPhpunitDeprecation="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnPhpunitDeprecations="true">
<testsuites>
<testsuite name="Qandidate Feature Flip Test Suite">
<directory>./test/Qandidate/</directory>
Expand Down
15 changes: 10 additions & 5 deletions test/Qandidate/Toggle/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,36 @@

namespace Qandidate\Toggle;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

#[CoversClass(Context::class)]
class ContextTest extends TestCase
{
#[Test]
public function it_sets_a_value()
public function it_sets_a_value(): void
{
$context = new Context();
$context->set('foo', 'bar');

$this->assertEquals('bar', $context->get('foo'));
$this->assertSame('bar', $context->get('foo'));
}

#[Test]
#[DataProvider('validValues')]
public function it_exposes_whether_it_has_a_value($value)
public function it_exposes_whether_it_has_a_value(mixed $value): void
{
$context = new Context();
$context->set('foo', $value);

$this->assertTrue($context->has('foo'));
}

public static function validValues()
/**
* @return iterable<array{mixed}>
*/
public static function validValues(): iterable
{
return [
[42],
Expand All @@ -50,7 +55,7 @@ public static function validValues()
}

#[Test]
public function it_does_not_have_a_value_that_was_never_set()
public function it_does_not_have_a_value_that_was_never_set(): void
{
$context = new Context();

Expand Down
15 changes: 9 additions & 6 deletions test/Qandidate/Toggle/ExpressionConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,33 @@

namespace Qandidate\Toggle;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\ExpressionLanguage\SyntaxError;

#[CoversClass(ExpressionCondition::class)]
class ExpressionConditionTest extends TestCase
{
protected $language;
private ExpressionLanguage $language;

protected function setUp(): void
{
$this->language = new ExpressionLanguage();
}

#[Test]
public function it_should_fire_a_syntax_error_exception()
public function it_should_fire_a_syntax_error_exception(): void
{
$this->expectException('Symfony\Component\ExpressionLanguage\SyntaxError');
$this->expectException(SyntaxError::class);
$condition = new ExpressionCondition('price < 5', $this->language);
$context = new Context();

$condition->holdsFor($context);
}

#[Test]
public function it_should_evaluate_a_correct_expression()
public function it_should_evaluate_a_correct_expression(): void
{
$condition = new ExpressionCondition('user["active"] and product["price"] >= 25', $this->language);
$context = new Context();
Expand All @@ -54,7 +57,7 @@ public function it_should_evaluate_a_correct_expression()
}

#[Test]
public function it_should_returns_false_if_the_conditions_are_not_met()
public function it_should_returns_false_if_the_conditions_are_not_met(): void
{
$condition = new ExpressionCondition('"bootstrap" in user["tags"]', $this->language);
$context = new Context();
Expand All @@ -68,7 +71,7 @@ public function it_should_returns_false_if_the_conditions_are_not_met()
}

#[Test]
public function it_should_return_false_if_the_expression_does_not_return_boolean()
public function it_should_return_false_if_the_expression_does_not_return_boolean(): void
{
$condition = new ExpressionCondition('user["tags"]', $this->language);
$context = new Context();
Expand Down
34 changes: 24 additions & 10 deletions test/Qandidate/Toggle/Operator/EqualToOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@

namespace Qandidate\Toggle\Operator;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Qandidate\Toggle\TestCase;

#[CoversClass(EqualTo::class)]
class EqualToOperatorTest extends TestCase
{
#[Test]
#[DataProvider('integerValues')]
public function it_applies_to_integer_values($value, $argument)
public function it_applies_to_integer_values(mixed $value, mixed $argument): void
{
$operator = new EqualTo($value);
$this->assertTrue($operator->appliesTo($argument));
}

public static function integerValues()
/**
* @return iterable<array{mixed, mixed}>
*/
public static function integerValues(): iterable
{
return [
[0, 0],
Expand All @@ -38,13 +43,16 @@ public static function integerValues()

#[Test]
#[DataProvider('stringValues')]
public function it_applies_to_string_values($value, $argument)
public function it_applies_to_string_values(mixed $value, mixed $argument): void
{
$operator = new EqualTo($value);
$this->assertTrue($operator->appliesTo($argument));
}

public static function stringValues()
/**
* @return iterable<array{mixed, mixed}>
*/
public static function stringValues(): iterable
{
return [
['foo', 'foo'],
Expand All @@ -55,13 +63,16 @@ public static function stringValues()

#[Test]
#[DataProvider('floatValues')]
public function it_applies_to_float_values($value, $argument)
public function it_applies_to_float_values(mixed $value, mixed $argument): void
{
$operator = new EqualTo($value);
$this->assertTrue($operator->appliesTo($argument));
}

public static function floatValues()
/**
* @return iterable<array{mixed, mixed}>
*/
public static function floatValues(): iterable
{
return [
[3.14, 3.14],
Expand All @@ -71,13 +82,16 @@ public static function floatValues()

#[Test]
#[DataProvider('notEqualValues')]
public function it_does_not_apply_to_not_equal_values($value, $argument)
public function it_does_not_apply_to_not_equal_values(mixed $value, mixed $argument): void
{
$operator = new EqualTo($value);
$this->assertFalse($operator->appliesTo($argument));
}

public static function notEqualValues()
/**
* @return iterable<array{mixed, mixed}>
*/
public static function notEqualValues(): iterable
{
return [
[42, 43],
Expand All @@ -91,9 +105,9 @@ public static function notEqualValues()
}

#[Test]
public function it_exposes_its_value()
public function it_exposes_its_value(): void
{
$operator = new EqualTo(42);
$this->assertEquals(42, $operator->getValue());
$this->assertSame(42, $operator->getValue());
}
}
Loading
Loading