Skip to content

Commit

Permalink
tests: added test for extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 7, 2018
1 parent 6be22db commit 119b9ad
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/Forms/BaseControl.extensionMethod.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Nette\Forms\Controls\Button;
use Nette\Forms\Controls\Checkbox;
use Nette\Forms\Controls\TextBase;
use Nette\Forms\Controls\TextInput;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


TextBase::extensionMethod('test', function ($control, $a, $b) {
Assert::type(TextInput::class, $control);
Assert::same(1, $a);
Assert::same(2, $b);
return 'TextInput';
});

Checkbox::extensionMethod('test', function ($control, $a, $b) {
Assert::type(Checkbox::class, $control);
Assert::same(1, $a);
Assert::same(2, $b);
return 'Checkbox';
});

$control1 = new TextInput;
Assert::same('TextInput', $control1->test(1, 2));

$control2 = new Checkbox;
Assert::same('Checkbox', $control2->test(1, 2));

Assert::exception(function () {
$control3 = new Button;
$control3->test(1, 2);
}, Nette\MemberAccessException::class);
18 changes: 18 additions & 0 deletions tests/Forms/Container.extensionMethod.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Nette\Forms\Form;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


Nette\Forms\Container::extensionMethod('test', function ($form, $a, $b) {
Assert::type(Nette\Forms\Form::class, $form);
Assert::same(1, $a);
Assert::same(2, $b);
return 3;
});

$form = new Form;
Assert::same(3, $form->test(1, 2));

0 comments on commit 119b9ad

Please sign in to comment.