/** * Assert that JSON attributes can be set through mutators */ public function testSetAttribute() { // Mock the model with data $mock = new MockJsonDialectModel(); $mock->setJsonColumns(['testColumn']); $mock->setAttribute('testColumn', json_encode(['foo' => 'bar'])); // Execute the insepect call $mock->inspectJsonColumns(); $mock->foo = 'baz'; $mock->setJsonAttribute('testColumn', 'fizz', 'buzz'); // Assert that the column were properly parsed and various bits have // been set on the model $this->assertEquals($mock->foo, 'baz'); $this->assertEquals($mock->fizz, 'buzz'); }
/** * Assert that defined JSON attributes are returned in the getDirty() * response when expected. */ public function testGetDirtyJson() { // Mock the model with data $mock = new MockJsonDialectModel(); $mock->hintJsonStructure('testColumn', json_encode(['foo' => null])); // At this point 'foo' should not be dirty $this->assertArrayNotHasKey('foo', $mock->getDirty(true)); $mock->setAttribute('testColumn', json_encode(['foo' => 'bar'])); // Now that 'foo' has been changed it should show up in the getDirty() // response $this->assertArrayHasKey('foo', $mock->getDirty(true)); }