[增添]添加了datasource的setting数据库以及默认值
This commit is contained in:
40
vendor/anourvalar/eloquent-serialize/tests/ConnectionTest.php
vendored
Normal file
40
vendor/anourvalar/eloquent-serialize/tests/ConnectionTest.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace AnourValar\EloquentSerialize\Tests;
|
||||
|
||||
use AnourValar\EloquentSerialize\Tests\Models\User;
|
||||
|
||||
class ConnectionTest extends AbstractSuite
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testDefault()
|
||||
{
|
||||
$package = $this->service->serialize(User::where('id', '!=', 1));
|
||||
$package = json_encode($package);
|
||||
|
||||
$package = json_decode($package, true);
|
||||
$builder = $this->service->unserialize($package);
|
||||
|
||||
$this->assertEquals('testing', $builder->getQuery()->getConnection()->getName());
|
||||
$this->assertEquals('testing', $builder->first()->getConnectionName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSimple()
|
||||
{
|
||||
config(['database.connections.foo' => config('database.connections.testing')]);
|
||||
|
||||
$package = $this->service->serialize((new User())->setConnection('foo')->where('id', '!=', 1));
|
||||
$package = json_encode($package);
|
||||
|
||||
$package = json_decode($package, true);
|
||||
$builder = $this->service->unserialize($package);
|
||||
|
||||
$this->assertEquals('foo', $builder->getQuery()->getConnection()->getName());
|
||||
$this->assertEquals('foo', $builder->getModel()->getConnectionName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user