Skip to content
Permalink
Browse files

Add __debugInfo() methods to more objects.

Many of these objects can contain Closures, and I'd like to improve how
they are printed in DebugKit. This feels like the best way to improve
developer experience around these objects without making the solution
too specific to DebugKit.

Refs #6504
  • Loading branch information...
markstory committed May 10, 2015
1 parent aff1b8b commit dcc936601e174ca729162f33f9c1f7b508dfad73
@@ -188,4 +188,19 @@ protected function _execute(array $data)
{
return true;
}
/**
* Get the printable version of a Form instance.
*
* @return array
*/
public function __debugInfo()
{
$special = [
'_schema' => $this->schema()->__debugInfo(),
'_errors' => $this->errors(),
'_validator' => $this->validator()->__debugInfo()
];
return $special + get_object_vars($this);
}
}
@@ -121,4 +121,16 @@ public function fieldType($name)
}
return $field['type'];
}
/**
* Get the printable version of this object
*
* @return array
*/
public function __debugInfo()
{
return [
'_fields' => $this->_fields
];
}
}
@@ -580,4 +580,28 @@ protected function _processRules($field, ValidationSet $rules, $data, $newRecord
}
return $errors;
}
/**
* Get the printable version of this object.
*
* @return array
*/
public function __debugInfo()
{
$fields = [];
foreach ($this->_fields as $name => $fieldSet) {
$fields[$name] = [
'isPresenceRequired' => $fieldSet->isPresenceRequired(),
'isEmptyAllowed' => $fieldSet->isEmptyAllowed(),
'rules' => array_keys($fieldSet->rules()),
];
}
return [
'_presenceMessages' => $this->_presenceMessages,
'_allowEmptyMessages' => $this->_allowEmptyMessages,
'_useI18n' => $this->_useI18n,
'_providers' => array_keys($this->_providers),
'_fields' => $fields
];
}
}
@@ -154,4 +154,18 @@ public function testExecuteValid()
$this->assertTrue($form->execute($data));
}
/**
* test __debugInfo
*
* @return void
*/
public function testDebugInfo()
{
$form = new Form();
$result = $form->__debugInfo();
$this->assertArrayHasKey('_schema', $result);
$this->assertArrayHasKey('_errors', $result);
$this->assertArrayHasKey('_validator', $result);
}
}
@@ -116,4 +116,28 @@ public function testFieldType()
$this->assertEquals('decimal', $schema->fieldType('numbery'));
$this->assertNull($schema->fieldType('nope'));
}
/**
* test __debugInfo
*
* @return void
*/
public function testDebugInfo()
{
$schema = new Schema();
$schema->addField('name', 'string')
->addField('numbery', [
'type' => 'decimal',
'required' => true
]);
$result = $schema->__debugInfo();
$expected = [
'_fields' => [
'name' => ['type' => 'string', 'length' => null, 'precision' => null],
'numbery' => ['type' => 'decimal', 'length' => null, 'precision' => null],
],
];
$this->assertEquals($expected, $result);
}
}
@@ -769,4 +769,44 @@ public function testCompareWithIntegration()
];
$this->assertNotEmpty($validator->errors($data), 'Validation should fail.');
}
/**
* Test debugInfo helper method.
*
* @return void
*/
public function testDebugInfo()
{
$validator = new Validator();
$validator->provider('test', $this);
$validator->add('title', 'not-empty', ['rule' => 'notEmpty']);
$validator->requirePresence('body');
$validator->allowEmpty('published');
$result = $validator->__debugInfo();
$expected = [
'_providers' => ['test'],
'_fields' => [
'title' => [
'isPresenceRequired' => false,
'isEmptyAllowed' => false,
'rules' => ['not-empty'],
],
'body' => [
'isPresenceRequired' => true,
'isEmptyAllowed' => false,
'rules' => [],
],
'published' => [
'isPresenceRequired' => false,
'isEmptyAllowed' => true,
'rules' => [],
],
],
'_presenceMessages' => [],
'_allowEmptyMessages' => [],
'_useI18n' => true,
];
$this->assertEquals($expected, $result);
}
}

0 comments on commit dcc9366

Please sign in to comment.
You can’t perform that action at this time.