Inheritance: extends Illuminate\Database\Eloquent\Model, use trait Eloquent\Dialect\Json
Example #1
0
 /**
  * Assert that an exception is thrown when given invalid json as a
  * structure hint
  *
  * @expectedException Eloquent\Dialect\InvalidJsonException
  */
 public function testInvalidHint()
 {
     // Mock the model with data
     $mock = new MockJsonDialectModel();
     $mock->hintJsonStructure('testColumn', '{');
     // Execute the hint call
     $mock->addHintedAttributes();
 }
Example #2
0
 /**
  * Test the ability to allow models to provide their own custom attribute
  * getters for json attributes
  */
 public function testCustomSetter()
 {
     // Mock the model with data
     $mock = new MockJsonDialectModel();
     $mock->hintJsonStructure('foo', json_encode(['custom_set' => 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->hasSetMutator('custom_set'));
     // Set a value
     $mock->custom_set = 'value';
     // Assert that the attribute was mutated by the mutator on our mock
     // model
     $this->assertEquals($mock->custom_set, 'custom value');
 }
Example #3
0
 /**
  * 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'"));
 }