Skip to content

Commit 57ee19b

Browse files
committed
Update README.md; Update ValidatorTest
1 parent 6c977c8 commit 57ee19b

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ if ($valid) {
231231
* `ipv4` Validate that value is IPv4
232232
* `ipv6` Validate that value is IPv6
233233
* `date`, `datetime` Validate that value is date/datetime
234+
* `resource` Validate that value is a resource
235+
* `stream` Validate that value is a stream
236+
* `dir`, `directory` Validate that value is a directory
237+
* `file` Validate that value is a file
234238

235239
**Hint:** Adding `[]` to any type (e.g. `int[]`) will validate an array of values.
236240

tests/ValidatorTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
class ValidatorTest extends \PHPUnit_Framework_TestCase
55
{
6+
protected $dir;
7+
protected $file;
68
protected $resource;
79
protected $nullValues;
810
protected $booleanValues;
@@ -30,6 +32,8 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
3032
protected function setUp()
3133
{
3234
// Create resource/stream
35+
$this->dir = __DIR__ . '/fixtures';
36+
$this->file = $this->dir . '/resource.txt';
3337
$this->resource = fopen(__DIR__ . '/fixtures/resource.txt', 'r');
3438

3539
// Set values for each data type
@@ -741,6 +745,43 @@ public function testValidateDateTime()
741745
}
742746
}
743747

748+
/**
749+
* @covers Validator::validateResource
750+
*/
751+
public function testValidateResource()
752+
{
753+
$this->assertTrue(Validator::isResource($this->resource));
754+
$this->assertTrue(Validator::isResource($this->resource, ['resource_type' => 'stream']));
755+
}
756+
757+
/**
758+
* @covers Validator::validateStream
759+
*/
760+
public function testValidateStream()
761+
{
762+
$this->assertTrue(Validator::isStream($this->resource));
763+
}
764+
765+
/**
766+
* @covers Validator::validateDir
767+
*/
768+
public function testValidateDir()
769+
{
770+
$this->assertTrue(Validator::isDir($this->dir));
771+
$this->assertTrue(Validator::isDir($this->dir, ['is_writable' => true]));
772+
$this->assertFalse(Validator::isDir($this->dir, ['is_writable' => false]));
773+
}
774+
775+
/**
776+
* @covers Validator::validateFile
777+
*/
778+
public function testValidateFile()
779+
{
780+
$this->assertTrue(Validator::isFile($this->file));
781+
$this->assertTrue(Validator::isFile($this->file, ['is_writable' => true]));
782+
$this->assertFalse(Validator::isFile($this->file, ['is_writable' => false]));
783+
}
784+
744785
/**
745786
* Test 'required' setting for rules.
746787
*/

0 commit comments

Comments
 (0)