Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
4d8956f3
Commit
4d8956f3
authored
Mar 09, 2013
by
alexkappa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added custom constraint and validator to properly test the ConstraintValidatorFactory.
parent
b45b4fb2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
5 deletions
+65
-5
tests/Silex/Tests/Provider/ValidatorServiceProviderTest.php
tests/Silex/Tests/Provider/ValidatorServiceProviderTest.php
+9
-5
tests/Silex/Tests/Provider/ValidatorServiceProviderTest/Constraint/Custom.php
...ovider/ValidatorServiceProviderTest/Constraint/Custom.php
+29
-0
tests/Silex/Tests/Provider/ValidatorServiceProviderTest/Constraint/CustomValidator.php
...lidatorServiceProviderTest/Constraint/CustomValidator.php
+27
-0
No files found.
tests/Silex/Tests/Provider/ValidatorServiceProviderTest.php
View file @
4d8956f3
...
...
@@ -15,6 +15,8 @@ use Silex\Application;
use
Silex\Provider\ValidatorServiceProvider
;
use
Silex\Provider\FormServiceProvider
;
use
Symfony\Component\Validator\Constraints
as
Assert
;
use
Silex\Tests\Provider\ValidatorServiceProviderTest\Constraint\Custom
;
use
Silex\Tests\Provider\ValidatorServiceProviderTest\Constraint\CustomValidator
;
/**
* ValidatorServiceProvider
...
...
@@ -43,14 +45,13 @@ class ValidatorServiceProviderTest extends \PHPUnit_Framework_TestCase
{
$app
=
new
Application
();
// Dummy ConstraintValidators
$app
[
'validator.x'
]
=
'x'
;
$app
[
'validator.y'
]
=
'y'
;
$app
[
'custom.validator'
]
=
$app
->
share
(
function
()
{
return
new
CustomValidator
()
;
})
;
$app
->
register
(
new
ValidatorServiceProvider
(),
array
(
'validator.validator_service_ids'
=>
array
(
'alias_x'
=>
'validator.x'
,
'alias_y'
=>
'validator.y'
'test.custom.validator'
=>
'custom.validator'
,
)
));
...
...
@@ -63,6 +64,9 @@ class ValidatorServiceProviderTest extends \PHPUnit_Framework_TestCase
public
function
testConstraintValidatorFactory
(
$app
)
{
$this
->
assertInstanceOf
(
'Silex\ConstraintValidatorFactory'
,
$app
[
'validator.validator_factory'
]);
$validator
=
$app
[
'validator.validator_factory'
]
->
getInstance
(
new
Custom
());
$this
->
assertInstanceOf
(
'Silex\Tests\Provider\ValidatorServiceProviderTest\Constraint\CustomValidator'
,
$validator
);
}
/**
...
...
tests/Silex/Tests/Provider/ValidatorServiceProviderTest/Constraint/Custom.php
0 → 100644
View file @
4d8956f3
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Provider\ValidatorServiceProviderTest\Constraint
;
use
Symfony\Component\Validator\Constraint
;
/**
* @author Alex Kalyvitis <alex.kalyvitis@gmail.com>
*/
class
Custom
extends
Constraint
{
public
$message
=
'This field must be ...'
;
public
$table
;
public
$field
;
public
function
validatedBy
()
{
return
'test.custom.validator'
;
}
}
tests/Silex/Tests/Provider/ValidatorServiceProviderTest/Constraint/CustomValidator.php
0 → 100644
View file @
4d8956f3
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Provider\ValidatorServiceProviderTest\Constraint
;
use
Symfony\Component\Validator\Constraint
;
use
Symfony\Component\Validator\ConstraintValidator
;
/**
* @author Alex Kalyvitis <alex.kalyvitis@gmail.com>
*/
class
CustomValidator
extends
ConstraintValidator
{
public
function
isValid
(
$value
,
Constraint
$constraint
)
{
// Validate...
return
true
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment