/** * Assert that defined JSON attributes are properly parsed and exposed * through mutators. */ public function testHintedJsonColumns() { // Mock the model with data $mock = new MockJsonDialectModel(); $mock->hintJsonStructure('testColumn', json_encode(['foo' => null])); // Execute the hint call $mock->addHintedAttributes(); // Assert that the column were properly parsed and various bits have // been set on the model $this->assertTrue($mock->hasGetMutator('foo')); $this->assertContains('foo', $mock->getMutatedAttributes()); $this->assertContains('testColumn', $mock->getHidden()); $this->assertNull($mock->foo); // Set a value for foo $mock->foo = 'bar'; // assert that the column has been set properly $this->assertEquals($mock->foo, 'bar'); $this->assertEquals($mock->testColumn, json_encode(['foo' => 'bar'])); }
/** * Test the ability to allow models to provide their own custom attribute * getters for json attributes */ public function testCustomGetter() { // Mock the model with data $mock = new MockJsonDialectModel(); $mock->hintJsonStructure('foo', json_encode(['custom_get' => null])); // Execute the hint call $mock->addHintedAttributes(); // Assert that the column were properly parsed and various bits have // been set on the model $this->assertTrue($mock->hasGetMutator('custom_get')); $this->assertEquals($mock->custom_get, 'custom getter result'); }
/** * Assert that attributes with JSON operators are properly recognized as JSON attributes */ public function testGetMutator() { // Mock the model with data $mock = new MockJsonDialectModel(); $this->assertTrue($mock->hasGetMutator("testColumn->>'foo'")); }