There is a screencast explaining how extend the form builder and test it using phpspec (you can of course also use phpunit).
Mar 10, 2015
5
Level 88
How to test custom FormBuilder
Hi guys,
So I created a custom FormBuilder based on the FormBuilder from the Collective package: http://laravelcollective.com/docs/5.0/html
The FormBuilder will only return html so I was thinking about a unit test. Then I can compare the output on correctness.
So I have a function like this:
<?php namespace App\Services\Html;
class FormBuilder extends \Collective\Html\FormBuilder {
public function destroy($value = null, $options = [])
{
$options['class'] = 'btn btn-cons btn-danger ' . (isset($options['class']) ? $options['class'] : '');
return parent::submit($value, $options);
}
}
What is the best approache on testing this? If you need anything please let me know!
Many thanks :D
Level 2
Can you write unit tests like a Base Class? https://github.com/LaravelCollective/html/blob/5.0/tests/FormBuilderTest.php
Please or to participate in this conversation.