Skip to content

Commit

Permalink
#72 WIP HasMetasTest
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitriBouteille committed Sep 28, 2024
1 parent 05de571 commit aae16e3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/WordPress/Concerns/HasMetasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Dbout\WpOrm\Tests\WordPress\Concerns;

use Carbon\Carbon;
use Dbout\WpOrm\Concerns\HasMetas;
use Dbout\WpOrm\Enums\YesNo;
use Dbout\WpOrm\Models\Meta\AbstractMeta;
Expand Down Expand Up @@ -143,6 +144,36 @@ public function testGetMetaValueWithEnumCasts(): void
$this->assertEquals('yes', $value->value);
}

/**
* @return void
* @covers HasMetas::getMetaValue
*/
public function testGetMetaValueWithDatetimeCasts(): void
{
$object = new class () extends Post {
protected array $metaCasts = [
'created_at' => 'datetime',
'uploaded_at' => 'date',
];
};

$model = new $object();
$model->setPostTitle('Hello world');
$model->save();
$model->setMeta('created_at', '2022-09-08 07:30:05');
$model->setMeta('uploaded_at', '2024-10-08 10:25:35');

/** @var Carbon|null $date */
$date = $model->getMetaValue('created_at');
$this->assertInstanceOf(Carbon::class, $date);
$this->assertEquals('2022-09-08 07:30:05', $date->format('Y-m-d H:i:s'));

/** @var Carbon|null $date */
$date = $model->getMetaValue('uploaded_at');
$this->assertInstanceOf(Carbon::class, $date);
$this->assertEquals('2022-09-08 00:00:00', $date->format('Y-m-d H:i:s'));
}

/**
* @return void
* @covers HasMetas::deleteMeta
Expand Down

0 comments on commit aae16e3

Please sign in to comment.