ValidatorTest::validateXApiValidator()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 21
rs 9.3142
c 2
b 0
f 1
cc 2
eloc 13
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Validator\Tests;
13
14
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
15
use Symfony\Component\Validator\ValidatorInterface;
16
use Xabbuh\XApi\Validator\Validator;
17
18
/**
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
class ValidatorTest extends \PHPUnit_Framework_TestCase
22
{
23
    public function testRegisterXApiConstraints()
24
    {
25
        $validatorBuilder = $this->getMock('\Symfony\Component\Validator\ValidatorBuilderInterface');
26
        $validatorBuilder->expects($this->once())
27
            ->method('addXmlMappings');
28
29
        Validator::registerXApiConstraints($validatorBuilder);
30
    }
31
32
    public function testCreateValidatorBuilder()
33
    {
34
        $builder = Validator::createValidatorBuilder();
35
36
        $this->validateXApiValidator($builder->getValidator());
37
    }
38
39
    public function testCreateValidator()
40
    {
41
        $this->validateXApiValidator(Validator::createValidator());
42
    }
43
44
    private function validateXApiValidator(ValidatorInterface $validator)
45
    {
46
        if ($validator instanceof MetadataFactoryInterface) {
47
            $metadataFactory = $validator;
48
        } else {
49
            $metadataFactory = $validator->getMetadataFactory();
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Valida...e::getMetadataFactory() has been deprecated with message: since version 2.5, to be removed in 3.0. Use {@link Validator\ValidatorInterface::getMetadataFor()} or {@link Validator\ValidatorInterface::hasMetadataFor()} instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
50
        }
51
52
        $this->assertTrue(
53
            $metadataFactory->hasMetadataFor('\Xabbuh\XApi\Model\Activity')
54
        );
55
        $this->assertTrue(
56
            $metadataFactory->hasMetadataFor('\Xabbuh\XApi\Model\Agent')
57
        );
58
        $this->assertTrue(
59
            $metadataFactory->hasMetadataFor('\Xabbuh\XApi\Model\Activity')
60
        );
61
        $this->assertTrue(
62
            $metadataFactory->hasMetadataFor('\Xabbuh\XApi\Model\Activity')
63
        );
64
    }
65
}
66