Skip to content

Commit

Permalink
tests: compatibility with Nette 3
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Apr 13, 2019
1 parent 5a95cd9 commit ffcd6ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions phpstan.tests.neon.dist
Expand Up @@ -23,3 +23,6 @@ parameters:
-
message: '#Call to an undefined method Nette\\Forms\\Form::addEmailAddress\(\)#' # false positive
path: %currentWorkingDirectory%/tests/Bridges/EmailAddressInputDI/EmailAddressInputExtensionTest.phpt
-
message: "#Call to function method_exists\\(\\) with 'Nette\\\\\\\\Forms\\\\\\\\Rules' and '.*' will always evaluate to (false|true)\\.#"
path: %currentWorkingDirectory%/tests/EmailAddressInput/EmailAddressInputTest.phpt
2 changes: 1 addition & 1 deletion src/EmailAddressInput/EmailAddressInput.php
Expand Up @@ -21,7 +21,7 @@ public function __construct($label = null, ?int $maxLength = null)
{
parent::__construct($label, $maxLength);
$this->setNullable();
$this->setRequired(false);
$this->setRequired(false); // BC with Nette 2.4
$this->addRule(Form::EMAIL);
}

Expand Down
22 changes: 19 additions & 3 deletions tests/EmailAddressInput/EmailAddressInputTest.phpt
Expand Up @@ -8,6 +8,7 @@ use Nepada\EmailAddress\InvalidEmailAddressException;
use Nepada\EmailAddressInput\EmailAddressInput;
use NepadaTests\TestCase;
use Nette\Forms\Form;
use Nette\Forms\Rules;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';
Expand All @@ -19,6 +20,15 @@ require_once __DIR__ . '/../bootstrap.php';
class EmailAddressInputTest extends TestCase
{

/** @var bool */
private $isNette24 = false;

protected function setUp(): void
{
parent::setUp();
$this->isNette24 = method_exists(Rules::class, 'isOptional') && method_exists(Rules::class, 'check'); // BC with Nette 2.4
}

public function testSetNullValue(): void
{
$input = new EmailAddressInput();
Expand Down Expand Up @@ -81,7 +91,9 @@ class EmailAddressInputTest extends TestCase
Assert::same(null, $emailAddressInput->getError());
Assert::same(
'<input type="email" name="email" id="frm-email" '
. 'data-nette-rules=\'[{"op":"optional"},{"op":":email","msg":"Please enter a valid email address."}]\'>',
. 'data-nette-rules=\'['
. ($this->isNette24 ? '{"op":"optional"},' : '')
. '{"op":":email","msg":"Please enter a valid email address."}]\'>',
(string) $emailAddressInput->getControl()
);
}
Expand All @@ -102,7 +114,9 @@ class EmailAddressInputTest extends TestCase
Assert::same(null, $emailAddressInput->getError());
Assert::same(
'<input type="email" name="email" id="frm-email" '
. 'data-nette-rules=\'[{"op":"optional"},{"op":":email","msg":"Please enter a valid email address."}]\' data-nette-empty-value="&#64;" value="&#64;">',
. 'data-nette-rules=\'['
. ($this->isNette24 ? '{"op":"optional"},' : '')
. '{"op":":email","msg":"Please enter a valid email address."}]\' data-nette-empty-value="&#64;" value="&#64;">',
(string) $emailAddressInput->getControl()
);
}
Expand All @@ -123,7 +137,9 @@ class EmailAddressInputTest extends TestCase
Assert::same(null, $emailAddressInput->getError());
Assert::same(
'<input type="email" name="email" id="frm-email" '
. 'data-nette-rules=\'[{"op":"optional"},{"op":":email","msg":"Please enter a valid email address."}]\' value="Example&#64;Example.com">',
. 'data-nette-rules=\'['
. ($this->isNette24 ? '{"op":"optional"},' : '')
. '{"op":":email","msg":"Please enter a valid email address."}]\' value="Example&#64;Example.com">',
(string) $emailAddressInput->getControl()
);
}
Expand Down

0 comments on commit ffcd6ed

Please sign in to comment.