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.42k stars 338 forks source link

Arch plugin fails #782

Closed TKrisee closed 1 year ago

TKrisee commented 1 year ago

Hi,

I've encountered the following error using the aarch plugin:

Testcase:

<?php

test('No debugging statements are left in code')
    ->expect(['dd', 'dump', 'ray', 'die', 'd'])->each->not()->toBeUsed();

output:

PHP Fatal error:  Declaration of MyCLabs\Enum\PHPUnit\Comparator::accepts($expected, $actual) must be compatible with SebastianBergmann\Comparator\Comparator::accepts(mixed $expected, mixed $actual): bool in /var/www/html/plugins/php-monorepo/vendor/myclabs/php-enum/src/PHPUnit/Comparator.php on line 17

I don't know if this is the right repo to report this in or in phpunit-architecture-test. I've checked the myclabs/php-enum but it uses and older version of the sebastian/comparator package that still does not have the type hints in it. I'm using the latest (2.5) pest version and the latest (10.1) phpunit version.

Thanks for the awesome framework btw.

nunomaduro commented 1 year ago

Can you share your "composer.json" file please?

TKrisee commented 1 year ago

Absolutely, here you go:

{
    "name": "my-project/php-monorepo",
    "description": "Collection of packages for laravel projects",
    "license": "MIT",
    "require": {
        "php": "^8.1",
        "ext-intl": "*",
        "ext-json": "*",
        "composer-runtime-api": "^2.1",
        "akaunting/laravel-money": "^3.1 || ^4.0",
        "doctrine/dbal": "^3.3.3",
        "filament/filament": "^2.0",
        "filament/spatie-laravel-media-library-plugin": "^2.0",
        "illuminate/contracts": "^10.0",
        "livewire/livewire": "^2.10",
        "maatwebsite/excel": "^3.1",
        "picqer/php-barcode-generator": "^2.2",
        "pxlrbt/filament-excel": "^1.1",
        "spatie/laravel-package-tools": "^1.13.0",
        "spatie/laravel-permission": "^5.5",
        "staudenmeir/eloquent-has-many-deep": "^1.7"
    },
    "require-dev": {
        "ergebnis/composer-normalize": "^2.28",
        "laravel/pint": "^1.0",
        "nunomaduro/collision": "^7.0",
        "nunomaduro/larastan": "^2.0.1",
        "orchestra/testbench": "^8.0",
        "pestphp/pest": "^2.0",
        "pestphp/pest-plugin-laravel": "^2.0",
        "phpstan/extension-installer": "^1.1",
        "phpstan/phpstan-deprecation-rules": "^1.0",
        "phpstan/phpstan-phpunit": "^1.0",
        "phpunit/phpunit": "^10.0",
        "spatie/laravel-ray": "^1.26",
        "symplify/monorepo-builder": "11.2.2.72"
    },
    "replace": {
        "my-project/filament-core": "self.version",
        "my-project/klk-wms": "self.version",
        "my-project/laravel-core": "self.version"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "autoload": {
        "psr-4": {
            "MYPROJECT\\": "packages",
            "MYPROJECT\\Filament\\Core\\": "packages/Filament/Core/src",
            "MYPROJECT\\Filament\\WMS\\": "packages/Filament/WMS/src",
            "MYPROJECT\\Laravel\\Core\\": "packages/Laravel/Core/src",
            "MYPROJECT\\Tests\\Database\\Factories\\": "tests/database/factories"
        },
        "files": [
            "packages/Laravel/Core/src/helpers.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "MYPROJECT\\Tests\\": "tests/src",
            "MYPROJECT\\Tests\\Models\\": "tests/Models"
        }
    },
    "config": {
        "allow-plugins": {
            "composer/package-versions-deprecated": true,
            "pestphp/pest-plugin": true,
            "phpstan/extension-installer": true,
            "ergebnis/composer-normalize": true
        },
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "aliases": {
                "FilamentCore": "MYPROJECT\\Filament\\Core\\Facades\\FilamentCore",
                "LaravelCore": "MYPROJECT\\Laravel\\Core\\Facades\\LaravelCore"
            },
            "providers": [
                "MYPROJECT\\Filament\\Core\\CoreServiceProvider",
                "MYPROJECT\\Filament\\WMS\\WMSServiceProvider",
                "MYPROJECT\\Laravel\\Core\\CoreServiceProvider"
            ]
        }
    },
    "scripts": {
        "pint": "pint",
        "test": [
            "@test:pest",
            "@test:phpstan"
        ],
        "test:pest": "pest",
        "test:phpstan": "phpstan analyse"
    }
}

We are using this for a monorepo, in which we use enums for model statuses and other stuff via the Eloquent $casts:


<?php

namespace MYPROJECT\Filament\WMS\Enums;

use MYPROJECT\Laravel\Core\Traits\EnumToArray;

enum DocumentStatus: int
{
    use EnumToArray;

    case PENDING = 0;
    case DISPATCHED = 1;
    case CLOSED = 2;
}

<?php

namespace MYPROJECT\Laravel\Core\Traits;

trait EnumToArray
{
    public static function names(): array
    {
        return array_column(self::cases(), 'name');
    }

    public static function values(): array
    {
        return array_column(self::cases(), 'value');
    }

    public static function array(): array
    {
        return array_combine(self::names(), self::values());
    }

    public static function translatedEnums(string $translationKey): array
    {
        return array_combine(
            self::values(),
            array_combine(
                self::names(),
                __($translationKey)
            )
        );
    }
}
TKrisee commented 1 year ago

It seems like it was some sort of cache issue, after I've purged every cache (composer, docker etc) it seems to be working now. Thank you for your time.