Skip to content

Commit

Permalink
Add method for adding multiple fields at once.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 15, 2014
1 parent 94fedf0 commit a108fe2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Form/Schema.php
Expand Up @@ -37,6 +37,19 @@ class Schema {
'required' => false,
];

/**
* Add multiple fields to the schema.
*
* @param array $fields The fields to add.
* @return $this
*/
public function addFields(array $fields) {
foreach ($fields as $name => $attrs) {
$this->addField($name, $attrs);
}
return $this;
}

/**
* Adds a field to the schema.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/Form/SchemaTest.php
Expand Up @@ -22,6 +22,22 @@
*/
class SchemaTest extends TestCase {

/**
* Test adding multiple fields.
*
* @return void
*/
public function testAddingMultipleFields() {
$schema = new Schema();
$schema->addFields([
'email' => 'string',
'body' => ['type' => 'string', 'length' => 1000]
]);
$this->assertEquals(['email', 'body'], $schema->fields());
$this->assertEquals('string', $schema->field('email')['type']);
$this->assertEquals('string', $schema->field('body')['type']);
}

/**
* test adding fields.
*
Expand Down

0 comments on commit a108fe2

Please sign in to comment.