Пример #1
0
 /**
  * Assert that defined JSON attributes are properly parsed and exposed through mutators.
  */
 public function testInspectJsonColumns()
 {
     // Mock the model with data
     $mock = new MockJsonDialectModel();
     $mock->setJsonColumns(['testColumn']);
     $mock->setAttribute('testColumn', json_encode(['foo' => 'bar']));
     // Execute the insepect call
     $mock->inspectJsonColumns();
     // 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->assertEquals($mock->foo, 'bar');
 }
Пример #2
0
 /**
  * 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('bar', $mock->foo);
     $this->assertEquals($mock->testColumn, json_encode(['foo' => 'bar']));
 }