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

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

Closed
geraintp opened this issue Apr 9, 2024 · 0 comments · Fixed by #39

Comments

@geraintp
Copy link

geraintp commented Apr 9, 2024

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..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant