thephpleague / factory-muffin

Enables the rapid creation of objects for testing
https://factory-muffin.thephpleague.com/
MIT License
531 stars 72 forks source link

Custom delete Method support gone? #420

Closed Anyqax closed 8 years ago

Anyqax commented 8 years ago

We are using FactoryMuffin with Propel v1. Propel delete Methods do not return anything, therefore even on successful deletion FactoryMuffin throws a DeletionFailedException. Apparently there was support for custom delete methods in an earlier version: https://github.com/thephpleague/factory-muffin/commit/937c225625b223557f6db23c0d928493d7dd4a19 But that change hasn't survived the facade refactoring in v3: https://github.com/thephpleague/factory-muffin/pull/334/commits/de2a3d2129cad7241451db0dd826adc0ecf74b0d

Are there plans to support custom delete methods again?

GrahamCampbell commented 8 years ago

This is still possible. The idea now is just that you extend the ModelStore class, and then pass that through to the FactoryMuffin constructor.

GrahamCampbell commented 8 years ago
<?php

use League\FactoryMuffin\FactoryMuffin;
use League\FactoryMuffin\Stores\ModelStore;

class CustomStore extends ModelStore
{
    // custom code in here
}

$fm = new FactoryMuffin(new CustomStore);
GrahamCampbell commented 8 years ago

If you want to force delention to be assumed to have worked, you could just have this:

<?php

use League\FactoryMuffin\FactoryMuffin;
use League\FactoryMuffin\Stores\ModelStore;

class CustomStore extends ModelStore
{
    /**
     * Delete our object from the db.
     *
     * @param object $model The model instance.
     *
     * @throws \League\FactoryMuffin\Exceptions\DeleteMethodNotFoundException
     *
     * @return mixed
     */
    protected function delete($model)
    {
        parent::delete($model);

        return true;
    }
}

$fm = new FactoryMuffin(new CustomStore);
Anyqax commented 8 years ago

ah ok, makes sense, thanks