-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
16 changed files
with
369 additions
and
5 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
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
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,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fab2s/dt0. | ||
* (c) Fabrice de Stefanis / https://github.com/fab2s/dt0 | ||
* This source file is licensed under the MIT license which you will | ||
* find in the LICENSE file or at https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace fab2s\Dt0\Exception; | ||
|
||
class AttributeException extends Dt0Exception | ||
{ | ||
} |
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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fab2s/dt0. | ||
* (c) Fabrice de Stefanis / https://github.com/fab2s/dt0 | ||
* This source file is licensed under the MIT license which you will | ||
* find in the LICENSE file or at https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace fab2s\Dt0\Tests\Artifacts; | ||
|
||
use fab2s\Dt0\Attribute\Rule; | ||
use fab2s\Dt0\Attribute\Rules; | ||
use fab2s\Dt0\Attribute\Validate; | ||
use fab2s\Dt0\Dt0; | ||
|
||
#[Validate( | ||
validator: NoOpValidator::class, | ||
rules: new Rules( | ||
fromValidate: new Rule('rule1'), | ||
), | ||
)] | ||
#[Rules( | ||
fromRules: new Rule('rule2'), | ||
)] | ||
class DummyValidatedDt0 extends Dt0 | ||
{ | ||
public readonly string $fromValidate; | ||
public readonly string $fromRules; | ||
|
||
#[Rule('rule3')] | ||
public readonly string $fromRule; | ||
} |
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,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fab2s/dt0. | ||
* (c) Fabrice de Stefanis / https://github.com/fab2s/dt0 | ||
* This source file is licensed under the MIT license which you will | ||
* find in the LICENSE file or at https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace fab2s\Dt0\Tests\Artifacts; | ||
|
||
use fab2s\Dt0\Attribute\Rule; | ||
use fab2s\Dt0\Validator\ValidatorInterface; | ||
|
||
class NoOpValidator implements ValidatorInterface | ||
{ | ||
public array $rules = []; | ||
|
||
public function validate(array $data): array | ||
{ | ||
return $data; | ||
} | ||
|
||
public function addRule(string $name, Rule $rule): static | ||
{ | ||
$this->rules[$name] = $rule; | ||
|
||
return $this; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fab2s/dt0. | ||
* (c) Fabrice de Stefanis / https://github.com/fab2s/dt0 | ||
* This source file is licensed under the MIT license which you will | ||
* find in the LICENSE file or at https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace fab2s\Dt0\Tests\Attribute; | ||
|
||
use fab2s\Dt0\Attribute\Cast; | ||
use fab2s\Dt0\Dt0; | ||
use fab2s\Dt0\Exception\AttributeException; | ||
use fab2s\Dt0\Tests\TestCase; | ||
|
||
class CastTest extends TestCase | ||
{ | ||
public function test_casts() | ||
{ | ||
$cast = new Cast; | ||
|
||
$this->assertNull($cast->in); | ||
$this->assertNull($cast->out); | ||
$this->assertSame(Dt0::DT0_NIL, $cast->default); | ||
$this->assertNull($cast->renameFrom); | ||
$this->assertNull($cast->renameTo); | ||
$this->assertNull($cast->propName); | ||
$this->assertFalse($cast->hasDefault); | ||
|
||
$this->expectException(AttributeException::class); | ||
new Cast(in: 'NotACaster'); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fab2s/dt0. | ||
* (c) Fabrice de Stefanis / https://github.com/fab2s/dt0 | ||
* This source file is licensed under the MIT license which you will | ||
* find in the LICENSE file or at https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace fab2s\Dt0\Tests\Attribute; | ||
|
||
use fab2s\Dt0\Attribute\Cast; | ||
use fab2s\Dt0\Attribute\Casts; | ||
use fab2s\Dt0\Tests\TestCase; | ||
use ReflectionClass; | ||
|
||
class CastsTest extends TestCase | ||
{ | ||
public function test_casts() | ||
{ | ||
$casts = new Casts( | ||
new Cast(propName: 'prop1'), | ||
new Cast(default: 'casted'), | ||
prop2: new Cast(default: 'casted'), | ||
); | ||
|
||
$reflexion = new ReflectionClass($casts); | ||
|
||
$this->assertTrue($casts->hasCast('prop1')); | ||
$this->assertTrue($casts->hasCast('prop2')); | ||
$this->assertCount(2, $reflexion->getProperty('casters')->getValue($casts)); | ||
} | ||
} |
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 | ||
|
||
/* | ||
* This file is part of fab2s/dt0. | ||
* (c) Fabrice de Stefanis / https://github.com/fab2s/dt0 | ||
* This source file is licensed under the MIT license which you will | ||
* find in the LICENSE file or at https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace fab2s\Dt0\Tests\Attribute; | ||
|
||
use fab2s\Dt0\Attribute\Rule; | ||
use fab2s\Dt0\Tests\TestCase; | ||
|
||
class RuleTest extends TestCase | ||
{ | ||
public function test_casts() | ||
{ | ||
$rule = new Rule('rule'); | ||
|
||
$this->assertSame('rule', $rule->rule); | ||
$this->assertNull($rule->propName); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fab2s/dt0. | ||
* (c) Fabrice de Stefanis / https://github.com/fab2s/dt0 | ||
* This source file is licensed under the MIT license which you will | ||
* find in the LICENSE file or at https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace fab2s\Dt0\Tests\Attribute; | ||
|
||
use fab2s\Dt0\Attribute\Rule; | ||
use fab2s\Dt0\Attribute\Rules; | ||
use fab2s\Dt0\Tests\TestCase; | ||
use ReflectionClass; | ||
|
||
class RulesTest extends TestCase | ||
{ | ||
public function test_casts() | ||
{ | ||
$rules = new Rules( | ||
new Rule(rule: 'rule', propName: 'prop1'), | ||
new Rule(rule: 'rule'), | ||
prop2: new Rule(rule: 'rule'), | ||
); | ||
|
||
$reflexion = new ReflectionClass($rules); | ||
|
||
$this->assertTrue($rules->hasRule('prop1')); | ||
$this->assertSame('rule', $rules->getRule('prop1')->rule); | ||
$this->assertTrue($rules->hasRule('prop2')); | ||
$this->assertSame('rule', $rules->getRule('prop2')->rule); | ||
|
||
$this->assertCount(2, $reflexion->getProperty('rules')->getValue($rules)); | ||
} | ||
} |
Oops, something went wrong.