Skip to content

Commit

Permalink
Merge pull request #9 from koriym/construct
Browse files Browse the repository at this point in the history
base form class empty constructor
  • Loading branch information
koriym committed Sep 10, 2015
2 parents eef26a3 + 2b1c48b commit b15c888
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 28 deletions.
1 change: 0 additions & 1 deletion docs/demo/1.csrf/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
echo 'Anti CSRF DOES NOT works !' . PHP_EOL;
//$works = $controller->response['body'] == 'create bear';
//echo ($works ? 'It works!' : 'It DOES NOT work!') . PHP_EOL;

24 changes: 12 additions & 12 deletions src/AbstractAuraForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,37 @@
abstract class AbstractAuraForm extends Form implements FormInterface
{
/**
* @\Ray\Di\Di\Inject
*
* @param BuilderInterface $builder An object to build input objects.
* @param FilterInterface $filter A filter object for this fieldset.
* @param object $options An arbitrary options object for use when setting
* up inputs and filters.
* @\Ray\Di\Di\Inject
*/
public function parentConstruct(
public function setBaseDependencies(
BuilderInterface $builder,
FilterInterface $filter,
HelperLocatorFactory $factory,
$options = null
) {
$this->builder = $builder;
$this->filter = $filter;
$this->options = $options;
$this->helper = $factory->newInstance();
}

public function __construct()
{
}

/**
* @PostConstruct
* @\Ray\Di\Di\PostConstruct
*/
public function postConstruct()
{
$this->init();
if ($this->antiCsrf instanceof AntiCsrfInterface) {
$this->setAntiCsrf($this->antiCsrf);
}
}

/**
Expand All @@ -55,14 +63,6 @@ public function postConstruct()
*/
protected $string = '<form></form>';

/**
* @Inject
*/
public function setFormHelper(HelperLocatorFactory $factory)
{
$this->helper = $factory->newInstance();
}

/**
* @param AntiCsrfInterface $antiCsrf
*/
Expand Down
17 changes: 11 additions & 6 deletions src/AbstractForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
use Aura\Input\AntiCsrfInterface;
use Aura\Input\Builder;
use Aura\Input\BuilderInterface;
use Aura\Input\Filter;
use Aura\Input\FilterInterface;
use Aura\Input\Form;
use Ray\Di\Di\Inject;
use Ray\Di\Di\PostConstruct;

abstract class AbstractForm extends Form implements FormInterface
{
Expand All @@ -35,8 +31,10 @@ abstract class AbstractForm extends Form implements FormInterface
* @param BuilderInterface $builder
* @param FilterFactory $filterFactory
* @param HelperLocatorFactory $helperFactory
*
* @\Ray\Di\Di\Inject
*/
public function __construct(
public function setBaseDependencies(
BuilderInterface $builder = null,
FilterFactory $filterFactory = null,
HelperLocatorFactory $helperFactory = null
Expand All @@ -46,12 +44,19 @@ public function __construct(
$this->helper = $helperFactory ? $helperFactory->newInstance() : (new HelperLocatorFactory)->newInstance();
}

public function __construct()
{
}

/**
* @PostConstruct
* @\Ray\Di\Di\PostConstruct
*/
public function postConstruct()
{
$this->init();
if ($this->antiCsrf instanceof AntiCsrfInterface) {
$this->setAntiCsrf($this->antiCsrf);
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/SetAntiCsrfTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@

trait SetAntiCsrfTrait
{
/**
* @var AntiCsrfInterface
*/
protected $antiCsrf;

/**
* @param AntiCsrfInterface $antiCsrf
*
* @\Ray\Di\Di\Inject
*/
public function injectAntiCsrf(AntiCsrfInterface $antiCsrf)
{
$this->setAntiCsrf($antiCsrf);
$this->antiCsrf = $antiCsrf;
}
}
5 changes: 3 additions & 2 deletions tests/AbstractAuraFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class AbstractAuraFormTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
parent::setUp();
$this->form = new FakeForm(new Builder, new Filter);
$this->form->setFormHelper(new HelperLocatorFactory);
$this->form = new FakeForm;
$this->form->setBaseDependencies(new Builder, new Filter, new HelperLocatorFactory);
$this->form->postConstruct();
}

public function testForm()
Expand Down
3 changes: 2 additions & 1 deletion tests/AbstractFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class AbstractFormTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
parent::setUp();
$this->form = new FakeNameForm(new Builder, new FilterFactory, new HelperLocatorFactory);
$this->form = new FakeNameForm;
$this->form->setBaseDependencies(new Builder, new FilterFactory, new HelperLocatorFactory);
}

public function testSubmit()
Expand Down
18 changes: 15 additions & 3 deletions tests/AuraInputInterceptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,25 @@ public function getMethodInvocation($method, array $submit, FailureHandlerInterf
public function getController(array $submit)
{
$controller = new FakeController;
$fakeForm = new FakeForm(new Builder, new Filter);
$fakeForm = $this->getFakeForm();
$fakeForm->setSubmit($submit);
$fakeForm->setFormHelper(new HelperLocatorFactory);
$controller->setForm($fakeForm);

return $controller;
}

/**
* @return FakeForm
*/
private function getFakeForm()
{
$fakeForm = new FakeForm;
$fakeForm->setBaseDependencies(new Builder, new Filter, new HelperLocatorFactory);
$fakeForm->postConstruct();

return $fakeForm;
}

public function proceed($controller)
{
$invocation = new ReflectiveMethodInvocation(
Expand Down Expand Up @@ -103,7 +114,8 @@ public function testInvalidFormPropertyException()
{
$this->setExpectedException(InvalidOnFailureMethod::class);
$controller = new FakeInvalidController3;
$controller->setForm(new FakeForm(new Builder, new Filter));
$fakeForm = $this->getFakeForm();
$controller->setForm($fakeForm);
$this->proceed($controller);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/AuraInputModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setUp()

public function testAuraInputModule()
{
$injector = new Injector(new FakeModule);
$injector = new Injector(new FakeModule, __DIR__ . '/tmp');
$controller = $injector->getInstance(FakeController::class);
$this->assertInstanceOf(WeavedInterface::class, $controller);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/VndErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class VndErrorHandlerTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
parent::setUp();
$this->controller = (new Injector(new FakeVndErrorModule))->getInstance(FakeController::class);
$this->controller = (new Injector(new FakeVndErrorModule, __DIR__ . '/tmp'))->getInstance(FakeController::class);
}

public function testValidationException()
Expand Down

0 comments on commit b15c888

Please sign in to comment.