Completed
Push — master ( 967300...790e1c )
by Asmir
11s
created

AuthCheckerMock::isGranted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace JMS\SerializerBundle\Tests\ExpressionLanguage;
20
21
use JMS\SerializerBundle\ExpressionLanguage\BasicSerializerFunctionsProvider;
22
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
23
24
class ExpressionLanguageTest extends \PHPUnit_Framework_TestCase
25
{
26
    public function testFunctionProviderCompilation()
27
    {
28
        $provider = new BasicSerializerFunctionsProvider();
29
30
        $exp = new ExpressionLanguage();
31
        $exp->registerProvider($provider);
32
33
        $this->assertEquals('$this->get("foo")', $exp->compile("service('foo')"));
34
        $this->assertEquals('$this->getParameter("foo")', $exp->compile("parameter('foo')"));
35
        $this->assertEquals('call_user_func_array(array($this->get(\'security.authorization_checker\'), \'isGranted\'), array("foo", ))', $exp->compile("is_granted('foo')"));
36
    }
37
38
    public function testFunctionProviderEvaluation()
39
    {
40
        $provider = new BasicSerializerFunctionsProvider();
41
42
        $exp = new ExpressionLanguage();
43
        $exp->registerProvider($provider);
44
45
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() 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...
46
        $container
47
            ->expects($this->once())
48
            ->method('get')->with('foo', 1)
49
            ->will($this->returnValue('bar'));
50
51
        $this->assertEquals('bar', $exp->evaluate("service('foo')", ['container' => $container]));
52
53
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() 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...
54
        $container
55
            ->expects($this->once())
56
            ->method('getParameter')->with('foo')
57
            ->will($this->returnValue('bar'));
58
59
        $this->assertEquals('bar', $exp->evaluate("parameter('foo')", ['container' => $container]));
60
61
        $authChecker = $this->getMock('JMS\SerializerBundle\Tests\ExpressionLanguage\AuthCheckerMock');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() 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...
62
        $authChecker
63
            ->expects($this->once())
64
            ->method('isGranted')->with('foo')
65
            ->will($this->returnValue('bar'));
66
67
68
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() 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...
69
        $container
70
            ->expects($this->once())
71
            ->method('get')->with('security.authorization_checker')
72
            ->will($this->returnValue($authChecker));
73
74
        $this->assertEquals('bar', $exp->evaluate("is_granted('foo')", ['container' => $container]));
75
    }
76
}
77
78
class AuthCheckerMock
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
79
{
80
    public function isGranted()
81
    {
82
83
    }
84
}
85
86