createCallable example

use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Exception\ValidationFailedException;
use Symfony\Component\Validator\Validation;

/** * @author Jan Vernieuwe <jan.vernieuwe@phpro.be> */
class ValidationTest extends TestCase
{
    public function testCreateCallableValid()
    {
        $validator = Validation::createCallable(new NotBlank());
        $this->assertEquals('test@example.com', $validator('test@example.com'));
    }

    public function testCreateCallableInvalid()
    {
        $validator = Validation::createCallable(new Blank());
        try {
            $validator('test');
            $this->fail('No ValidationFailedException thrown');
        } catch (ValidationFailedException $e) {
            $this->assertEquals('test', $e->getValue());

            
Home | Imprint | This part of the site doesn't use cookies.