laravel에서 내 모델에 몇 가지 테스트를하고 있는데 spatie/laravel-activitylog을 사용하여 활동 로그를 활성화 할 때 몇 가지 문제가 있습니다.TDD Laravel - laravel 및 spatie/laravel-activitylog의 기능 테스트에서 JSON 인코딩 오류가 발생합니다.
그래서, 내가 Factory
를 사용하여 사용자를 생성, 나는 시스템에서 인증하고, 내가 로그 아웃하려고합니다 때이 오류가 얻을 :
1) Tests\Feature\Usuario\CriarUsuarioTest::testAcessaPaginaDeRegistro Illuminate\Database\Eloquent\JsonEncodingException: Unable to encode attribute [properties] for model [Spatie\Activitylog\Models\Activity] to JSON: Type is not supported.
내 시험 TestCase.php
:
protected function setUp()
{
parent::setUp();
$this->user = create('App\Models\Usuario');
$this->singIn($this->user)
->disableExceptionHandling();
}
...
...
...
protected function singIn($user)
{
$this->actingAs($user);
return $this;
}
protected function singOut()
{
// routeLogout() goes to '/logout' route.
$this->post(routeLogout()); // <- Here, where the error occurs
return $this;
}
을
내 App/Models/Usuario.php
모델 :
namespace App\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Webpatser\Uuid\Uuid;
use Spatie\Activitylog\Traits\LogsActivity;
class Usuario extends Authenticatable
{
use LogsActivity, Notifiable, SoftDeletes;
protected $table = 'usuario';
protected $fillable = [/*...*/] ; // I remove this to post here on SO
protected static $logFillable = true;
public $timestamps = true;
protected $dates = [
'created_at',
'updated_at',
'deleted_at'
];
protected static function boot()
{
// Handle the \LogsActivity boot method
parent::boot();
static::saving(function ($usuario){
$usuario->uuid = Uuid::generate()->string;
});
}
public function getRouteKeyName()
{
return 'uuid';
}
}
내 config/activitylog.php
FIL E :
return [
'enabled' => env('ACTIVITY_LOGGER_ENABLED', true),
'delete_records_older_than_days' => 365,
'default_log_name' => 'default',
'default_auth_driver' => null,
'subject_returns_soft_deleted_models' => false,
'activity_model' => \Spatie\Activitylog\Models\Activity::class,
];
내 phpunit.xml
파일 :
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="API_DEBUG" value="true"/>
<env name="memory_limit" value="512M"/>
<env name="APP_DATABASE" value="test"/>
</php>
</phpunit>
내 create_activity_log_migration
파일 : 나는 모델 활동 로그를 사용하지 않는 경우 그때 알
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateActivityLogTable extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('activity_log', function (Blueprint $table) {
$table->increments('id');
$table->string('log_name')->nullable();
$table->string('description');
$table->integer('subject_id')->nullable();
$table->string('subject_type')->nullable();
$table->integer('causer_id')->nullable();
$table->string('causer_type')->nullable();
$table->text('properties')->nullable();
$table->timestamps();
$table->index('log_name');
});
}
/**
* Reverse the migrations.
*/
public function down()
{
Schema::drop('activity_log');
}
}
, 그 잘 작동. 그리고, 내가 땜장이 나 브라우저로 시스템을 사용할 때 로그도 잘 작동합니다.
'routeLogout()'의 정의를 보여줄 수 있습니까? – Camilo
죄송합니다, 깜 빡합니다. 'routeLogout()'는'/ logout' 경로를 돕는 역할을합니다. – Abe
'/ logout' 경로에 대한 요청을받는 방법을 보여줄 수 있습니까? – Camilo