2016-06-25 21:12:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Glmdev\Meta\Tests;
|
|
|
|
|
|
|
|
use Glmdev\Meta\Meta;
|
2016-06-25 22:10:21 +00:00
|
|
|
use Ramsey\Uuid\Uuid;
|
2016-06-25 21:12:01 +00:00
|
|
|
|
|
|
|
class MetaTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-06-25 22:10:21 +00:00
|
|
|
public function testReadWrite ()
|
|
|
|
{
|
|
|
|
$model = Meta::create();
|
|
|
|
|
|
|
|
$model->write('name', 'John');
|
|
|
|
$model->write('age', 15);
|
2016-06-26 01:32:09 +00:00
|
|
|
$model->write('true', false);
|
|
|
|
|
|
|
|
$model->write([
|
|
|
|
'food' => 'taco',
|
|
|
|
'old' => 'spice',
|
|
|
|
'new' => 1935
|
|
|
|
]);
|
2016-06-25 22:10:21 +00:00
|
|
|
|
|
|
|
$this->assertEquals('John', $model->read('name'));
|
|
|
|
$this->assertEquals(15, $model->read('age'));
|
2016-06-26 01:32:09 +00:00
|
|
|
$this->assertEquals(false, $model->read('true'));
|
|
|
|
|
|
|
|
$this->assertEquals('taco', $model->read('food'));
|
|
|
|
$this->assertEquals('spice', $model->read('old'));
|
|
|
|
$this->assertEquals(1935, $model->read('new'));
|
2016-06-25 22:10:21 +00:00
|
|
|
}
|
2016-06-25 21:12:01 +00:00
|
|
|
|
2016-06-25 22:10:21 +00:00
|
|
|
public function testUuid ()
|
2016-06-25 21:12:01 +00:00
|
|
|
{
|
2016-06-25 22:10:21 +00:00
|
|
|
$model = Meta::create();
|
|
|
|
$uuid = Uuid::uuid4();
|
|
|
|
|
|
|
|
$this->assertTrue($model->hasUuid());
|
|
|
|
|
|
|
|
$model->setRawUuid($uuid);
|
|
|
|
$this->assertEquals($uuid, $model->getUuid());
|
2016-06-25 21:12:01 +00:00
|
|
|
}
|
2016-06-26 01:00:13 +00:00
|
|
|
|
|
|
|
public function testUuidQuery ()
|
|
|
|
{
|
|
|
|
$model = Meta::create([
|
2016-06-26 01:12:17 +00:00
|
|
|
'meta' => ['name' => 'Tony']
|
2016-06-26 01:00:13 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$queried = Meta::withUuid($model->getUuid())->first();
|
|
|
|
|
|
|
|
$this->assertEquals($model->read('name'), $queried->read('name'));
|
|
|
|
}
|
2016-06-25 21:12:01 +00:00
|
|
|
}
|