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.

Tests/Units/EnumTests.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
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Enum\Tests\Units;
12
13
use Cubiche\Core\Enum\Enum;
14
use Cubiche\Core\Enum\Tests\Fixtures\BadDefaultEnumFixture;
15
use Cubiche\Core\Enum\Tests\Fixtures\DefaultEnumFixture;
16
use Cubiche\Core\Enum\Tests\Fixtures\EnumFixture;
17
18
/**
19
 * Enum Tests Class.
20
 *
21
 * @author Ivannis Suárez Jerez <[email protected]>
22
 * @author Karel Osorio Ramírez <[email protected]>
23
 */
24
class EnumTests extends EnumTestCase
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function newDefaultTestedInstance()
30
    {
31
        return new EnumFixture(EnumFixture::FOO);
32
    }
33
34
    /**
35
     * Test value method.
36
     */
37 View Code Duplication
    public function testValue()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $this
40
            ->given($enum = new EnumFixture(EnumFixture::FOO))
41
            ->when($value = $enum->value())
42
            ->then()
43
                ->variable($value)
44
                    ->isEqualTo(EnumFixture::FOO)
45
        ;
46
    }
47
48
    /**
49
     * Test name method.
50
     */
51 View Code Duplication
    public function testName()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        $this
54
            ->given($enum = new EnumFixture(EnumFixture::FOO))
55
            ->when($name = $enum->name())
56
            ->then()
57
                ->variable($name)
58
                    ->isEqualTo('FOO')
59
        ;
60
    }
61
62
    /**
63
     * Test hashCode method.
64
     */
65 View Code Duplication
    public function testHashCode()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        $this
68
            ->given($enum = new EnumFixture(EnumFixture::FOO))
69
            ->when($hashCode = $enum->hashCode())
70
            ->then()
71
                ->variable($hashCode)
72
                    ->isEqualTo((string) $enum->value())
73
        ;
74
    }
75
76
    /**
77
     * Test __toString method.
78
     */
79 View Code Duplication
    public function testToString()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $this
82
            ->given($enum = new EnumFixture(EnumFixture::FOO))
83
            ->when($string = $enum->__toString())
84
            ->then()
85
                ->string($string)
86
                    ->isEqualTo((string) $enum->value())
87
        ;
88
    }
89
90
    /**
91
     * Test is method.
92
     */
93
    public function testIs()
94
    {
95
        $this
96
            ->given($enum = new EnumFixture(EnumFixture::FOO))
97
            ->then()
98
                ->boolean($enum->is(EnumFixture::FOO))
99
                    ->isTrue()
100
                ->boolean($enum->is(EnumFixture::BAR))
101
                    ->isFalse()
102
        ;
103
    }
104
105
    /**
106
     * Test isValidName method.
107
     */
108
    public function testIsValidName()
109
    {
110
        $this
111
            ->when($isValid = EnumFixture::isValidName('FOO'))
112
            ->then()
113
                ->boolean($isValid)
114
                    ->isTrue()
115
        ;
116
117
        $this
118
            ->when($isValid = EnumFixture::isValidName('ZOO'))
119
                ->then()
120
                ->boolean($isValid)
121
                ->isFalse()
122
        ;
123
124
        $this
125
            ->when($isValid = EnumFixture::isValidName('__DEFAULT'))
126
            ->then()
127
                ->boolean($isValid)
128
                    ->isFalse()
129
        ;
130
    }
131
132
    /**
133
     * Test names method.
134
     */
135
    public function testNames()
136
    {
137
        $this
138
            ->when($names = EnumFixture::names())
139
            ->then()
140
                ->array($names)
141
                    ->isEqualTo(array('FOO', 'BAR'))
142
        ;
143
    }
144
145
    /**
146
     * Test values method.
147
     */
148
    public function testValues()
149
    {
150
        $this
151
            ->when($values = EnumFixture::values())
152
            ->then()
153
                ->array($values)
154
                    ->isEqualTo(array('FOO' => EnumFixture::FOO(), 'BAR' => EnumFixture::BAR()))
155
        ;
156
    }
157
158
    /**
159
     * Test __DEFAULT method.
160
     */
161
    public function testDefault()
162
    {
163
        $this->equalityTest(EnumFixture::__DEFAULT(), EnumFixture::FOO());
164
        $this->equalityTest(DefaultEnumFixture::__DEFAULT(), DefaultEnumFixture::BAR());
165
166
        $this
167
            ->exception(function () {
168
                BadDefaultEnumFixture::__DEFAULT();
169
            })
170
                ->isInstanceof(\UnexpectedValueException::class)
171
            ->exception(function () {
172
                BadDefaultEnumFixture::BAZ();
173
            })
174
                ->isInstanceof(\BadMethodCallException::class)
175
        ;
176
    }
177
178
    /**
179
     * Test ensure method.
180
     */
181
    public function testEnsure()
182
    {
183
        $this->equalityTest(EnumFixture::ensure(EnumFixture::FOO()), EnumFixture::FOO());
184
        $this->equalityTest(EnumFixture::ensure(EnumFixture::FOO(), EnumFixture::BAR()), EnumFixture::FOO());
185
        $this->equalityTest(EnumFixture::ensure(), EnumFixture::__DEFAULT());
186
        $this->equalityTest(EnumFixture::ensure(null, EnumFixture::BAR()), EnumFixture::BAR());
187
188
        $this
189
            ->exception(function () {
190
                EnumFixture::ensure(DefaultEnumFixture::FOO());
191
            })
192
                ->isInstanceof(\InvalidArgumentException::class)
193
        ;
194
    }
195
196
    /**
197
     * @param Enum $enum1
198
     * @param Enum $enum2
199
     */
200
    protected function equalityTest(Enum $enum1, Enum $enum2)
201
    {
202
        $this
203
            ->given($enum1, $enum2)
204
            ->then()
205
                ->boolean($enum1->equals($enum2))
206
                    ->isTrue()
207
        ;
208
    }
209
}
210