Skip to content

Error "Call to a member function prepare() on null" when creating new Filemaker model #4

@cariboufute

Description

@cariboufute

When I try to create a new Filemaker model, I expect to create a new entry in Filemaker, but I receive an error saying "Call to a member function prepare() on null". It looks like the $pdo attribute in Illuminate\Database\Connection is not set.

The model (the bad attribute naming is made by client...)

<?php

//app/Models/Filemaker/Phonelog.php

namespace App\Models\Filemaker;

use FMLaravel\Database\Model;

class Phonelog extends Model
{
    protected $connection = 'filemaker';
    protected $layoutName = 'Basic';
    protected $primaryKey = 'Log Id';
    protected $fillable = [
        "Date",
        "Incoming|Outgoing",
        "Production ID",
        "Prod_Show_Combo",
        "From",
        "To",
        "Summary",
        "Result",
        "Topic",
        "Type",
    ];
}

The test

<?php

//tests/Learning/FilemakerDbTest.php

namespace Tests\Learning;

use App\Models\Filemaker\Phonelog;
use TestCase;

class FilemakerDbTest extends TestCase
{
    //DATABASE : fmsvr.rms.biz ?
    public function setUp()
    {
        parent::setUp();
        $this->model = new Phonelog;
    }

    public function testAll()
    {
        $logs = $this->model->all();

        $this->assertNotTrue($logs->isEmpty());
    }

    public function testEdit()
    {
        $form = [
            "Date" => "12/12/2012",
            "Incoming|Outgoing" => "Outgoing",
            "Production ID" => "p999",
            "Prod_Show_Combo" => "combo",
            "From" => "Joe Crisse",
            "To" => "Joe Crisse",
            "Summary" => "Sommaire",
            "Result" => "Result!",
            "Topic" => "Conclusion",
            "Type" => "type",
        ];

        $log = $this->model->create($form);

        $this->assertInstanceOf(Phonelog::class, $log);
    }
}

The PHPUnit log output. Please note that the first test works, so the connection to Filemaker server works too.

PHPUnit 4.8.24 by Sebastian Bergmann and contributors.

.E

Time: 4.06 seconds, Memory: 12.00Mb

There was 1 error:

1) Tests\Learning\FilemakerDbTest::testEdit
Error: Call to a member function prepare() on null

/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:408
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:666
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:629
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:409
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:365
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php:32
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1970
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1337
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1621
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1590
/home/vagrant/Code/rms-php-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1481
/home/vagrant/Code/rms-php-api/tests/Learning/FilemakerDbTest.php:42

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions