Skip to content

Commit

Permalink
Test enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Nov 16, 2018
1 parent 61ed77b commit 6adedfa
Show file tree
Hide file tree
Showing 52 changed files with 216 additions and 84 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

before_script:
- composer self-update
- composer install --dev
- composer install

script: phpunit --coverage-text
script: phpunit --coverage-text
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
"Rakit\\Validation\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Rakit\\Validation\\Tests\\": "tests"
}
},
"require": {
"php": ">=5.5.0",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "4.*"
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5"
}
}
}
19 changes: 14 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
<phpunit bootstrap="vendor/autoload.php">
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Block">
<testsuite name="Validation test suites">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
4 changes: 2 additions & 2 deletions src/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function setMessage($message)
{
$this->message = $message;
return $this;
}
}

public function getMessage()
{
Expand All @@ -109,4 +109,4 @@ protected function requireParameters(array $params)
}
}

}
}
2 changes: 1 addition & 1 deletion src/Rules/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Defaults extends Rule
public function check($value)
{
$this->requireParameters($this->fillable_params);

$default = $this->parameter('default');
return $default;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function check($value)
if (! is_string($value) || empty($value)) {
return false;
}

json_decode($value);

if (json_last_error() !== JSON_ERROR_NONE) {
Expand All @@ -24,4 +24,4 @@ public function check($value)
return true;
}

}
}
2 changes: 1 addition & 1 deletion src/Rules/Min.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Min extends Rule
public function check($value)
{
$this->requireParameters($this->fillable_params);

$min = (int) $this->parameter('min');
if (is_int($value)) {
return $value >= $min;
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RequiredIf.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function check($value)

if (in_array($anotherValue, $definedValues)) {
$this->setAttributeAsRequired();
return $required_validator->check($value, []);
return $required_validator->check($value, []);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RequiredUnless.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function check($value)

if (!in_array($anotherValue, $definedValues)) {
$this->setAttributeAsRequired();
return $required_validator->check($value, []);
return $required_validator->check($value, []);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RequiredWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function check($value)
foreach($fields as $field) {
if ($this->validation->hasValue($field)) {
$this->setAttributeAsRequired();
return $required_validator->check($value, []);
return $required_validator->check($value, []);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RequiredWithAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function check($value)
}

$this->setAttributeAsRequired();
return $required_validator->check($value, []);
return $required_validator->check($value, []);
}

}
2 changes: 1 addition & 1 deletion src/Rules/RequiredWithout.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function check($value)
foreach($fields as $field) {
if (!$this->validation->hasValue($field)) {
$this->setAttributeAsRequired();
return $required_validator->check($value, []);
return $required_validator->check($value, []);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RequiredWithoutAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function check($value)
}

$this->setAttributeAsRequired();
return $required_validator->check($value, []);
return $required_validator->check($value, []);
}

}
2 changes: 1 addition & 1 deletion src/Rules/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function fileTypes($types)
}

public function check($value)
{
{
$minSize = $this->parameter('min_size');
$maxSize = $this->parameter('max_size');
$allowedTypes = $this->parameter('allowed_types');
Expand Down
2 changes: 1 addition & 1 deletion src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function validate(array $inputs, array $rules, array $messages = array())
public function make(array $inputs, array $rules, array $messages = array())
{
$messages = array_merge($this->messages, $messages);
return new Validation($this, $inputs, $rules, $messages);
return new Validation($this, $inputs, $rules, $messages);
}

public function __invoke($rule)
Expand Down
13 changes: 8 additions & 5 deletions tests/ErrorBagTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Rakit\Validation\Tests;

use Rakit\Validation\ErrorBag;
use PHPUnit\Framework\TestCase;

class ErrorBagTest extends PHPUnit_Framework_TestCase
class ErrorBagTest extends TestCase
{

public function testCount()
Expand Down Expand Up @@ -117,15 +120,15 @@ public function testGet()
'email' => '1',
'unique' => '2',
],

'items.0.id_product' => [
'numeric' => '3',
'etc' => 'x'
],
'items.0.qty' => [
'numeric' => 'a'
],

'items.1.id_product' => [
'numeric' => '4',
'etc' => 'y'
Expand Down Expand Up @@ -227,7 +230,7 @@ public function testAll()
$this->assertEquals($errors->all('prefix :message suffix'), [
'prefix 1 suffix',
'prefix 2 suffix',

'prefix 3 suffix',
'prefix x suffix',
'prefix a suffix',
Expand Down Expand Up @@ -263,7 +266,7 @@ public function testFirstOfAll()

$this->assertEquals($errors->firstOfAll('prefix :message suffix'), [
'prefix 1 suffix',

'prefix 3 suffix',
'prefix a suffix',

Expand Down
5 changes: 4 additions & 1 deletion tests/Fixtures/Even.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

namespace Rakit\Validation\Tests;

class Even extends \Rakit\Validation\Rule
use Rakit\Validation\Rule;

class Even extends Rule
{

protected $message = "The :attribute must be even";
Expand Down
5 changes: 4 additions & 1 deletion tests/Fixtures/Required.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

namespace Rakit\Validation\Tests;

class Required extends \Rakit\Validation\Rule
use Rakit\Validation\Rule;

class Required extends Rule
{

public function check($value)
Expand Down
5 changes: 4 additions & 1 deletion tests/HelperTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Rakit\Validation\Tests;

use Rakit\Validation\Helper;
use PHPUnit\Framework\TestCase;

class HelperTest extends PHPUnit_Framework_TestCase
class HelperTest extends TestCase
{

public function testArrayHas()
Expand Down
5 changes: 4 additions & 1 deletion tests/Rules/AcceptedTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Rakit\Validation\Tests;

use Rakit\Validation\Rules\Accepted;
use PHPUnit\Framework\TestCase;

class AcceptedTest extends PHPUnit_Framework_TestCase
class AcceptedTest extends TestCase
{

public function setUp()
Expand Down
9 changes: 7 additions & 2 deletions tests/Rules/AfterTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php

namespace Rakit\Validation\Tests;

class AfterTest extends PHPUnit_Framework_TestCase
use Rakit\Validation\Rules\After;
use PHPUnit\Framework\TestCase;
use DateTime;

class AfterTest extends TestCase
{

/**
Expand All @@ -11,7 +16,7 @@ class AfterTest extends PHPUnit_Framework_TestCase

public function setUp()
{
$this->validator = new \Rakit\Validation\Rules\After();
$this->validator = new After();
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/Rules/AlphaDashTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Rakit\Validation\Tests;

use Rakit\Validation\Rules\AlphaDash;
use PHPUnit\Framework\TestCase;

class AlphaDashTest extends PHPUnit_Framework_TestCase
class AlphaDashTest extends TestCase
{

public function setUp()
Expand Down
5 changes: 4 additions & 1 deletion tests/Rules/AlphaNumTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Rakit\Validation\Tests;

use Rakit\Validation\Rules\AlphaNum;
use PHPUnit\Framework\TestCase;

class AlphaNumTest extends PHPUnit_Framework_TestCase
class AlphaNumTest extends TestCase
{

public function setUp()
Expand Down
6 changes: 5 additions & 1 deletion tests/Rules/AlphaTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

namespace Rakit\Validation\Tests;

use Rakit\Validation\Rules\Alpha;
use PHPUnit\Framework\TestCase;
use stdClass;

class AlphaTest extends PHPUnit_Framework_TestCase
class AlphaTest extends TestCase
{

public function setUp()
Expand Down
9 changes: 7 additions & 2 deletions tests/Rules/BeforeTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php

namespace Rakit\Validation\Tests;

class BeforeTest extends PHPUnit_Framework_TestCase
use Rakit\Validation\Rules\Before;
use PHPUnit\Framework\TestCase;
use DateTime;

class BeforeTest extends TestCase
{

/**
Expand All @@ -11,7 +16,7 @@ class BeforeTest extends PHPUnit_Framework_TestCase

public function setUp()
{
$this->validator = new \Rakit\Validation\Rules\Before();
$this->validator = new Before();
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/Rules/BetweenTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Rakit\Validation\Tests;

use Rakit\Validation\Rules\Between;
use PHPUnit\Framework\TestCase;

class BetweenTest extends PHPUnit_Framework_TestCase
class BetweenTest extends TestCase
{

public function setUp()
Expand Down
5 changes: 4 additions & 1 deletion tests/Rules/CallbackTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Rakit\Validation\Tests;

use Rakit\Validation\Rules\Callback;
use PHPUnit\Framework\TestCase;

class CallbackTest extends PHPUnit_Framework_TestCase
class CallbackTest extends TestCase
{

public function setUp()
Expand Down
Loading

0 comments on commit 6adedfa

Please sign in to comment.