Issues (4)

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.

MockedIteratorTest.php (4 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
 * This file is part of the Axstrad library.
4
 *
5
 * (c) Dan Kempster <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Axstrad\Component\Test;
12
13
/**
14
 * Axstrad\Component\Test\MockedIteratorTest
15
 *
16
 * Tests for _mock_ Iterator
17
 *
18
 * Here we have added a helper method (which you could add to your own abstract
19
 * base test class) that will help us mock iterators quickly and easily.
20
 *
21
 * @author Dave Gardner <[email protected]>
22
 * @author Dan Kempster <[email protected]>
23
 * @license http://opensource.org/licenses/MIT MIT
24
 * @package Axstrad/Test
25
 * @subpackage Iterator
26
 */
27
class MockedIteratorTest extends \PHPUnit_Framework_TestCase
28
{
29 6
    protected function mockGenericIteratableList()
30
    {
31 6
        return $this->getMock('Axstrad\Component\Test\Example\ExampleList');
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...
32
    }
33
34
    /**
35
     * Mock iterator
36
     *
37
     * This attaches all the required expectations in the right order so that
38
     * our iterator will act like an iterator!
39
     *
40
     * @param \Iterator $iterator The iterator object; this is what we attach
41
     *      all the expectations to
42
     * @param array An array of items that we will mock up, we will use the
43
     *      keys (if needed) and values of this array to return
44
     * @param boolean $includeCallsToKey Whether we want to mock up the calls
45
     *      to "key"; only needed if you are doing foreach ($foo as $k => $v)
46
     *      as opposed to foreach ($foo as $v)
47
     */
48 4
    protected function mockIterator(
49
        \Iterator $iterator,
50
        array $items,
51
        $includeCallsToKey = FALSE
52
    ) {
53
        $iterator
54 4
            ->expects(
55 4
                $this->at(0)
56
            )
57 4
            ->method('rewind')
58
        ;
59 4
        $counter = 1;
60
61 4
        foreach ($items as $k => $v) {
62
            $iterator
63 4
                ->expects(
64 4
                    $this->at($counter++)
65
                )
66 4
                ->method('valid')
67 4
                ->will(
68 4
                    $this->returnValue(TRUE)
69
                )
70
            ;
71
            $iterator
72 4
                ->expects(
73 4
                    $this->at($counter++)
74
                )
75 4
                ->method('current')
76 4
                ->will(
77 4
                    $this->returnValue($v)
78
                )
79
            ;
80 4
            if ($includeCallsToKey) {
81
                $iterator
82 2
                    ->expects(
83 2
                        $this->at($counter++)
84
                    )
85 2
                    ->method('key')
86 2
                    ->will(
87 2
                        $this->returnValue($k)
88
                    )
89
                ;
90
            }
91
            $iterator
92 4
                ->expects(
93 4
                    $this->at($counter++)
94
                )
95 4
                ->method('next')
96
            ;
97
        }
98
99
        $iterator
100 4
            ->expects(
101 4
                $this->at($counter)
102
            )
103 4
            ->method('valid')
104 4
            ->will(
105 4
                $this->returnValue(FALSE)
106
            )
107
        ;
108 4
    }
109
110 1
    public function testConstructs()
111
    {
112 1
        $list = $this->mockGenericIteratableList();
113 1
        $this->assertInstanceOf('Axstrad\Component\Test\Example\ExampleList', $list);
114 1
        $this->assertInstanceOf('Iterator', $list);
115 1
    }
116
117 1
    public function testHasZeroItemsWhenWeHaventMockedMethods()
118
    {
119 1
        $list = $this->mockGenericIteratableList();
120 1
        $counter = 0;
121 1
        foreach ($list as $item) {
122
            // @codeCoverageIgnoreStart
123
            $counter++;
124
            // @codeCoverageIgnoreEnd
125
        }
126 1
        $this->assertEquals(0, $counter);
127 1
    }
128
129 1
    public function testWhenMockOneIterationWithNoKey()
130
    {
131 1
        $list = $this->mockGenericIteratableList();
132
133 1
        $this->mockIterator($list, array('This is the first item'));
134
135 1
        $counter = 0;
136 1
        foreach ($list as $value) {
137 1
            $counter++;
138
        }
139 1
        $this->assertEquals(1, $counter);
140 1
        $this->assertEquals('This is the first item', $value);
0 ignored issues
show
The variable $value seems to be defined by a foreach iteration on line 136. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
141 1
    }
142
143 1
    public function testWhenMockOneIterationWithKey()
144
    {
145 1
        $list = $this->mockGenericIteratableList();
146
147 1
        $this->mockIterator($list, array('key1' => 'This is the first item'), TRUE);
148
149 1
        $counter = 0;
150 1
        foreach ($list as $key => $value) {
151 1
            $counter++;
152
        }
153 1
        $this->assertEquals(1, $counter);
154 1
        $this->assertEquals('key1', $key);
0 ignored issues
show
The variable $key seems to be defined by a foreach iteration on line 150. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
155 1
        $this->assertEquals('This is the first item', $value);
0 ignored issues
show
The variable $value seems to be defined by a foreach iteration on line 150. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
156 1
    }
157
158 1
    public function testWhenMockThreeIterationWithNoKey()
159
    {
160 1
        $list = $this->mockGenericIteratableList();
161
162
        $expectedValues = array(
163 1
            'This is the first item',
164
            'This is the second item',
165
            'And the final item'
166
        );
167 1
        $this->mockIterator($list, $expectedValues);
168
169 1
        $counter = 0;
170 1
        $values = array();
171 1
        foreach ($list as $value) {
172 1
            $values[] = $value;
173 1
            $counter++;
174
        }
175 1
        $this->assertEquals(3, $counter);
176
177 1
        $this->assertEquals($expectedValues, $values);
178 1
    }
179
180 1
    public function testWhenMockThreeIterationWithKey()
181
    {
182 1
        $list = $this->mockGenericIteratableList();
183
184
        $expectedValues = array(
185 1
            'item1' => 'This is the first item',
186
            'foo'   => 'This is the second item!!',
187
            'bar'   => 'And the final item'
188
        );
189 1
        $this->mockIterator($list, $expectedValues, TRUE);
190
191 1
        $counter = 0;
192 1
        $values = array();
193 1
        foreach ($list as $key => $value) {
194 1
            $values[$key] = $value;
195 1
            $counter++;
196
        }
197 1
        $this->assertEquals(3, $counter);
198
199 1
        $this->assertEquals($expectedValues, $values);
200 1
    }
201
}
202