Issues (31)

Security Analysis    not enabled

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/Manager/ContentManagerTest.php (9 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
/*
4
 * This file is part of the Ivoaz ContentEditable bundle.
5
 *
6
 * (c) Ivo Azirjans <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Ivoaz\Bundle\ContentEditableBundle\Tests\Manager;
13
14
use Doctrine\Common\Persistence\ObjectManager;
15
use Doctrine\Common\Persistence\ObjectRepository;
16
use Ivoaz\Bundle\ContentEditableBundle\Manager\ContentManager;
17
use Ivoaz\Bundle\ContentEditableBundle\Exception\MissingLocaleException;
18
use Ivoaz\Bundle\ContentEditableBundle\Model\Content;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\HttpFoundation\RequestStack;
21
22
class ContentManagerTest extends \PHPUnit_Framework_TestCase
23
{
24
    /**
25
     * @var ObjectManager|\PHPUnit_Framework_MockObject_MockObject
26
     */
27
    private $om;
28
29
    /**
30
     * @var ObjectRepository|\PHPUnit_Framework_MockObject_MockObject
31
     */
32
    private $repository;
33
34
    public function setUp()
35
    {
36
        $this->repository = $this->getMock(ObjectRepository::class);
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

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...
37
38
        $this->om = $this->getMock(ObjectManager::class);
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

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...
39
        $this->om->method('getRepository')
40
            ->with(Content::class)
41
            ->willReturn($this->repository);
42
    }
43
44
    public function testUpdateFlushesObject()
45
    {
46
        $manager = new ContentManager($this->om);
47
48
        $content = new Content();
49
50
        $this->om->method('contains')
51
            ->with($content)
52
            ->willReturn(true);
53
54
        $this->om->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
55
            ->method('flush')
56
            ->with($content);
57
58
        $manager->update($content);
59
    }
60
61
    public function testUpdateDetachesObject()
62
    {
63
        $manager = new ContentManager($this->om);
64
65
        $content = new Content();
66
        $managedContent = new Content();
67
68
        $this->om->method('contains')
69
            ->with($content)
70
            ->willReturn(false);
71
72
        $this->om->expects($this->at(1))
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
73
            ->method('merge')
74
            ->with($content)
75
            ->willReturn($managedContent);
76
77
        $this->om->expects($this->at(2))
78
            ->method('flush')
79
            ->with($managedContent);
80
81
        $this->om->expects($this->at(3))
82
            ->method('detach')
83
            ->with($managedContent);
84
85
        $manager->update($content);
86
    }
87
88
    public function testGetReturnsFoundContentByNameAndLocale()
89
    {
90
        $manager = new ContentManager($this->om);
91
92
        $expectedContent = new Content();
93
94
        $this->repository->method('findOneBy')
95
            ->with(['name' => 'name', 'locale' => 'en'])
96
            ->willReturn($expectedContent);
97
98
        $content = $manager->get('name', 'en', 'text');
99
100
        $this->assertSame($expectedContent, $content);
101
    }
102
103
    public function testGetCreatesNewContent()
104
    {
105
        $manager = new ContentManager($this->om);
106
107
        $expectedContent = new Content();
108
        $expectedContent->setName('name')
109
            ->setText('text')
110
            ->setLocale('en');
111
112
        $this->repository->method('findOneBy')
113
            ->with(['name' => 'name', 'locale' => 'en'])
114
            ->willReturn(null);
115
116
        $this->om->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
117
            ->method('persist')
118
            ->with(
119
                $this->callback(
120
                    function ($value) use ($expectedContent) {
121
                        return $value == $expectedContent;
122
                    }
123
                )
124
            );
125
126
        $this->om->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
127
            ->method('flush')
128
            ->with(
129
                $this->callback(
130
                    function ($value) use ($expectedContent) {
131
                        return $value == $expectedContent;
132
                    }
133
                )
134
            );
135
136
        $content = $manager->get('name', 'en', 'text');
137
138
        $this->assertEquals($expectedContent, $content);
139
    }
140
141
    public function testGetUsesNameForDefaultWhenNotSpecified()
142
    {
143
        $manager = new ContentManager($this->om);
144
145
        $expectedContent = new Content();
146
        $expectedContent->setName('name')
147
            ->setText('name')
148
            ->setLocale('en');
149
150
        $this->repository->method('findOneBy')
151
            ->with(['name' => 'name', 'locale' => 'en'])
152
            ->willReturn(null);
153
154
        $content = $manager->get('name', 'en');
155
156
        $this->assertEquals($expectedContent, $content);
157
    }
158
159
    public function testGetDetachesExistingObject()
160
    {
161
        $manager = new ContentManager($this->om);
162
163
        $content = new Content();
164
165
        $this->repository->method('findOneBy')
166
            ->with(['name' => 'name', 'locale' => 'en'])
167
            ->willReturn($content);
168
169
        $this->om->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
170
            ->method('detach')
171
            ->with($content);
172
173
        $manager->get('name', 'en', 'text');
174
    }
175
176
    public function testGetDetachesNewObject()
177
    {
178
        $manager = new ContentManager($this->om);
179
180
        $this->repository->method('findOneBy')
181
            ->with(['name' => 'name', 'locale' => 'en'])
182
            ->willReturn(null);
183
184
        $content = new Content();
185
        $content->setName('name')
186
            ->setText('text')
187
            ->setLocale('en');
188
189
        $this->om->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Persistence\ObjectManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
190
            ->method('detach')
191
            ->with(
192
                $this->callback(
193
                    function ($value) use ($content) {
194
                        return $value == $content;
195
                    }
196
                )
197
            );
198
199
        $manager->get('name', 'en', 'text');
200
    }
201
202
    public function testGetGuessesLocaleFromRequest()
203
    {
204
        $requests = new RequestStack();
205
        $request = new Request();
206
        $request->setLocale('en');
207
        $requests->push($request);
208
209
        $manager = new ContentManager($this->om, $requests);
210
211
        $content = $manager->get('name');
212
213
        $this->assertSame('en', $content->getLocale());
214
    }
215
216
    public function testGetThrowsMissingLocaleException()
217
    {
218
        $this->setExpectedException(MissingLocaleException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

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...
219
220
        $manager = new ContentManager($this->om);
221
        $manager->get('name');
222
    }
223
}
224