Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: php

php:
- 7.0
- 7.1
- 7.2
- 5.6

before_script:
- composer install --no-interaction

script:
- php vendor/bin/phpunit
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
}
],
"require": {
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "4.1.4"
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5"
},
"autoload": {
"psr-4": {
"Psecio\\Validation\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Psecio\\Validation\\": "tests/"
}
}
}
5 changes: 5 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
4 changes: 3 additions & 1 deletion tests/Check/AfterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class AfterTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class AfterTest extends TestCase
{
protected $after;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/AlphaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class AlphaTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class AlphaTest extends TestCase
{
protected $alpha;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/AlphanumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class AlphanumTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class AlphanumTest extends TestCase
{
protected $alphanum;

Expand Down
8 changes: 5 additions & 3 deletions tests/Check/Before.php → tests/Check/BeforeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class BeforeTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class BeforeTest extends TestCase
{
protected $before;

Expand All @@ -20,8 +22,8 @@ public function testCheckValidAfterDate()
$start = '+2 days';
$end = 'yesterday';

$this->after->setAdditional(['start' => $start]);
$this->assertTrue($this->after->execute($end));
$this->before->setAdditional(['start' => $start]);
$this->assertTrue($this->before->execute($end));
}

}
4 changes: 3 additions & 1 deletion tests/Check/BooleanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class BooleanTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class BooleanTest extends TestCase
{
protected $boolean;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class DateTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class DateTest extends TestCase
{
protected $date;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class EmailTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class EmailTest extends TestCase
{
protected $email;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/InTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class InTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class InTest extends TestCase
{
protected $in;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/IntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class IntegerTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class IntegerTest extends TestCase
{
protected $int;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/IpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class IpTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class IpTest extends TestCase
{
protected $ip;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/IsarrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class IsarrayTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class IsarrayTest extends TestCase
{
protected $array;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class JsonTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class JsonTest extends TestCase
{
protected $json;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/LengthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class LengthTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class LengthTest extends TestCase
{
protected $length;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/NumericTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class NumericTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class NumericTest extends TestCase
{
protected $num;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/RegexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class RegexTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class RegexTest extends TestCase
{
protected $regex;

Expand Down
4 changes: 3 additions & 1 deletion tests/Check/RequiredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation\Check;

class RequiredTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class RequiredTest extends TestCase
{
protected $req;

Expand Down
19 changes: 18 additions & 1 deletion tests/CheckSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation;

class CheckSetTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class CheckSetTest extends TestCase
{
/**
* Test the looping of the set via a foreach
Expand Down Expand Up @@ -39,4 +41,19 @@ public function testArrayAccessValid()
unset($set[2]);
$this->assertFalse(isset($set[2]));
}

/**
* Test that the check set can remove the specific index
*/
public function testRemove()
{
$checks = [
new \Psecio\Validation\Check\Integer('test1'),
new \Psecio\Validation\Check\Numeric('test2')
];
$set = new CheckSet($checks);
$set->remove(0);

$this->assertFalse(isset($set[0]));
}
}
54 changes: 53 additions & 1 deletion tests/CheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Psecio\Validation;

class CheckTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class CheckTest extends TestCase
{
/**
* Test setting the additional info on construct
Expand Down Expand Up @@ -53,4 +55,54 @@ public function testGetAdditionalByNameInvalid()
$check = $this->getMockForAbstractClass('\Psecio\Validation\Check', [$addl]);
$this->assertNull($check->get('wrongkey'));
}

/**
* Test that can get the input
*/
public function testGetInput()
{
$addl = [
'foo' => 'bar'
];
$check = $this->getMockForAbstractClass('\Psecio\Validation\Check', [$addl]);
$check->setInput('input_value');
$this->assertEquals('input_value', $check->getInput());
}

/**
* Test that can get the key
*/
public function testGetKey()
{
$addl = [
'foo' => 'bar'
];
$check = $this->getMockForAbstractClass('\Psecio\Validation\Check', [$addl]);
$check->setKey('key');
$this->assertEquals('key', $check->getKey());
}

/**
* Test that can get the type
*/
public function testGetType()
{
$addl = [
'foo' => 'bar'
];
$check = $this->getMockForAbstractClass('\Psecio\Validation\Check', [$addl]);
$this->assertStringStartsWith('mock_', $check->getType());
}

/**
* Test that can get the message if name is null
*/
public function testGetMessage()
{
$addl = [
'foo' => 'bar'
];
$check = $this->getMockForAbstractClass('\Psecio\Validation\Check', [$addl]);
$this->assertEquals('', $check->getMessage());
}
}
31 changes: 29 additions & 2 deletions tests/RuleTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

namespace Psecio\Validation;
use Psecio\Validation\CheckSet;

class RuleTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class RuleTest extends TestCase
{
protected $rule;

Expand Down Expand Up @@ -110,4 +111,30 @@ public function testParseCheckMappingValid()
$this->assertEquals(1, count($result));
$this->assertInstanceOf('\Psecio\Validation\Check\Isarray', $result[0]);
}

public function testGetMessages()
{
$checks = 'array';
$result = $this->rule->parse($checks);

$this->assertEquals([], $this->rule->getMessages());
}

public function testGetMessage()
{
$checks = 'array';
$result = $this->rule->parse($checks);
$this->rule->setMessages(['message']);

$this->assertEquals('message', $this->rule->getMessage(0));
$this->assertNull($this->rule->getMessage(1));
}

public function testGetFailures()
{
$checks = 'array';
$result = $this->rule->parse($checks);

$this->assertEquals([], $this->rule->getFailures(true));
}
}