Skip to content

Commit 6c2fdd6

Browse files
committed
change tests to use pest
1 parent cd4239f commit 6c2fdd6

34 files changed

+198
-3193
lines changed

.travis.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

codeception.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"php": ">=5.4.0"
2121
},
2222
"require-dev": {
23-
"codeception/codeception": "^2.1",
24-
"codeception/specify": "^0.4.3",
23+
"pestphp/pest": "^3.8",
2524
"rector/rector": "^2.0"
2625
},
2726
"autoload": {
@@ -38,5 +37,10 @@
3837
"Rut": "Freshwork\\ChileanBundle\\Facades\\Rut"
3938
}
4039
}
40+
},
41+
"config": {
42+
"allow-plugins": {
43+
"pestphp/pest-plugin": true
44+
}
4145
}
4246
}

phpunit.xml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
syntaxCheck="false"
126
>
137
<testsuites>
14-
<testsuite name="Package Test Suite">
15-
<directory suffix=".php">./tests/</directory>
8+
<testsuite name="Unit">
9+
<directory>./tests/Unit</directory>
1610
</testsuite>
1711
</testsuites>
12+
<source>
13+
<include>
14+
<directory>./src</directory>
15+
</include>
16+
</source>
17+
<php>
18+
19+
</php>
1820
</phpunit>

rector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
])
1212
// uncomment to reach your current PHP version
1313
->withPhpSets()
14-
->withTypeCoverageLevel(0)
15-
->withDeadCodeLevel(0)
16-
->withCodeQualityLevel(0);
14+
->withTypeCoverageLevel(9)
15+
->withDeadCodeLevel(9)
16+
->withCodeQualityLevel(9);

src/Rut.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ class Rut
5858
* The number part of the RUT. Example: 12.345.678-9 ($rut = 12345678)
5959
* @var integer
6060
*/
61-
protected $number = null;
61+
protected $number;
6262

6363
/**
6464
* Verification Number of the RUT
6565
* The verification number part of the RUT. Example: 12.345.678-9 ($vn = 9)
6666
* @var string
6767
*/
68-
protected $vn = null;
68+
protected $vn;
6969

7070
/**
7171
*
@@ -104,7 +104,7 @@ public function __construct($rut = null, $vn = null)
104104
*/
105105
public static function parse($rut)
106106
{
107-
list($rut, $vn) = self::split($rut);
107+
[$rut, $vn] = self::split($rut);
108108

109109
return (new self($rut, $vn));
110110
}
@@ -203,13 +203,16 @@ public function vnSeparator(?array $vnSeparator = null)
203203
public function isValid()
204204
{
205205
if (!$this->hasValidFormat()) {
206+
if ($this->useExceptions) {
207+
throw new InvalidFormatException("R.U.T. '{$this->number}' with verification code '{$this->vn}' has an invalid format");
208+
}
206209
return false;
207210
}
208211

209212
$vn_has_to_be = $this->calculateVerificationNumber();
210213
if ($this->vn == $vn_has_to_be) {
211214
return true;
212-
}
215+
};
213216

214217
return false;
215218
}
@@ -244,7 +247,7 @@ public function calculateVerificationNumber()
244247
$rut = $this->number;
245248
$s=1;
246249
for ($m=0; $rut != 0; $rut /= 10) {
247-
$s=((int)$s+(int)$rut % (int)10 * ((int)9-(int)$m++%(int)6))%(int)11;
250+
$s=($s+(int)$rut % 10 * (9-$m++%6))%11;
248251
}
249252
return chr($s?$s+47:75);
250253
}
@@ -346,12 +349,23 @@ public function format($format = self::FORMAT_COMPLETE)
346349
*/
347350
public function hasValidFormat()
348351
{
349-
$is_ok = (preg_match('/^[0-9]+$/', $this->number) && preg_match('/([K0-9])$/', $this->vn) && strlen($this->number) > $this->minChars && strlen($this->number) < $this->maxChars);
350-
if (!$is_ok && $this->useExceptions) {
351-
throw new InvalidFormatException("R.U.T. '{$this->number}' with verification code '{$this->vn}' has an invalid format");
352+
if (strlen($this->number) >= $this->maxChars) {
353+
return false;
354+
}
355+
356+
if (strlen($this->number) <= $this->minChars) {
357+
return false;
358+
}
359+
360+
if (!preg_match('/([K0-9])$/', $this->vn)) {
361+
return false;
362+
}
363+
364+
if (!preg_match('/^[0-9]+$/', $this->number)) {
365+
return false;
352366
}
353367

354-
return $is_ok;
368+
return true;
355369
}
356370

357371
/**

tests/Pest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Test Case
6+
|--------------------------------------------------------------------------
7+
|
8+
| The closure you provide to your test functions is always bound to a specific PHPUnit test
9+
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
10+
| need to change it using the "uses()" function to bind a different classes or traits.
11+
|
12+
*/
13+
14+
// uses(Tests\TestCase::class)->in('Feature');
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Expectations
19+
|--------------------------------------------------------------------------
20+
|
21+
| When you're writing tests, you often need to check that values meet certain conditions. The
22+
| "expect()" function gives you access to a set of "expectations" methods that you can use
23+
| to assert different things. Of course, you may extend the Expectation API at any time.
24+
|
25+
*/
26+
27+
expect()->extend('toBeValidRut', function () {
28+
return $this->toBeTruthy()
29+
->and($this->value->validate())->toBeTrue();
30+
});
31+
32+
/*
33+
|--------------------------------------------------------------------------
34+
| Functions
35+
|--------------------------------------------------------------------------
36+
|
37+
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
38+
| project that you don't want to repeat in every file. Here you can also expose helpers as
39+
| global functions to help you to reduce the number of lines of code in your test files.
40+
|
41+
*/
42+
43+
function createRut(string $rut)
44+
{
45+
return \Freshwork\ChileanBundle\Rut::parse($rut);
46+
}
47+
48+
function validRuts()
49+
{
50+
return ['11.111.111-1', '111111111', '11111112-K', '11111112-k'];
51+
}
52+
53+
function invalidRuts()
54+
{
55+
return ['11111112-9', '17601065fail-7', '123-1', '123.456.789-2', '11.111.111-L'];
56+
}

tests/_bootstrap.php

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/_data/dump.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/_output/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/_support/AcceptanceTester.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/_support/FunctionalTester.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/_support/Helper/Acceptance.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/_support/Helper/Acceptance.php~HEAD

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/_support/Helper/Acceptance.php~release_2.0

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/_support/Helper/Functional.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/_support/Helper/Functional.php~HEAD

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/_support/Helper/Functional.php~release_2.0

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/_support/Helper/Unit.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/_support/Helper/Unit.php~HEAD

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/_support/Helper/Unit.php~HEAD_0

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)