Skip to content

Commit

Permalink
refactored naming for string length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kasitmp committed Mar 2, 2017
1 parent e5440d8 commit 6c75f16
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 46 deletions.
45 changes: 25 additions & 20 deletions src/StringParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace MPScholten\RequestParser;

use MPScholten\RequestParser\Validator\EmailParser;
use MPScholten\RequestParser\Validator\StringBetweenParser;
use MPScholten\RequestParser\Validator\StringLargerThanOrEqualToParser;
use MPScholten\RequestParser\Validator\StringLargerThanParser;
use MPScholten\RequestParser\Validator\StringSmallerThanOrEqualToParser;
use MPScholten\RequestParser\Validator\StringSmallerThanParser;
use MPScholten\RequestParser\Validator\StringLengthBetween;
use MPScholten\RequestParser\Validator\StringLengthLargerThanOrEqualToParser;
use MPScholten\RequestParser\Validator\StringLengthLargerThanParser;
use MPScholten\RequestParser\Validator\StringLengthSmallerThanOrEqualToParser;
use MPScholten\RequestParser\Validator\StringLengthSmallerThanParser;
use MPScholten\RequestParser\Validator\UrlParser;

class StringParser extends AbstractValueParser
Expand Down Expand Up @@ -83,46 +83,51 @@ public function rightTrim()
/**
* @param int $minValue
* @param int $maxValue
* @return StringBetweenParser
*
* @return StringLengthBetween
*/
public function between($minValue, $maxValue)
public function lengthBetween($minValue, $maxValue)
{
return new StringBetweenParser($this->config, $this->name, $this->value, $minValue, $maxValue);
return new StringLengthBetween($this->config, $this->name, $this->value, $minValue, $maxValue);
}

/**
* @param int $minValue
* @return StringLargerThanParser
*
* @return StringLengthLargerThanParser
*/
public function largerThan($minValue)
public function lengthLargerThan($minValue)
{
return new StringLargerThanParser($this->config, $this->name, $this->value, $minValue);
return new StringLengthLargerThanParser($this->config, $this->name, $this->value, $minValue);
}

/**
* @param int $minValue
* @return StringLargerThanOrEqualToParser
*
* @return StringLengthLargerThanOrEqualToParser
*/
public function largerThanOrEqualTo($minValue)
public function lengthLargerThanOrEqualTo($minValue)
{
return new StringLargerThanOrEqualToParser($this->config, $this->name, $this->value, $minValue);
return new StringLengthLargerThanOrEqualToParser($this->config, $this->name, $this->value, $minValue);
}

/**
* @param int $maxValue
* @return StringSmallerThanParser
*
* @return StringLengthSmallerThanParser
*/
public function smallerThan($maxValue)
public function lengthSmallerThan($maxValue)
{
return new StringSmallerThanParser($this->config, $this->name, $this->value, $maxValue);
return new StringLengthSmallerThanParser($this->config, $this->name, $this->value, $maxValue);
}

