Check "bcmath" extension before executing tests

Although BCMath is necessary to execute "Ip" and "Iban" rules, we not
required that in the "composer.json" file. That's because if someone
wants to use the library, but doesn't want to use those rules, they
would not need to install that extension.

However, when executing the tests, they will break. This commit will
verify whether the extension exists to test "Ip" and "Iban" rules.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2020-10-04 11:07:18 +02:00
parent e0c6f33c01
commit ed304f3406
No known key found for this signature in database
GPG key ID: 221E9281655813A6
4 changed files with 40 additions and 0 deletions

View file

@ -35,6 +35,12 @@ try {
echo $exception->getFullMessage() . PHP_EOL;
}
?>
--SKIPIF--
<?php
if (!extension_loaded('bcmath')) {
echo 'skip: Extension "bcmath" is required to execute this test';
}
?>
--EXPECT--
"SE35 5000 5880 7742" must be a valid IBAN
"GB82 WEST 1234 5698 7654 32" must not be a valid IBAN

View file

@ -60,6 +60,12 @@ try {
echo $exception->getFullMessage() . PHP_EOL;
}
?>
--SKIPIF--
<?php
if (!extension_loaded('bcmath')) {
echo 'skip: Extension "bcmath" is required to execute this test';
}
?>
--EXPECT--
"257.0.0.1" must be an IP address
"127.0.0.1" must not be an IP address

View file

@ -16,6 +16,8 @@ namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
use function extension_loaded;
/**
* @group rule
*
@ -68,4 +70,16 @@ final class IbanTest extends RuleTestCase
'GermanydWrong' => [$sut, 'DE89 5000 5880 7742'],
];
}
/**
* {@inheritDoc}
*/
protected function setUp(): void
{
if (extension_loaded('bcmath')) {
return;
}
$this->markTestSkipped('You need bcmath to execute this test');
}
}

View file

@ -16,6 +16,8 @@ namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Test\RuleTestCase;
use function extension_loaded;
use const FILTER_FLAG_IPV6;
use const FILTER_FLAG_NO_PRIV_RANGE;
@ -113,4 +115,16 @@ final class IpTest extends RuleTestCase
new Ip($range);
}
/**
* {@inheritDoc}
*/
protected function setUp(): void
{
if (extension_loaded('bcmath')) {
return;
}
$this->markTestSkipped('You need bcmath to execute this test');
}
}