-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d916138
commit 3b787be
Showing
4 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
# Changelog | ||
|
||
All notable changes to `laravel-mixins` will be documented in this file | ||
All notable changes to `laravel-mixins` will be documented in this file. | ||
|
||
## 1.0.0 - 2020-08-xx | ||
## 2.1.0 - 2020-10-13 | ||
|
||
- Initial release | ||
- Added `InKeys` rule. | ||
|
||
## 2.0.0 - 2020-10-05 | ||
|
||
- [ConvertsBase64ToFiles] Renamed `base64ImageKeys` to `base64FileKeys`. | ||
|
||
## 1.0.0 - 2020-09-22 | ||
|
||
- Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace ProtoneMedia\LaravelMixins\Rules; | ||
|
||
use Illuminate\Validation\Rules\In; | ||
|
||
class InKeys extends In | ||
{ | ||
/** | ||
* Create a new rule instance with the keys of the given values. | ||
* | ||
* @param array $values | ||
* @return void | ||
*/ | ||
public function __construct(array $values) | ||
{ | ||
$this->values = array_keys($values); | ||
} | ||
|
||
public static function make(array $values): self | ||
{ | ||
return new static($values); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace ProtoneMedia\Mixins\Tests\Rules; | ||
|
||
use Illuminate\Support\Facades\Validator; | ||
use Orchestra\Testbench\TestCase; | ||
use ProtoneMedia\LaravelMixins\Rules\InKeys; | ||
|
||
class InKeysTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_validates_the_keys() | ||
{ | ||
$rule = InKeys::make([ | ||
'a' => 'foo', | ||
'b' => 'bar', | ||
'c' => 'baz', | ||
]); | ||
|
||
$validator = Validator::make([], ['attribute' => $rule]); | ||
|
||
$this->assertTrue($validator->setData(['attribute' => 'a'])->passes()); | ||
$this->assertFalse($validator->setData(['attribute' => 'd'])->passes()); | ||
$this->assertFalse($validator->setData(['attribute' => 'foo'])->passes()); | ||
} | ||
} |