Commit 7bd92dbc authored by Ditty's avatar Ditty

Remove test and revert back old test

parent 31b0fdf0
<?php
declare(strict_types=1);
use Illuminate\Support\Carbon;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class DatabaseEloquentTimestampsTest extends TestCase
{
/**
* Tear down the database schema.
*
* @return void
*/
protected function tearDown(): void
{
$this->schema()->drop('users');
$this->schema()->drop('users_created_at');
$this->schema()->drop('users_updated_at');
}
/**
* Tests...
*/
public function testUserWithCreatedAtAndUpdatedAt()
{
$now = Carbon::now();
$user = UserWithCreatedAndUpdated::create([
'email' => 'test@test.com',
]);
$this->assertEquals($now->toDateTimeString(), $user->created_at->toDateTimeString());
$this->assertEquals($now->toDateTimeString(), $user->updated_at->toDateTimeString());
}
public function testUserWithCreatedAt()
{
$now = Carbon::now();
$user = UserWithCreated::create([
'email' => 'test@test.com',
]);
$this->assertEquals($now->toDateTimeString(), $user->created_at->toDateTimeString());
}
public function testUserWithUpdatedAt()
{
$now = Carbon::now();
$user = UserWithUpdated::create([
'email' => 'test@test.com',
]);
$this->assertEquals($now->toDateTimeString(), $user->updated_at->toDateTimeString());
}
/**
* Get a database connection instance.
*
* @return \Illuminate\Database\ConnectionInterface
*/
protected function connection()
{
return Eloquent::getConnectionResolver()->connection();
}
/**
* Get a schema builder instance.
*
* @return \Illuminate\Database\Schema\Builder
*/
protected function schema()
{
return $this->connection()->getSchemaBuilder();
}
}
/**
* Eloquent Models...
*/
class UserWithCreatedAndUpdated extends Eloquent
{
protected $collection = 'users';
protected $guarded = [];
}
class UserWithCreated extends Eloquent
{
public const UPDATED_AT = null;
protected $collection = 'users_created_at';
protected $guarded = [];
protected $dateFormat = 'U';
}
class UserWithUpdated extends Eloquent
{
public const CREATED_AT = null;
protected $collection = 'users_updated_at';
protected $guarded = [];
protected $dateFormat = 'U';
}
...@@ -405,6 +405,12 @@ class ModelTest extends TestCase ...@@ -405,6 +405,12 @@ class ModelTest extends TestCase
->getTimestamp(), $item->created_at->getTimestamp()); ->getTimestamp(), $item->created_at->getTimestamp());
$this->assertLessThan(2, abs(time() - $item->created_at->getTimestamp())); $this->assertLessThan(2, abs(time() - $item->created_at->getTimestamp()));
// test default date format for json output
/** @var Item $item */
$item = Item::create(['name' => 'sword']);
$json = $item->toArray();
$this->assertEquals($item->created_at->format('Y-m-d\TH:i:s.u\Z'), $json['created_at']);
/** @var User $user */ /** @var User $user */
$user = User::create(['name' => 'Jane Doe', 'birthday' => time()]); $user = User::create(['name' => 'Jane Doe', 'birthday' => time()]);
$this->assertInstanceOf(Carbon::class, $user->birthday); $this->assertInstanceOf(Carbon::class, $user->birthday);
......
...@@ -67,9 +67,4 @@ class User extends Eloquent implements AuthenticatableContract, CanResetPassword ...@@ -67,9 +67,4 @@ class User extends Eloquent implements AuthenticatableContract, CanResetPassword
{ {
return $this->morphMany('Photo', 'imageable'); return $this->morphMany('Photo', 'imageable');
} }
public function getDateFormat()
{
return 'l jS \of F Y h:i:s A';
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment