Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding Laravel 11 support + pest [v4.1.0] #12

Merged
merged 8 commits into from
Dec 17, 2024
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
56 changes: 29 additions & 27 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,42 @@ jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
fail-fast: false
matrix:
php: [8.1]
laravel: [10.*]
php: [8.1, 8.2, 8.3, 8.4]
laravel: [10.*, 11.*]
exclude:
- php: 8.1
laravel: 10.*
laravel: 11.*
include:
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress
- name: Execute tests
run: vendor/bin/phpunit
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress
- name: Execute tests
run: vendor/bin/pest
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ You can install the package via composer:
composer require pod-point/laravel-configcat
```

For Laravel 5.4 up to 9.x

```bash
composer require pod-point/laravel-configcat:^3.0
```

### Publishing the config file

Next, you should publish the Laravel package configuration file using the `vendor:publish` Artisan command. It will be placed in your application's config directory:
Expand Down Expand Up @@ -71,12 +77,12 @@ Validator::make([
]);
```

- When the feature flag is **on**
- The `email` will be a required field
- The `username` will be an optional field
- When the feature flag is **off**, undefined, a text or number setting
- The `email` will be an optional field
- The `username` will be a required field
- When the feature flag is **on**
- The `email` will be a required field
- The `username` will be an optional field
- When the feature flag is **off**, undefined, a text or number setting
- The `email` will be an optional field
- The `username` will be a required field

### HTTP middleware

Expand Down Expand Up @@ -244,10 +250,10 @@ Please see [CONTRIBUTING](https://github.com/Pod-Point/laravel-configcat/blob/ma

## Credits

- [configcat/php-sdk](https://github.com/configcat/php-sdk)
- [ylsideas/feature-flags](https://github.com/ylsideas/feature-flags) for inspiration
- [Pod Point](https://github.com/pod-point)
- [All Contributors](https://github.com/pod-point/laravel-configcat/graphs/contributors)
- [configcat/php-sdk](https://github.com/configcat/php-sdk)
- [ylsideas/feature-flags](https://github.com/ylsideas/feature-flags) for inspiration
- [Pod Point](https://github.com/pod-point)
- [All Contributors](https://github.com/pod-point/laravel-configcat/graphs/contributors)

## License

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
}
],
"require": {
"php": ">=8.1",
"php": "^8.1",
"configcat/configcat-client": "^9.0",
"illuminate/contracts": "^10.0"
"illuminate/contracts": "^10.0|^11.0"
},
"require-dev": {
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^9.6",
"orchestra/testbench": "^8.0|^9.0",
"pestphp/pest": "^2.28",
"mockery/mockery": "^1.6.7"
},
"autoload": {
Expand All @@ -50,15 +50,15 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit --colors=always",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
"test": "vendor/bin/pest"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true,
"allow-plugins": {
"kylekatarnls/update-helper": true
"kylekatarnls/update-helper": true,
"pestphp/pest-plugin": true
}
}
}
24 changes: 7 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<exclude>./tests/resources</exclude>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<exclude>./tests/resources</exclude>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/Facades/ConfigCat.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function fake(array $flagsToFake = []): ConfigCatFake
return $fake;
}

protected static function isFake(): bool
public static function isFake(): bool
{
$name = static::getFacadeAccessor();

Expand Down
203 changes: 95 additions & 108 deletions tests/Feature/BladeDirectivesTest.php
Original file line number Diff line number Diff line change
@@ -1,112 +1,99 @@
<?php

namespace PodPoint\ConfigCat\Tests\Feature;

use Illuminate\Support\Facades\Route;
use PodPoint\ConfigCat\Facades\ConfigCat;
use PodPoint\ConfigCat\Tests\TestCase;

class BladeDirectivesTest extends TestCase
{
public function test_it_will_render_something_only_when_the_corresponding_feature_flag_is_enabled()
{
ConfigCat::fake([
'enabled_feature' => true,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertDontSee('I am hidden');
}

public function test_it_will_consider_an_unknown_feature_flag_to_be_disabled()
{
ConfigCat::fake([
'enabled_feature' => true,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertSee('You can see me');
}

public function test_it_will_consider_a_feature_flag_as_a_number_setting_to_be_disabled()
{
ConfigCat::fake([
'enabled_feature' => 1234,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertDontSee('I should be visible');
$this->get('/foo')->assertSee('I should not be visible');
}

public function test_it_will_consider_a_feature_flag_as_a_text_setting_to_be_disabled()
{
ConfigCat::fake([
'enabled_feature' => 'foobar',
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertDontSee('I should be visible');
$this->get('/foo')->assertSee('I should not be visible');
}

public function test_it_supports_the_unlessconfigcat_directive()
{
ConfigCat::fake([
'enabled_feature' => true,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertSee('I am not hidden');
}

public function test_it_supports_the_else_directive()
{
ConfigCat::fake([
'enabled_feature' => false,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertDontSee('I should be visible');
$this->get('/foo')->assertSee('I should not be visible');
}

public function test_it_supports_the_elseconfigcat_directive()
{
ConfigCat::fake([
'enabled_feature' => true,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertDontSee('You cannot see me');
$this->get('/foo')->assertSee('You can see me');
}
}

test('it will render something only when the corresponding feature flag is enabled', function () {
ConfigCat::fake([
'enabled_feature' => true,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertDontSee('I am hidden');
});

test('it will consider an unknown feature flag to be disabled', function () {
ConfigCat::fake([
'enabled_feature' => true,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertSee('You can see me');
});

test('it will consider a feature flag as a number setting to be disabled', function () {
ConfigCat::fake([
'enabled_feature' => 1234,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertDontSee('I should be visible');
$this->get('/foo')->assertSee('I should not be visible');
});

test('it will consider a feature flag as a text setting to be disabled', function () {
ConfigCat::fake([
'enabled_feature' => 'foobar',
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertDontSee('I should be visible');
$this->get('/foo')->assertSee('I should not be visible');
});

test('it supports the unlessconfigcat directive', function () {
ConfigCat::fake([
'enabled_feature' => true,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertSee('I am not hidden');
});

test('it supports the else directive', function () {
ConfigCat::fake([
'enabled_feature' => false,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertDontSee('I should be visible');
$this->get('/foo')->assertSee('I should not be visible');
});

test('it supports the elseconfigcat directive', function () {
ConfigCat::fake([
'enabled_feature' => true,
'disabled_feature' => false,
]);

Route::get('/foo', function () {
return view('feature');
});

$this->get('/foo')->assertDontSee('You cannot see me');
$this->get('/foo')->assertSee('You can see me');
});
Loading
Loading