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

Fixture fatal error #5

Open
florant359 opened this issue Apr 2, 2020 · 1 comment
Open

Fixture fatal error #5

florant359 opened this issue Apr 2, 2020 · 1 comment
Labels

Comments

@florant359
Copy link

I am trying to use Faker in my fixtures to generate data for my tests, i tried your fixture example but when i try to run my test i get this error.

Fatal error: Declaration of Gourmet\Faker\TestSuite\Fixture\TestFixture::insert(Cake\Database\Connection $db) must be compatible with Cake\TestSuite\Fixture\TestFixture::insert(Cake\Datasource\ConnectionInterface $db) in C:\laragon\www\my_app_name\vendor\gourmet\faker\src\TestSuite\Fixture\TestFixture.php on line 11
Can you please help me find out what is missing.
My php version is : 7.3.5
My cakephp version : 3.7
fzaninotto/faker: 1.4.*

My PostsFixture

`<?php

namespace App\Test\Fixture;

use Gourmet\Faker\TestSuite\Fixture\TestFixture;

class PostsFixture extends TestFixture {

public $fields = [
    'id' => ['type' => 'integer'],
    'title' => ['type' => 'string', 'length' => 255, 'null' => false],
    'body' => 'text',
    'published' => ['type' => 'integer', 'default' => '0', 'null' => false],
    'created' => 'datetime',
    'updated' => 'datetime',
    '_constraints' => [
        'primary' => ['type' => 'primary', 'columns' => ['id']]
    ]
];

public $records = [
    [
        'id' => 1,
        'title' => 'First Article',
        'body' => 'First Article Body',
        'published' => '1',
        'created' => '2007-03-18 10:39:23',
        'updated' => '2007-03-18 10:41:31'
    ],
    [
        'id' => 2,
        'title' => 'Second Article',
        'body' => 'Second Article Body',
        'published' => '1',
        'created' => '2007-03-18 10:41:23',
        'updated' => '2007-03-18 10:43:31'
    ],
    [
        'id' => 3,
        'title' => 'Third Article',
        'body' => 'Third Article Body',
        'published' => '1',
        'created' => '2007-03-18 10:43:23',
        'updated' => '2007-03-18 10:45:31'
    ]
];

public $number = 20;
public $guessers = ['\Faker\Guesser\Name'];

public function init() {
    $this->customColumnFormatters = [
        'id' => function () { return $this->faker->numberBetween(count($this->records) + 2); },
        'published' => function () { return rand(0,3); }
    ];
    parent::init();
}

}`

@jadb
Copy link
Member

jadb commented Apr 19, 2020

The plugin wasn't upgraded/tested for this version of CakePHP.

It looks like the error is caused because a method signature was changed.

I don't have time to fix that right now but if you want, you could that yourself and submit a PR. The error message is pretty self-explanatory.

@jadb jadb added the bug label Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants