diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..5811f0c --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,23 @@ +name: Check & fix styling + +on: [push] + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Run PHP CS Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --config=.php-cs-fixer.php --allow-risky=yes + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Fix styling diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..e4d66ff --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,49 @@ +name: run-tests + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: [8.0, 8.1, 8.2, 8.3] + laravel: [8.*, 9.*, 10.*, 11.*] + exclude: + - laravel: 10.* + php: 8.0 + + - laravel: 11.* + php: 8.0 + - laravel: 11.* + php: 8.1 + + name: P${{ matrix.php }} - L${{ matrix.laravel }} + + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --prefer-stable --prefer-dist --no-interaction + - name: Execute tests + run: vendor/bin/pest diff --git a/composer.json b/composer.json index 88d9fb9..5f64b16 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,10 @@ { "name": "ensi/test-factories", - "description": "", "keywords": [ "laravel", "factory" ], + "description": "", "license": "MIT", "type": "library", "authors": [ @@ -16,13 +16,13 @@ "require": { "php": "^8.0", "fakerphp/faker": "^1.10 || ^2.0", - "illuminate/support": "^8.0 || ^9.0 || ^10.0" + "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.2", "pestphp/pest": "^1.16 || ^2.0", "php-parallel-lint/php-var-dump-check": "^0.5.0", - "phpunit/phpunit": "^9.0 || ^10.0" + "phpunit/phpunit": "^9.0 || ^10.0 || ^11.0" }, "autoload": { "psr-4": { diff --git a/src/Factory.php b/src/Factory.php index 24dc9a1..69c60d0 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -101,12 +101,14 @@ protected function when(bool $condition, $value, $default = null): mixed protected function whenNotNull($condition, $value, $default = null): mixed { $default = func_num_args() === 3 ? $default : new FactoryMissingValue; + return $this->when($condition !== null, $value, $default); } protected function executed($condition, $value, $default = null): mixed { $default = func_num_args() === 3 ? $default : new FactoryMissingValue; + return $this->when($condition !== null, $value, $default); } diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 4b4200e..3a7e222 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -35,4 +35,4 @@ $result = TestArrayFactory::new()->make(); expect($result)->not->toHaveKey('id'); -}); \ No newline at end of file +});