/**
* @param int $maxValue
* @return StringSmallerThanOrEqualToParser
*
* @return StringLengthSmallerThanOrEqualToParser
*/
public function smallerThanOrEqualTo($maxValue)
public function lengthSmallerThanOrEqualTo($maxValue)
{
return new StringSmallerThanOrEqualToParser($this->config, $this->name, $this->value, $maxValue);
return new StringLengthSmallerThanOrEqualToParser($this->config, $this->name, $this->value, $maxValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MPScholten\RequestParser\Validator;

class StringBetweenParser extends AbstractBetweenParser
class StringLengthBetween extends AbstractBetweenParser
{
protected function describe()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MPScholten\RequestParser\Validator;

class StringLargerThanOrEqualToParser extends AbstractLargerThanOrEqualToParser
class StringLengthLargerThanOrEqualToParser extends AbstractLargerThanOrEqualToParser
{
protected function describe()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MPScholten\RequestParser\Validator;

class StringLargerThanParser extends AbstractLargerThanParser
class StringLengthLargerThanParser extends AbstractLargerThanParser
{
protected function describe()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MPScholten\RequestParser\Validator;

class StringSmallerThanOrEqualToParser extends AbstractSmallerThanOrEqualToParser
class StringLengthSmallerThanOrEqualToParser extends AbstractSmallerThanOrEqualToParser
{
protected function describe()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MPScholten\RequestParser\Validator;

class StringSmallerThanParser extends AbstractSmallerThanParser
class StringLengthSmallerThanParser extends AbstractSmallerThanParser
{
protected function describe()
{
Expand Down
22 changes: 11 additions & 11 deletions tests/ParserSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ public function testBetweenValidatorWithValidValues()
$this->assertEquals(101.12, $parser->required());

$parser = new StringParser(new Config(), 'name', '');
$parser->between(0, 1);
$parser->lengthBetween(0, 1);
$this->assertEquals('', $parser->required());
$parser = new StringParser(new Config(), 'groupId', 'A');
$parser->between(0, 1);
$parser->lengthBetween(0, 1);
$this->assertEquals('A', $parser->required());
}

Expand All @@ -192,11 +192,11 @@ public function testLargerThanValidatorWithValidValues()
$this->assertEquals(1.01, $parser->required());

$parser = new StringParser(new Config(), 'name', 'A');
$parser->largerThan(0);
$parser->lengthLargerThan(0);
$this->assertEquals('A', $parser->required());

$parser = new StringParser(new Config(), 'groupId', 'A');
$parser->largerThanOrEqualTo(1);
$parser->lengthLargerThanOrEqualTo(1);
$this->assertEquals('A', $parser->required());
}

Expand All @@ -219,11 +219,11 @@ public function testSmallerThanValidatorWithValidValues()
$this->assertEquals(-2.01, $parser->required());

$parser = new StringParser(new Config(), 'groupId', 'A');
$parser->smallerThan(2);
$parser->lengthSmallerThan(2);
$this->assertEquals('A', $parser->required());

$parser = new StringParser(new Config(), 'groupId', 'A');
$parser->largerThanOrEqualTo(1);
$parser->lengthLargerThanOrEqualTo(1);
$this->assertEquals('A', $parser->required());
}

Expand All @@ -245,7 +245,7 @@ public function testStringBetweenValidatorWithValuesOutOfRange()
{
$this->setExpectedException(InvalidValueException::class, 'Invalid value for parameter "name". Expected a string with character length between 0 and 1, but got "AB"');
$parser = new StringParser(new Config(), 'name', 'AB');
$parser->between(0, 1)->required();
$parser->lengthBetween(0, 1)->required();
}

public function testIntLargerThanValidatorWithValuesOutOfRange()
Expand Down Expand Up @@ -280,14 +280,14 @@ public function testStringLargerThanValidatorWithValuesOutOfRange()
{
$this->setExpectedException(InvalidValueException::class, 'Invalid value for parameter "name". Expected a string longer than 0 characters, but got ""');
$parser = new StringParser(new Config(), 'name', '');
$parser->largerThan(0)->required();
$parser->lengthLargerThan(0)->required();
}

public function testStringLargerThanOrEqualToValidatorWithValuesOutOfRange()
{
$this->setExpectedException(InvalidValueException::class, 'Invalid value for parameter "name". Expected a string longer than or equal to 2 characters, but got "A"');
$parser = new StringParser(new Config(), 'name', 'A');
$parser->largerThanOrEqualTo(2)->required();
$parser->lengthLargerThanOrEqualTo(2)->required();
}

public function testIntSmallerThanValidatorWithValuesOutOfRange()
Expand Down Expand Up @@ -322,13 +322,13 @@ public function testStringSmallerThanValidatorWithValuesOutOfRange()
{
$this->setExpectedException(InvalidValueException::class, 'Invalid value for parameter "name". Expected a string shorter than 1 characters, but got "A"');
$parser = new StringParser(new Config(), 'name', 'A');
$parser->smallerThan(1)->required();
$parser->lengthSmallerThan(1)->required();
}

public function testStringSmallerThanOrEqualToValidatorWithValuesOutOfRange()
{
$this->setExpectedException(InvalidValueException::class, 'Invalid value for parameter "name". Expected a string shorter than or equal to 1 characters, but got "AB"');
$parser = new StringParser(new Config(), 'name', 'AB');
$parser->smallerThanOrEqualTo(1)->required();
$parser->lengthSmallerThanOrEqualTo(1)->required();
}
}
20 changes: 10 additions & 10 deletions tests/TypeSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
use MPScholten\RequestParser\FloatParser;
use MPScholten\RequestParser\TrimParser;
use MPScholten\RequestParser\Validator\IntLargerThanOrEqualToParser;
use MPScholten\RequestParser\Validator\StringBetweenParser;
use MPScholten\RequestParser\Validator\StringLargerThanOrEqualToParser;
use MPScholten\RequestParser\Validator\StringLargerThanParser;
use MPScholten\RequestParser\Validator\StringSmallerThanOrEqualToParser;
use MPScholten\RequestParser\Validator\StringSmallerThanParser;
use MPScholten\RequestParser\Validator\StringLengthBetween;
use MPScholten\RequestParser\Validator\StringLengthLargerThanOrEqualToParser;
use MPScholten\RequestParser\Validator\StringLengthLargerThanParser;
use MPScholten\RequestParser\Validator\StringLengthSmallerThanOrEqualToParser;
use MPScholten\RequestParser\Validator\StringLengthSmallerThanParser;
use MPScholten\RequestParser\Validator\UrlParser;
use MPScholten\RequestParser\Validator\FloatLargerThanOrEqualToParser;
use MPScholten\RequestParser\Validator\FloatLargerThanParser;
Expand Down Expand Up @@ -224,30 +224,30 @@ public function testCommaSeparatedBoolean()
public function testStringBetween()
{
$spec = new TypeParser(new Config(), 'groupId', 'A');
$this->assertInstanceOf(StringBetweenParser::class, $spec->string()->between(0, 1));
$this->assertInstanceOf(StringLengthBetween::class, $spec->string()->lengthBetween(0, 1));
}

public function testStringLargerThan()
{
$spec = new TypeParser(new Config(), 'groupId', 'A');
$this->assertInstanceOf(StringLargerThanParser::class, $spec->string()->largerThan(0));
$this->assertInstanceOf(StringLengthLargerThanParser::class, $spec->string()->lengthLargerThan(0));
}

public function testStringLargerThanOrEqualTo()
{
$spec = new TypeParser(new Config(), 'groupId', 'A');
$this->assertInstanceOf(StringLargerThanOrEqualToParser::class, $spec->string()->largerThanOrEqualTo(1));
$this->assertInstanceOf(StringLengthLargerThanOrEqualToParser::class, $spec->string()->lengthLargerThanOrEqualTo(1));
}

public function testStringSmallerThan()
{
$spec = new TypeParser(new Config(), 'groupId', 'A');
$this->assertInstanceOf(StringSmallerThanParser::class, $spec->string()->smallerThan(2));
$this->assertInstanceOf(StringLengthSmallerThanParser::class, $spec->string()->lengthSmallerThan(2));
}

public function testStringSmallerThanOrEqualTo()
{
$spec = new TypeParser(new Config(), 'groupId', 'A');
$this->assertInstanceOf(StringSmallerThanOrEqualToParser::class, $spec->string()->smallerThanOrEqualTo(1));
$this->assertInstanceOf(StringLengthSmallerThanOrEqualToParser::class, $spec->string()->lengthSmallerThanOrEqualTo(1));
}
}

0 comments on commit 6c75f16

Please sign in to comment.