Skip to content

Commit

Permalink
Merge branch 'release/0.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
c0ntax committed Feb 14, 2018
2 parents 4313f5a + 9768bd1 commit 4b1665c
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ There may be occassions where you want the bridge between Symfony and Parsley en
);
```

There is also the ``RemoveParsleyConstraint()`` class that can be used to remove specific Parsley constrains. This is handy if you want to remove something that was auto-generated from a Symfony Constraint.
There is also the ``RemoveParsleyDirective()`` class that can be used to remove specific Parsley constrains. This is handy if you want to remove something that was auto-generated from a Symfony Constraint.

## Rolling your own

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "c0ntax/parsley-bundle",
"version": "0.6.0",
"version": "0.6.1",
"type": "symfony-bundle",
"description": "A bridge between Symfony and Parsley.js",
"license": "Apache-2.0",
Expand Down
10 changes: 6 additions & 4 deletions src/Form/Extension/ParsleyTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
use C0ntax\ParsleyBundle\Contracts\ParsleyInterface;
use C0ntax\ParsleyBundle\Contracts\RemoveInterface;
use C0ntax\ParsleyBundle\Factory\ConstraintFactory;
use C0ntax\ParsleyBundle\Parsleys\AbstractRemove;
use C0ntax\ParsleyBundle\Parsleys\Directive\Field\Trigger;
use C0ntax\ParsleyBundle\Parsleys\RemoveParsleyConstraint;
use C0ntax\ParsleyBundle\Parsleys\RemoveParsleyDirective;
use C0ntax\ParsleyBundle\Parsleys\RemoveSymfonyConstraint;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;
Expand Down Expand Up @@ -71,7 +73,7 @@ public function buildView(FormView $view, FormInterface $form, array $options):
$this->createParsleyConstraintsFromValidationConstraints($symfonyConstraints, $form),
$this->getDirectivesFromParsleys($parsleys)
),
$this->getRemoveParsleyConstraintsFromParsleys($parsleys)
$this->getRemoveParsleyDirectivesFromParsleys($parsleys)
);

$this->addParsleyToView($view, $parsleyConstraints);
Expand Down Expand Up @@ -121,15 +123,15 @@ function (ParsleyInterface $parsley) {

/**
* @param ParsleyInterface[] $parsleys
* @return RemoveParsleyConstraint[]
* @return AbstractRemove[]
*/
private function getRemoveParsleyConstraintsFromParsleys(array $parsleys): array
private function getRemoveParsleyDirectivesFromParsleys(array $parsleys): array
{
return array_values(
array_filter(
$parsleys,
function (ParsleyInterface $parsley) {
return $parsley instanceof RemoveParsleyConstraint;
return $parsley instanceof RemoveParsleyDirective || $parsley instanceof RemoveParsleyConstraint;
}
)
);
Expand Down
1 change: 1 addition & 0 deletions src/Parsleys/RemoveParsleyConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Used to remove Parsley Directives after they've been put in
*
* @package C0ntax\ParsleyBundle\Parsleys
* @deprecated Use RemoveParsleyDirective instead
*/
class RemoveParsleyConstraint extends AbstractRemove
{
Expand Down
27 changes: 27 additions & 0 deletions src/Parsleys/RemoveParsleyDirective.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Parsleys;

use C0ntax\ParsleyBundle\Contracts\DirectiveInterface;

/**
* Class RemoveParsleyConstraint
*
* Used to remove Parsley Directives after they've been put in
*
* @package C0ntax\ParsleyBundle\Parsleys
*/
class RemoveParsleyDirective extends AbstractRemove
{
/**
* RemoveParsley constructor.
*
* @param string $className
* @throws \InvalidArgumentException
*/
public function __construct(string $className)
{
parent::__construct($className, DirectiveInterface::class);
}
}
1 change: 0 additions & 1 deletion tests/Form/Extension/ParsleyTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public function testTriggerOverride()
],
$view->children['check']->vars['attr']
);

}

protected function getParsleyTypeConfig()
Expand Down
90 changes: 90 additions & 0 deletions tests/Parsleys/RemoveParsleyDirectiveTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace C0ntax\ParsleyBundle\Tests\Parsleys;

use C0ntax\ParsleyBundle\Parsleys\Directive\Field\Constraint as ParsleyConstraint;
use C0ntax\ParsleyBundle\Parsleys\Directive\Field\ConstraintErrorMessage;
use C0ntax\ParsleyBundle\Parsleys\Directive\Field\Generic;
use C0ntax\ParsleyBundle\Parsleys\Directive\Field\Trigger;
use C0ntax\ParsleyBundle\Parsleys\RemoveParsleyDirective;
use Symfony\Component\Validator\Constraints as SymfonyConstraint;

class RemoveParsleyDirectiveTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getValidClassNames
* @param string $className
*/
public function testValid(string $className)
{
self::assertInstanceOf(RemoveParsleyDirective::class, new RemoveParsleyDirective($className));
}

/**
* @dataProvider getInvalidClassNames
* @param string $className
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageRegExp /^Class [\S]+ does not implement C0ntax\\ParsleyBundle\\Contracts\\DirectiveInterface$/
*/
public function testInvalid(string $className)
{
new RemoveParsleyDirective($className);
}

public function getValidClassNames()
{
return [
[
'className' => ConstraintErrorMessage::class,
],
[
'className' => Generic::class,
],
[
'className' => Trigger::class,
],
[
'className' => ParsleyConstraint\Email::class,
],
[
'className' => ParsleyConstraint\Length::class,
],
[
'className' => ParsleyConstraint\Max::class,
],
[
'className' => ParsleyConstraint\MaxLength::class,
],
[
'className' => ParsleyConstraint\Min::class,
],
[
'className' => ParsleyConstraint\MinLength::class,
],
[
'className' => ParsleyConstraint\Pattern::class,
],
[
'className' => ParsleyConstraint\Range::class,
],
[
'className' => ParsleyConstraint\Required::class,
],
];
}

public function getInvalidClassNames()
{
return [
[
'className' => SymfonyConstraint\Email::class,
],
[
'className' => SymfonyConstraint\Length::class,
],
[
'className' => SymfonyConstraint\Regex::class,
],
];
}
}

0 comments on commit 4b1665c

Please sign in to comment.