Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsenhc committed Jul 9, 2022
2 parents 69470c8 + 7acf319 commit 0b4bbed
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none
tools: composer:v2

- name: Setup problem matchers
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The package will automatically register itself.

### Translations

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

```bash
php artisan vendor:publish --provider="Wilsenhc\RifValidation\RifValidationServiceProvider"
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 7 additions & 2 deletions src/RifValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
namespace Wilsenhc\RifValidation;

use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Rule;
use Wilsenhc\RifValidation\Rules\Rif;

class RifValidationServiceProvider extends ServiceProvider
{
public function boot()
{
$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/validateRif'),
__DIR__.'/../lang' => $this->app->langPath().'/vendor/validateRif',
]);

$this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'validateRif');
$this->loadTranslationsFrom(__DIR__.'/../lang/', 'validateRif');

// Register custom validation rule
$this->app['validator']->extend('rif', Rif::class . '@passes');
}
}
51 changes: 51 additions & 0 deletions tests/Rules/RifTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class RifTest extends TestCase
*/
protected $rule;

/**
* @var \Illuminate\Validation\Factory $validator
*/
protected $validator;

/**
* Setup the test environment.
*/
Expand All @@ -22,6 +27,8 @@ protected function setUp(): void
parent::setUp();

$this->rule = new Rif();

$this->validator = $this->app['validator'];
}

protected function getPackageProviders($app)
Expand Down Expand Up @@ -92,4 +99,48 @@ public function it_will_convert_values_to_uppercase_before_testing()

$this->assertTrue($this->rule->passes('rif', $rif));
}

/** @test */
public function it_will_validate_using_class()
{
// Valid RIF of "Universidad de Carabobo"
$this->assertTrue($this->validator->make(
['rif' => 'G-20000041-4'],
['rif' => new Rif],
)->passes());

// Valid RIF of "Banesco Banco Universal"
$this->assertTrue($this->validator->make(
['rif' => 'J-07013380-5'],
['rif' => new Rif],
)->passes());

// Valid RIF of "Nicolas Maduro Moros"
$this->assertTrue($this->validator->make(
['rif' => 'V-05892464-0'],
['rif' => new Rif],
)->passes());
}

/** @test */
public function it_will_validate_using_shortname()
{
// Valid RIF of "Universidad de Carabobo"
$this->assertTrue($this->validator->make(
['rif' => 'G-20000041-4'],
['rif' => 'rif'],
)->passes());

// Valid RIF of "Banesco Banco Universal"
$this->assertTrue($this->validator->make(
['rif' => 'J-07013380-5'],
['rif' => 'rif'],
)->passes());

// Valid RIF of "Nicolas Maduro Moros"
$this->assertTrue($this->validator->make(
['rif' => 'V-05892464-0'],
['rif' => 'rif'],
)->passes());
}
}

0 comments on commit 0b4bbed

Please sign in to comment.