Completed
Push — master ( 3da0b9...07614c )
by Kyle
55:56 queued 41:21
created

Source/Language/PHP/PHPParserVersion71Test.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file is part of PDepend.
4
 *
5
 * Copyright (c) 2008-2017 Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 *
12
 *   * Redistributions of source code must retain the above copyright
13
 *     notice, this list of conditions and the following disclaimer.
14
 *
15
 *   * Redistributions in binary form must reproduce the above copyright
16
 *     notice, this list of conditions and the following disclaimer in
17
 *     the documentation and/or other materials provided with the
18
 *     distribution.
19
 *
20
 *   * Neither the name of Manuel Pichler nor the names of his
21
 *     contributors may be used to endorse or promote products derived
22
 *     from this software without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
 * POSSIBILITY OF SUCH DAMAGE.
36
 *
37
 * @copyright 2008-2017 Manuel Pichler. All rights reserved.
38
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
39
 */
40
41
namespace PDepend\Source\Language\PHP;
42
43
use PDepend\AbstractTest;
44
use PDepend\Source\Builder\Builder;
45
use PDepend\Source\Tokenizer\Tokenizer;
46
use PDepend\Util\Cache\CacheDriver;
47
48
/**
49
 * Test case for the {@link \PDepend\Source\Language\PHP\PHPParserVersion71} class.
50
 *
51
 * @copyright 2008-2017 Manuel Pichler. All rights reserved.
52
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
53
 * @covers \PDepend\Source\Language\PHP\PHPParserVersion71
54
 * @group unittest
55
 */
56
class PHPParserVersion71Test extends AbstractTest
57
{
58
    /**
59
     * @return void
60
     */
61
    public function testConstVisibility()
62
    {
63
        $this->assertNotNull($this->parseCodeResourceForTest());
64
    }
65
66
    /**
67
     * @return void
68
     */
69
    public function testConstVisibilityInInterfacePublic()
70
    {
71
        $this->assertNotNull($this->parseCodeResourceForTest());
72
    }
73
74
    /**
75
     * @return void
76
     */
77
    public function testConstVisibilityInInterfaceProtected()
78
    {
79
        $this->setExpectedException(
80
            '\\PDepend\\Source\\Parser\\InvalidStateException',
81
            'Constant can\'t be declared private or protected in interface "TestInterface".'
82
        );
83
84
        $this->parseCodeResourceForTest();
85
    }
86
87
    /**
88
     * @return void
89
     */
90
    public function testConstVisibilityInInterfacePrivate()
91
    {
92
        $this->setExpectedException(
93
            '\\PDepend\\Source\\Parser\\InvalidStateException',
94
            'Constant can\'t be declared private or protected in interface "TestInterface".'
95
        );
96
        
97
        $this->parseCodeResourceForTest();
98
    }
99
100
    /**
101
     * @return void
102
     */
103
    public function testCatchMultipleExceptionClasses()
104
    {
105
        $this->assertNotNull($this->parseCodeResourceForTest());        
106
    }
107
    
108
    /**
109
     * @return void
110
     */
111
    public function testNullableTypeHintParameter()
112
    {
113
        $this->assertNotNull($this->parseCodeResourceForTest());
114
    }
115
116
    /**
117
     * @return void
118
     */
119
    public function testNullableTypeHintReturn()
120
    {
121
        $this->assertNotNull($this->parseCodeResourceForTest());
122
    }
123
124
    /**
125
     * @return void
126
     */
127
    public function testIterableTypeHintParameter()
128
    {
129
        $type = $this->getFirstFormalParameterForTestCase()->getType();
130
131
        $this->assertFalse($type->isScalar());
132
        $this->assertTrue($type->isArray());
133
        $this->assertSame('iterable', $type->getImage());
134
    }
135
136
    /**
137
     * @return void
138
     */
139 View Code Duplication
    public function testIterableTypeHintReturn()
140
    {
141
        $type = $this->getFirstFunctionForTestCase()->getReturnType();
142
        
143
        $this->assertFalse($type->isScalar());
144
        $this->assertTrue($type->isArray());
145
        $this->assertSame('iterable', $type->getImage());
146
    }
147
148
    /**
149
     * @return void
150
     */
151 View Code Duplication
    public function testVoidTypeHintReturn()
152
    {
153
        $type = $this->getFirstFunctionForTestCase()->getReturnType();
154
        
155
        $this->assertTrue($type->isScalar());
156
        $this->assertFalse($type->isArray());
157
        $this->assertSame('void', $type->getImage());
158
    }
159
160
    /**
161
     * @return void
162
     */
163 View Code Duplication
    public function testVoidTypeHintReturnNamespaced()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
164
    {
165
        $type = $this->getFirstFunctionForTestCase()->getReturnType();
166
        $this->assertTrue($type->isScalar());
167
        $this->assertFalse($type->isArray());
168
        $this->assertSame('void', $type->getImage());
169
    }
170
171
    /**
172
     * @param \PDepend\Source\Tokenizer\Tokenizer $tokenizer
173
     * @param \PDepend\Source\Builder\Builder $builder
174
     * @param \PDepend\Util\Cache\CacheDriver $cache
175
     * @return \PDepend\Source\Language\PHP\AbstractPHPParser
176
     */
177
    protected function createPHPParser(Tokenizer $tokenizer, Builder $builder, CacheDriver $cache)
178
    {
179
        return $this->getMockForAbstractClass(
180
            'PDepend\\Source\\Language\\PHP\\PHPParserVersion71',
181
            array($tokenizer, $builder, $cache)
182
        );
183
    }
184
}
185