Arbit - project tracking

PHPMD

Browse source code

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

Type
text/plain text/plain
Last Author
mapi
Version
200
Line Rev. Author Source
1 200 mapi <?php
2 mapi /**
3 mapi * This file is part of PHP_PMD.
4 mapi *
5 mapi * PHP Version 5
6 mapi *
7 mapi * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
8 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 mapi * @author Manuel Pichler <mapi@phpmd.org>
43 mapi * @copyright 2009-2010 Manuel Pichler. All rights reserved.
44 mapi * @license http://www.opensource.org/licenses/bsd-license.php BSD License
45 mapi * @version SVN: $Id$
46 mapi * @link http://phpmd.org
47 mapi */
48 mapi
49 mapi require_once dirname(__FILE__) . '/../AbstractTest.php';
50 mapi
51 mapi require_once 'PHP/PMD/Node/Annotations.php';
52 mapi
53 mapi /**
54 mapi * Test case for the {@link PHP_PMD_Node_Annotations} class.
55 mapi *
56 mapi * @category PHP
57 mapi * @package PHP_PMD
58 mapi * @subpackage Node
59 mapi * @author Manuel Pichler <mapi@phpmd.org>
60 mapi * @copyright 2009-2010 Manuel Pichler. All rights reserved.
61 mapi * @license http://www.opensource.org/licenses/bsd-license.php BSD License
62 mapi * @version Release: @package_version@
63 mapi * @link http://phpmd.org
64 mapi */
65 mapi class PHP_PMD_Node_AnnotationsTest extends PHP_PMD_AbstractTest
66 mapi {
67 mapi /**
68 mapi * testCollectionReturnsFalseWhenNoAnnotationExists
69 mapi *
70 mapi * @return void
71 mapi * @covers PHP_PMD_Node_Annotations
72 mapi * @group phpmd
73 mapi * @group phpmd::node
74 mapi * @group unittest
75 mapi */
76 mapi public function testCollectionReturnsFalseWhenNoAnnotationExists()
77 mapi {
78 mapi $annotations = new PHP_PMD_Node_Annotations($this->getClassMock());
79 mapi $this->assertFalse($annotations->suppresses($this->getRuleMock()));
80 mapi }
81 mapi
82 mapi /**
83 mapi * testCollectionReturnsFalseWhenNoMatchingAnnotationExists
84 mapi *
85 mapi * @return void
86 mapi * @covers PHP_PMD_Node_Annotations
87 mapi * @group phpmd
88 mapi * @group phpmd::node
89 mapi * @group unittest
90 mapi */
91 mapi public function testCollectionReturnsFalseWhenNoMatchingAnnotationExists()
92 mapi {
93 mapi $class = $this->getClassMock();
94 mapi $class->expects($this->once())
95 mapi ->method('__call')
96 mapi ->with($this->equalTo('getDocComment'))
97 mapi ->will(
98 mapi $this->returnValue(
99 mapi '/**
100 mapi * @SuppressWarnings("Foo")
101 mapi * @SuppressWarnings("Bar")
102 mapi * @SuppressWarnings("Baz")
103 mapi */'
104 mapi )
105 mapi );
106 mapi
107 mapi $annotations = new PHP_PMD_Node_Annotations($class);
108 mapi $this->assertFalse($annotations->suppresses($this->getRuleMock()));
109 mapi }
110 mapi
111 mapi /**
112 mapi * testCollectionReturnsTrueWhenMatchingAnnotationExists
113 mapi *
114 mapi * @return void
115 mapi * @covers PHP_PMD_Node_Annotations
116 mapi * @group phpmd
117 mapi * @group phpmd::node
118 mapi * @group unittest
119 mapi */
120 mapi public function testCollectionReturnsTrueWhenMatchingAnnotationExists()
121 mapi {
122 mapi $class = $this->getClassMock();
123 mapi $class->expects($this->once())
124 mapi ->method('__call')
125 mapi ->with($this->equalTo('getDocComment'))
126 mapi ->will($this->returnValue('/** @SuppressWarnings("PMD") */'));
127 mapi
128 mapi $annotations = new PHP_PMD_Node_Annotations($class);
129 mapi $this->assertTrue($annotations->suppresses($this->getRuleMock()));
130 mapi }
131 mapi
132 mapi /**
133 mapi * testCollectionReturnsTrueWhenOneMatchingAnnotationExists
134 mapi *
135 mapi * @return void
136 mapi * @covers PHP_PMD_Node_Annotations
137 mapi * @group phpmd
138 mapi * @group phpmd::node
139 mapi * @group unittest
140 mapi */
141 mapi public function testCollectionReturnsTrueWhenOneMatchingAnnotationExists()
142 mapi {
143 mapi $class = $this->getClassMock();
144 mapi $class->expects($this->once())
145 mapi ->method('__call')
146 mapi ->with($this->equalTo('getDocComment'))
147 mapi ->will(
148 mapi $this->returnValue(
149 mapi '/**
150 mapi * @SuppressWarnings("FooBar")
151 mapi * @SuppressWarnings("PMD")
152 mapi */'
153 mapi )
154 mapi );
155 mapi
156 mapi $annotations = new PHP_PMD_Node_Annotations($class);
157 mapi $this->assertTrue($annotations->suppresses($this->getRuleMock()));
158 mapi }
159 mapi }