/** * 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(); }
/** * 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'); }
/** * 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'")); }