Skip to content

Commit 0b4bbed

Browse files
committed
Merge branch 'dev' into main
2 parents 69470c8 + 7acf319 commit 0b4bbed

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
php-version: ${{ matrix.php }}
4747
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
4848
coverage: none
49+
tools: composer:v2
4950

5051
- name: Setup problem matchers
5152
run: |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The package will automatically register itself.
2020

2121
### Translations
2222

23-
If you wish to edit the package translations, you can run the following command to publish them into your `resources/lang` folder
23+
If you wish to edit the package translations, you can run the following command to publish them into your `lang/` folder
2424

2525
```bash
2626
php artisan vendor:publish --provider="Wilsenhc\RifValidation\RifValidationServiceProvider"
File renamed without changes.
File renamed without changes.

src/RifValidationServiceProvider.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
namespace Wilsenhc\RifValidation;
44

55
use Illuminate\Support\ServiceProvider;
6+
use Illuminate\Validation\Rule;
7+
use Wilsenhc\RifValidation\Rules\Rif;
68

79
class RifValidationServiceProvider extends ServiceProvider
810
{
911
public function boot()
1012
{
1113
$this->publishes([
12-
__DIR__.'/../resources/lang' => resource_path('lang/vendor/validateRif'),
14+
__DIR__.'/../lang' => $this->app->langPath().'/vendor/validateRif',
1315
]);
1416

15-
$this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'validateRif');
17+
$this->loadTranslationsFrom(__DIR__.'/../lang/', 'validateRif');
18+
19+
// Register custom validation rule
20+
$this->app['validator']->extend('rif', Rif::class . '@passes');
1621
}
1722
}

tests/Rules/RifTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class RifTest extends TestCase
1414
*/
1515
protected $rule;
1616

17+
/**
18+
* @var \Illuminate\Validation\Factory $validator
19+
*/
20+
protected $validator;
21+
1722
/**
1823
* Setup the test environment.
1924
*/
@@ -22,6 +27,8 @@ protected function setUp(): void
2227
parent::setUp();
2328

2429
$this->rule = new Rif();
30+
31+
$this->validator = $this->app['validator'];
2532
}
2633

2734
protected function getPackageProviders($app)
@@ -92,4 +99,48 @@ public function it_will_convert_values_to_uppercase_before_testing()
9299

93100
$this->assertTrue($this->rule->passes('rif', $rif));
94101
}
102+
103+
/** @test */
104+
public function it_will_validate_using_class()
105+
{
106+
// Valid RIF of "Universidad de Carabobo"
107+
$this->assertTrue($this->validator->make(
108+
['rif' => 'G-20000041-4'],
109+
['rif' => new Rif],
110+
)->passes());
111+
112+
// Valid RIF of "Banesco Banco Universal"
113+
$this->assertTrue($this->validator->make(
114+
['rif' => 'J-07013380-5'],
115+
['rif' => new Rif],
116+
)->passes());
117+
118+
// Valid RIF of "Nicolas Maduro Moros"
119+
$this->assertTrue($this->validator->make(
120+
['rif' => 'V-05892464-0'],
121+
['rif' => new Rif],
122+
)->passes());
123+
}
124+
125+
/** @test */
126+
public function it_will_validate_using_shortname()
127+
{
128+
// Valid RIF of "Universidad de Carabobo"
129+
$this->assertTrue($this->validator->make(
130+
['rif' => 'G-20000041-4'],
131+
['rif' => 'rif'],
132+
)->passes());
133+
134+
// Valid RIF of "Banesco Banco Universal"
135+
$this->assertTrue($this->validator->make(
136+
['rif' => 'J-07013380-5'],
137+
['rif' => 'rif'],
138+
)->passes());
139+
140+
// Valid RIF of "Nicolas Maduro Moros"
141+
$this->assertTrue($this->validator->make(
142+
['rif' => 'V-05892464-0'],
143+
['rif' => 'rif'],
144+
)->passes());
145+
}
95146
}

0 commit comments

Comments
 (0)