Issues (5)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/phpunit/Unit/CompositeCacheTest.php (2 issues)

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
namespace Onoi\Cache\Tests;
4
5
use Onoi\Cache\CompositeCache;
6
7
/**
8
 * @covers \Onoi\Cache\CompositeCache
9
 *
10
 * @group onoi-cache
11
 *
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class CompositeCacheTest extends \PHPUnit_Framework_TestCase {
18
19
	public function testCanConstruct() {
20
21
		$cache = $this->getMockBuilder( '\Onoi\Cache\Cache' )
22
			->disableOriginalConstructor()
23
			->getMockForAbstractClass();
24
25
		$this->assertInstanceOf(
26
			'\Onoi\Cache\CompositeCache',
27
			new CompositeCache( array( $cache ) )
28
		);
29
	}
30
31
	public function testConstructForInvalidArrayKeyThrowsException() {
32
33
		$cache = $this->getMockBuilder( '\Onoi\Cache\Cache' )
34
			->disableOriginalConstructor()
35
			->getMockForAbstractClass();
36
37
		$this->setExpectedException( 'RuntimeException' );
38
		new CompositeCache( array( 'cache' => $cache ) );
39
	}
40
41
	public function testConstructForInvalidCacheInstanceThrowsException() {
42
43
		$this->setExpectedException( 'RuntimeException' );
44
		new CompositeCache( array( 'Foo' ) );
0 ignored issues
show
array('Foo') is of type array<integer,string,{"0":"string"}>, but the function expects a array<integer,object<Onoi\Cache\Cache>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
	}
46
47
	public function testGetName() {
48
49
		$first = $this->getMockBuilder( '\Onoi\Cache\ZendCache' )
50
			->disableOriginalConstructor()
51
			->getMockForAbstractClass();
52
53
		$second = $this->getMockBuilder( '\Onoi\Cache\DoctrineCache' )
54
			->disableOriginalConstructor()
55
			->getMockForAbstractClass();
56
57
		$instance = new CompositeCache( array( $first, $second ) );
58
59
		$this->assertInternalType(
60
			'string',
61
			$instance->getName()
62
		);
63
	}
64
65
	public function testSave() {
66
67
		$first = $this->getMockBuilder( '\Onoi\Cache\Cache' )
68
			->disableOriginalConstructor()
69
			->getMockForAbstractClass();
70
71
		$first->expects( $this->once() )
72
			->method( 'save' )
73
			->with(
74
				$this->equalTo( 'Foo' ),
75
				$this->anything() );
76
77
		$second = $this->getMockBuilder( '\Onoi\Cache\Cache' )
78
			->disableOriginalConstructor()
79
			->getMockForAbstractClass();
80
81
		$second->expects( $this->once() )
82
			->method( 'save' )
83
			->with(
84
				$this->equalTo( 'Foo' ),
85
				$this->anything() );
86
87
		$instance = new CompositeCache( array( $first, $second ) );
88
		$instance->save( 'Foo', 'Bar' );
89
	}
90
91
	public function testDelete() {
92
93
		$first = $this->getMockBuilder( '\Onoi\Cache\Cache' )
94
			->disableOriginalConstructor()
95
			->getMockForAbstractClass();
96
97
		$first->expects( $this->once() )
98
			->method( 'delete' )
99
			->with(
100
				$this->equalTo( 'Foo' ) );
101
102
		$second = $this->getMockBuilder( '\Onoi\Cache\Cache' )
103
			->disableOriginalConstructor()
104
			->getMockForAbstractClass();
105
106
		$second->expects( $this->once() )
107
			->method( 'delete' )
108
			->with(
109
				$this->equalTo( 'Foo' ) );
110
111
		$instance = new CompositeCache( array( $first, $second ) );
112
		$instance->delete( 'Foo' );
113
	}
114
115
	public function testGetStats() {
116
117
		$first = $this->getMockBuilder( '\Onoi\Cache\Cache' )
118
			->disableOriginalConstructor()
119
			->getMockForAbstractClass();
120
121
		$first->expects( $this->once() )
122
			->method( 'getStats' );
123
124
		$second = $this->getMockBuilder( '\Onoi\Cache\Cache' )
125
			->disableOriginalConstructor()
126
			->getMockForAbstractClass();
127
128
		$second->expects( $this->once() )
129
			->method( 'getStats' );
130
131
		$instance = new CompositeCache( array( $first, $second ) );
132
133
		$this->assertInternalType(
134
			'array',
135
			$instance->getStats( 'Foo' )
0 ignored issues
show
The call to CompositeCache::getStats() has too many arguments starting with 'Foo'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
136
		);
137
	}
138
139
	public function testContainsIsTrueForFirstCache() {
140
141
		$first = $this->getMockBuilder( '\Onoi\Cache\Cache' )
142
			->disableOriginalConstructor()
143
			->getMockForAbstractClass();
144
145
		$first->expects( $this->once() )
146
			->method( 'contains' )
147
			->with(
148
				$this->equalTo( 'Foo' ) )
149
			->will( $this->returnValue( true ) );
150
151
		$second = $this->getMockBuilder( '\Onoi\Cache\Cache' )
152
			->disableOriginalConstructor()
153
			->getMockForAbstractClass();
154
155
		$second->expects( $this->never() )
156
			->method( 'contains' );
157
158
		$instance = new CompositeCache( array( $first, $second ) );
159
160
		$this->assertTrue(
161
			$instance->contains( 'Foo' )
162
		);
163
	}
164
165
	public function testContainsIsFalseForFirstCache() {
166
167
		$first = $this->getMockBuilder( '\Onoi\Cache\Cache' )
168
			->disableOriginalConstructor()
169
			->getMockForAbstractClass();
170
171
		$first->expects( $this->once() )
172
			->method( 'contains' );
173
174
		$second = $this->getMockBuilder( '\Onoi\Cache\Cache' )
175
			->disableOriginalConstructor()
176
			->getMockForAbstractClass();
177
178
		$second->expects( $this->once() )
179
			->method( 'contains' )
180
			->with(
181
				$this->equalTo( 'Foo' ) )
182
			->will( $this->returnValue( false ) );
183
184
		$instance = new CompositeCache( array( $first, $second ) );
185
186
		$this->assertFalse(
187
			$instance->contains( 'Foo' )
188
		);
189
	}
190
191
	public function testFetchToReturnNoResultForFirstCache() {
192
193
		$first = $this->getMockBuilder( '\Onoi\Cache\Cache' )
194
			->disableOriginalConstructor()
195
			->getMockForAbstractClass();
196
197
		$first->expects( $this->once() )
198
			->method( 'contains' );
199
200
		$first->expects( $this->once() )
201
			->method( 'save' )
202
			->with(
203
				$this->equalTo( 'Foo' ),
204
				$this->anything() );
205
206
		$second = $this->getMockBuilder( '\Onoi\Cache\Cache' )
207
			->disableOriginalConstructor()
208
			->getMockForAbstractClass();
209
210
		$second->expects( $this->once() )
211
			->method( 'contains' )
212
			->will( $this->returnValue( true ) );
213
214
		$second->expects( $this->once() )
215
			->method( 'fetch' )
216
			->with(
217
				$this->equalTo( 'Foo' ) )
218
			->will( $this->returnValue( 'Bar' ) );
219
220
		$instance = new CompositeCache( array( $first, $second ) );
221
222
		$this->assertEquals(
223
			'Bar',
224
			$instance->fetch( 'Foo' )
225
		);
226
	}
227
228
	public function testFetchForToReturnNoResultForAll() {
229
230
		$first = $this->getMockBuilder( '\Onoi\Cache\Cache' )
231
			->disableOriginalConstructor()
232
			->getMockForAbstractClass();
233
234
		$first->expects( $this->once() )
235
			->method( 'contains' );
236
237
		$second = $this->getMockBuilder( '\Onoi\Cache\Cache' )
238
			->disableOriginalConstructor()
239
			->getMockForAbstractClass();
240
241
		$second->expects( $this->once() )
242
			->method( 'contains' );
243
244
		$instance = new CompositeCache( array( $first, $second ) );
245
246
		$this->assertFalse(
247
			$instance->fetch( 'Foo' )
248
		);
249
	}
250
251
}
252