mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Add a BaseTest class to reset static properties on setUp and tearDown
This commit is contained in:
parent
d3dfa81996
commit
611f264885
@ -12,7 +12,7 @@
|
|||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Valitron Test Suite">
|
<testsuite name="Valitron Test Suite">
|
||||||
<directory suffix=".php">tests/Valitron</directory>
|
<directory suffix="Test.php">tests/Valitron</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
24
tests/Valitron/BaseTestCase.php
Normal file
24
tests/Valitron/BaseTestCase.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class BaseTestCase extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
$this->resetProperty('_lang');
|
||||||
|
$this->resetProperty('_langDir');
|
||||||
|
$this->resetProperty('_ruleMessages', array());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function resetProperty($name, $value = null)
|
||||||
|
{
|
||||||
|
$prop = new ReflectionProperty('Valitron\Validator', $name);
|
||||||
|
$prop->setAccessible(true);
|
||||||
|
$prop->setValue($value);
|
||||||
|
$prop->setAccessible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
class ErrorMessagesTest extends \PHPUnit_Framework_TestCase
|
class ErrorMessagesTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testErrorMessageIncludesFieldName()
|
public function testErrorMessageIncludesFieldName()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,23 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
class StaticLangTest extends \PHPUnit_Framework_TestCase
|
class StaticLangTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
$this->resetProperty('_lang');
|
|
||||||
$this->resetProperty('_langDir');
|
|
||||||
$this->resetProperty('_ruleMessages', array());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function resetProperty($name, $value = null)
|
|
||||||
{
|
|
||||||
$prop = new ReflectionProperty('Valitron\Validator', $name);
|
|
||||||
$prop->setAccessible(true);
|
|
||||||
$prop->setValue($value);
|
|
||||||
$prop->setAccessible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getLangDir()
|
protected function getLangDir()
|
||||||
{
|
{
|
||||||
return __DIR__.'/../../lang';
|
return __DIR__.'/../../lang';
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
class ValidateTest extends \PHPUnit_Framework_TestCase
|
class ValidateTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testValidWithNoRules()
|
public function testValidWithNoRules()
|
||||||
{
|
{
|
||||||
@ -16,3 +16,4 @@ if($vendorPos !== false) {
|
|||||||
$loader = require __DIR__.'/../vendor/autoload.php';
|
$loader = require __DIR__.'/../vendor/autoload.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require_once __DIR__ . '/Valitron/BaseTestCase.php';
|
||||||
Loading…
x
Reference in New Issue
Block a user