PoncetheLion's avatar

PHPUnit MySQL in memory test with point and polygon column

I have a migration for a table as following:

    use Illuminate\Support\Facades\Schema;
    use Grimzy\LaravelMysqlSpatial\Schema\Blueprint;  //use this as blueprint
    use Illuminate\Database\Migrations\Migration;
Schema::create('properties', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->point('position');
    $table->integer('radius');
    $table->polygon('area_perimeter');
});

Also, I am using this library and added trait to the property model:

https://packagist.org/packages/grimzy/laravel-mysql-spatial

Before updating the position and area_perimeter to use geospatial type, the PHPUnit works with

<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="TELESCOPE_ENABLED" value="false"/>

But now it no longer works and I am getting this error:

Argument 1 passed to CreatePropertiesTable::{closure}() must be an instance of Grimzy\LaravelMysqlSpatial\Schema\Blueprint, instance of Illuminate\Database\Schema\Blueprint given

Which has something to do with sqlite does not support point and polygon column

I would like to be able to run phpunit on mysql in memory. Or how can I make this work with the said requirements?

0 likes
9 replies
PoncetheLion's avatar

@SERGIU17 - It is working perfectly, the only issue now is more on phpunit testing where as the phpunit runs on sqlite on memory, instead I would like to run it on mysql memory.

And yes, I have added that blueprint in the migration

gourab's avatar

Hi it's not working for me . I am using laravel 5.8 . when I am trying I have got this error

) Tests\Feature\DestinationTest::destination_addition Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such function: ST_GeomFromText (SQL: insert into "destinations" ("name", "url", "about", "address", "location", "image", "updated_at", "created_at") values (sddsds, sddsds, sfdsfs sdfds sdfsd, dsfds dsfds, ST_GeomFromText(POINT(30.33 20.22)), destination/0PKOpauAuF1wB8cvXz6UQiwT2LXACUlWx6J5eeAI.jpeg, 2019-08-16 06:46:26, 2019-08-16 06:46:26))

1 like
PoncetheLion's avatar

You need to install grimzy/laravel-mysql-spatial and use MySQL version >= 5.7 or any database that will support geospatial

gourab's avatar

Hi it's working perfectly on the web. But in PHPUnit testing, it's showing an error.

) Tests\Feature\DestinationTest::destination_addition Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such function: ST_GeomFromText (SQL: insert into "destinations" ("name", "url", "about", "address", "location", "image", "updated_at", "created_at") values (sddsds, sddsds, sfdsfs sdfds sdfsd, dsfds dsfds, ST_GeomFromText(POINT(30.33 20.22)), destination/0PKOpauAuF1wB8cvXz6UQiwT2LXACUlWx6J5eeAI.jpeg, 2019-08-16 06:46:26, 2019-08-16 06:46:26))

1 like
PoncetheLion's avatar

What database are you using for your test?

If you are doing it in memory and using SQLite, geospatial is not supported by SQLite. Maybe you might want to test on Spatialite? Haven't tried it though.

gourab's avatar

I have tried in SQLite and Mysql. showing the same error in both cases.

Please or to participate in this conversation.