Hello everyone,

I'm trying to write some unit tests on some services/classes that uses Models but i cannot simulate any data. The only way I found to do so is to use real database which is not the best practice for units...

I tried to use AspectMock\Test::double to do mock find and findFirst methods but totally ignored during tests...

Here is my test


use AspectMock\Test as test;

class ArticleDeserializerTest extends \Codeception\Test\Unit
    protected function _before()
        test::double(Article::class, [ 'findFirst' => date_create() ]);

     * @dataProvider getData
    public function testDenormalize($data, $valid)
        if ($valid) {
            $this->assertInstanceOf(Article::class, (new ArticleDeserializer)->denormalize($data));
        } else {
            $this->expectExceptionMessage('Undefined index:');
            (new ArticleDeserializer)->denormalize($data);

    public function getData()
        $article = json_decode(file_get_contents(APP_PATH . '/cli/commands/Fixtures/sources/articles-103699094818044.json'), true);
        $articleBadURL = $article;
        $articleBadURL['publicationUrl'] = 'not-a-valid-url';
        $articleMissing = $article;
        return [
            [ $article, true ],
            [ $articleBadURL, true ],
            [ $articleMissing, false ],

In this example Article::findFirst() never returns a \Datetime.

I tried with codeception and phpunit, same result.

Please help.