pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.49k stars 343 forks source link

[Bug]: Could not bind closure. #1048

Closed JhonatanGarcia92 closed 8 months ago

JhonatanGarcia92 commented 9 months ago

What Happened

Issue: Could not bind closure. PHP version: 8.2.13 Operating system: Linux str_replace(): Argument #3 ($subject) must be of type array|string, null given

Screenshot 2023-12-27 at 14 59 22

How to Reproduce

new test:

UserUnitTest.php

<?php

use App\Api\User\Models\UserModel;

test('check fillable', static function () {
    $userModel = new UserModel();

    $arrayCompared = [
        'name',
        'email',
        'password',
        'active',
        'confirmed_at',
    ];

    checkFillableModels($userModel::class, $userModel->getFillable(), $arrayCompared);
});

in Pest.php, was created

function checkFillableModels(string $modelClass, array $modelFillable, array $arrayCompared): void
{
    $diff = array_diff($modelFillable, $arrayCompared);
    if (count($diff) > 0) {
        $implode = implode(', ', $diff);
        throw new ExpectationFailedException("Found diff array '$implode' in the mode: " . $modelClass);
    }

    assertCount(0, $diff);
}

composer.php

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The skeleton application for the Laravel framework.",
    "keywords": ["laravel", "framework"],
    "license": "MIT",
    "require": {
        "php": "^8.2",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^10.10",
        "laravel/sanctum": "^3.3",
        "laravel/tinker": "^2.8",
        "spatie/laravel-permission": "^6.2",
        "tymon/jwt-auth": "^2.0"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/pail": "^1.0",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.18",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^7.0",
        "pestphp/pest": "^2.29",
        "phpunit/phpunit": "^10.1",
        "spatie/laravel-ignition": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true
        }
    },
    "minimum-stability": "stable",
    "prefer-stable": true
}

Sample Repository

No response

Pest Version

2.29

PHP Version

8.2.13

Operation System

Linux

Notes

No response

Katalam commented 8 months ago

The static is the problem. Remove it and you will remove the error.