woocommerce icon indicating copy to clipboard operation
woocommerce copied to clipboard

Test code referenced in Production code explicitly preventing models from being extended or having factories.

Open geraintp opened this issue 1 year ago • 0 comments

Test code referenced in Production code explicitly preventing models from being extended or having factories.

Order Product Customer

Models all define/override newFactory changing the default method signature from hasFactory, explicitly typing them to classes that are only composer PSR loaded in require-dev so don't exist in the production code base.

    /**
     * Create a new factory instance for the model.
     *
     * @return ProductFactory
     */
    protected static function newFactory(): ProductFactory

Causing this error in Production when trying to add or use factories.

Declaration of Illuminate\Database\Eloquent\Factories\HasFactory::newFactory() must be compatible with Corcel\WooCommerce\Model\Product::newFactory()  
  : Database\Factories\ProductFactory 

Even when Database\Factories\ProductFactory extends Illuminate\Database\Eloquent\Factories\HasFactory

the method signature should typed to the Factory interface as the original signature is.

    /**
     * Create a new factory instance for the model.
     *
     * @return \Illuminate\Database\Eloquent\Factories\Factory<static>
     */
    protected static function newFactory()

Or the factories should be moved into the production code and namespace (or added to a namespace that doesn't explicitly conflict with every laravel application) so they can be extending and used to fulfill the parent models method signature..

geraintp avatar Apr 09 '24 15:04 geraintp