Arbit - project tracking

PHPMD

Browse source code

File: / test/ PHP/ PMD/ Node/ MethodTest.php

Type
text/plain text/plain
Last Author
mapi
Version
209
Line Rev. Author Source
1 116 mapi <?php
2 mapi /**
3 mapi * This file is part of PHP_PMD.
4 mapi *
5 mapi * PHP Version 5
6 mapi *
7 174 mapi * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
8 116 mapi * All rights reserved.
9 mapi *
10 mapi * Redistribution and use in source and binary forms, with or without
11 mapi * modification, are permitted provided that the following conditions
12 mapi * are met:
13 mapi *
14 mapi * * Redistributions of source code must retain the above copyright
15 mapi * notice, this list of conditions and the following disclaimer.
16 mapi *
17 mapi * * Redistributions in binary form must reproduce the above copyright
18 mapi * notice, this list of conditions and the following disclaimer in
19 mapi * the documentation and/or other materials provided with the
20 mapi * distribution.
21 mapi *
22 mapi * * Neither the name of Manuel Pichler nor the names of his
23 mapi * contributors may be used to endorse or promote products derived
24 mapi * from this software without specific prior written permission.
25 mapi *
26 mapi * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 mapi * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 mapi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 mapi * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 mapi * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 mapi * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 mapi * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 mapi * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 mapi * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 mapi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 mapi * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 mapi * POSSIBILITY OF SUCH DAMAGE.
38 mapi *
39 mapi * @category PHP
40 mapi * @package PHP_PMD
41 mapi * @subpackage Node
42 174 mapi * @author Manuel Pichler <mapi@phpmd.org>
43 150 mapi * @copyright 2009-2010 Manuel Pichler. All rights reserved.
44 116 mapi * @license http://www.opensource.org/licenses/bsd-license.php BSD License
45 mapi * @version SVN: $Id$
46 174 mapi * @link http://phpmd.org
47 116 mapi */
48 mapi
49 mapi require_once dirname(__FILE__) . '/../AbstractTest.php';
50 mapi
51 200 mapi require_once 'PHP/PMD/Node/Method.php';
52 116 mapi require_once 'PHP/Depend/Code/Method.php';
53 mapi
54 mapi /**
55 mapi * Test case for the method node implementation.
56 mapi *
57 mapi * @category PHP
58 mapi * @package PHP_PMD
59 mapi * @subpackage Node
60 174 mapi * @author Manuel Pichler <mapi@phpmd.org>
61 150 mapi * @copyright 2009-2010 Manuel Pichler. All rights reserved.
62 116 mapi * @license http://www.opensource.org/licenses/bsd-license.php BSD License
63 mapi * @version Release: @package_version@
64 174 mapi * @link http://phpmd.org
65 116 mapi */
66 200 mapi class PHP_PMD_Node_MethodTest extends PHP_PMD_AbstractTest
67 116 mapi {
68 mapi /**
69 mapi * testMagicCallDelegatesToWrappedPHPDependMethod
70 mapi *
71 mapi * @return void
72 200 mapi * @covers PHP_PMD_Node_AbstractCallable::__call
73 116 mapi * @group phpmd
74 mapi * @group phpmd::node
75 mapi * @group unittest
76 mapi */
77 mapi public function testMagicCallDelegatesToWrappedPHPDependMethod()
78 mapi {
79 mapi $method = $this->getMock('PHP_Depend_Code_Method', array(), array(null));
80 mapi $method->expects($this->once())
81 mapi ->method('getStartLine');
82 mapi
83 200 mapi $node = new PHP_PMD_Node_Method($method);
84 116 mapi $node->getStartLine();
85 mapi }
86 mapi
87 mapi /**
88 mapi * testMagicCallThrowsExceptionWhenNoMatchingMethodExists
89 mapi *
90 mapi * @return void
91 200 mapi * @covers PHP_PMD_Node_AbstractCallable::__call
92 116 mapi * @group phpmd
93 mapi * @group phpmd::node
94 mapi * @group unittest
95 mapi * @expectedException BadMethodCallException
96 mapi */
97 mapi public function testMagicCallThrowsExceptionWhenNoMatchingMethodExists()
98 mapi {
99 200 mapi $node = new PHP_PMD_Node_Method(new PHP_Depend_Code_Method(null));
100 116 mapi $node->getFooBar();
101 209 mapi }
102 116 mapi
103 209 mapi /**
104 mapi * testGetParentTypeReturnsInterfaceForInterfaceMethod
105 mapi *
106 mapi * @return void
107 mapi * @covers PHP_PMD_Node_Method::getParentType
108 mapi * @group phpmd
109 mapi * @group phpmd::node
110 mapi * @group unittest
111 mapi */
112 mapi public function testGetParentTypeReturnsInterfaceForInterfaceMethod()
113 mapi {
114 mapi $method = $this->getMethod();
115 mapi $this->assertType(PHP_PMD_Node_Interface::CLAZZ, $method->getParentType());
116 116 mapi }
117 209 mapi
118 mapi /**
119 mapi * testGetParentTypeReturnsClassForClassMethod
120 mapi *
121 mapi * @return void
122 mapi * @covers PHP_PMD_Node_Method::getParentType
123 mapi * @group phpmd
124 mapi * @group phpmd::node
125 mapi * @group unittest
126 mapi */
127 mapi public function testGetParentTypeReturnsClassForClassMethod()
128 mapi {
129 mapi $method = $this->getMethod();
130 mapi $this->assertType(PHP_PMD_Node_Class::CLAZZ, $method->getParentType());
131 mapi }
132 mapi
133 mapi /**
134 mapi * testHasSuppressWarningsExecutesDefaultImplementation
135 mapi *
136 mapi * @return void
137 mapi * @covers PHP_PMD_Node_Method::hasSuppressWarningsAnnotationFor
138 mapi * @group phpmd
139 mapi * @group phpmd::node
140 mapi * @group unittest
141 mapi */
142 mapi public function testHasSuppressWarningsExecutesDefaultImplementation()
143 mapi {
144 mapi $rule = $this->getRuleMock();
145 mapi $rule->setName('FooBar');
146 mapi
147 mapi $method = $this->getMethod();
148 mapi $this->assertTrue($method->hasSuppressWarningsAnnotationFor($rule));
149 mapi }
150 mapi
151 mapi /**
152 mapi * testHasSuppressWarningsDelegatesToParentClassMethod
153 mapi *
154 mapi * @return void
155 mapi * @covers PHP_PMD_Node_Method::hasSuppressWarningsAnnotationFor
156 mapi * @group phpmd
157 mapi * @group phpmd::node
158 mapi * @group unittest
159 mapi */
160 mapi public function testHasSuppressWarningsDelegatesToParentClassMethod()
161 mapi {
162 mapi $rule = $this->getRuleMock();
163 mapi $rule->setName('FooBar');
164 mapi
165 mapi $method = $this->getMethod();
166 mapi $this->assertTrue($method->hasSuppressWarningsAnnotationFor($rule));
167 mapi }
168 mapi
169 mapi /**
170 mapi * testHasSuppressWarningsDelegatesToParentInterfaceMethod
171 mapi *
172 mapi * @return void
173 mapi * @covers PHP_PMD_Node_Method::hasSuppressWarningsAnnotationFor
174 mapi * @group phpmd
175 mapi * @group phpmd::node
176 mapi * @group unittest
177 mapi */
178 mapi public function testHasSuppressWarningsDelegatesToParentInterfaceMethod()
179 mapi {
180 mapi $rule = $this->getRuleMock();
181 mapi $rule->setName('FooBar');
182 mapi
183 mapi $method = $this->getMethod();
184 mapi $this->assertTrue($method->hasSuppressWarningsAnnotationFor($rule));
185 mapi }
186 116 mapi }