Completed
Push — master ( 6ddc93...bf8455 )
by Jan
22:23 queued 17:38
created

ColumnSecurityTest::testGetPlaceholderDBElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 9.9666
1
<?php
2
/**
3
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4
 *
5
 * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
20
 */
21
22
namespace App\Tests\Security\Annotations;
23
24
25
use App\Entity\Attachments\AttachmentType;
26
use App\Security\Annotations\ColumnSecurity;
27
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
29
class ColumnSecurityTest extends TestCase
30
{
31
    public function testGetReadOperation()
32
    {
33
        $annotation = new ColumnSecurity();
34
        $this->assertEquals('read', $annotation->getReadOperationName(), 'A new annotation must return read');
35
        $annotation->read = 'overwritten';
36
        $this->assertEquals('overwritten', $annotation->getReadOperationName());
37
        $annotation->prefix = 'prefix';
38
        $this->assertEquals('prefix.overwritten', $annotation->getReadOperationName());
39
    }
40
41
    public function testGetEditOperation()
42
    {
43
        $annotation = new ColumnSecurity();
44
        $this->assertEquals('edit', $annotation->getEditOperationName(), 'A new annotation must return read');
45
        $annotation->edit = 'overwritten';
46
        $this->assertEquals('overwritten', $annotation->getEditOperationName());
47
        $annotation->prefix = 'prefix';
48
        $this->assertEquals('prefix.overwritten', $annotation->getEditOperationName());
49
    }
50
51
    public function placeholderScalarDataProvider() : array
52
    {
53
        return [
54
            ['string', '???'],
55
            ['integer', 0],
56
            ['int', 0],
57
            ['float', 0.0],
58
            ['object', null],
59
            ['bool', false],
60
            ['boolean', false],
61
            //['datetime', (new \DateTime())->setTimestamp(0)]
62
        ];
63
    }
64
65
    /**
66
     * @dataProvider placeholderScalarDataProvider
67
     * @param string $type
68
     * @param $expected_value
69
     */
70
    public function testGetPlaceholderScalar(string $type, $expected_value)
71
    {
72
        $annotation = new ColumnSecurity();
73
        $annotation->type = $type;
74
        $this->assertEquals($expected_value, $annotation->getPlaceholder());
75
    }
76
77
    public function testGetPlaceholderSpecifiedValue()
78
    {
79
        $annotation = new ColumnSecurity();
80
        $annotation->placeholder = 3434;
81
        $this->assertEquals(3434, $annotation->getPlaceholder());
82
83
        $annotation->placeholder = [323];
0 ignored issues
show
Documentation Bug introduced by
It seems like array(323) of type array<integer,integer> is incompatible with the declared type string of property $placeholder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
84
        $this->assertCount(1, $annotation->getPlaceholder());
85
86
        //If a placeholder is specified we allow every type
87
        $annotation->type = "type2";
88
        $annotation->placeholder = 'invalid';
89
        $this->assertEquals('invalid', $annotation->getPlaceholder());
90
    }
91
92
    public function testGetPlaceholderDBElement()
93
    {
94
        $annotation = new ColumnSecurity();
95
        $annotation->type = AttachmentType::class;
96
97
        /** @var AttachmentType $placeholder */
98
        $placeholder = $annotation->getPlaceholder();
99
        $this->assertInstanceOf(AttachmentType::class, $placeholder);
100
        $this->assertEquals('???', $placeholder->getName());
101
102
        $annotation->placeholder = 'test';
103
        $placeholder = $annotation->getPlaceholder();
104
        $this->assertInstanceOf(AttachmentType::class, $placeholder);
105
        $this->assertEquals('test', $placeholder->getName());
0 ignored issues
show
Bug introduced by
The method getName() does not exist on Doctrine\Common\Collections\ArrayCollection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
        $this->assertEquals('test', $placeholder->/** @scrutinizer ignore-call */ getName());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getName() does not exist on DateTime. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
        $this->assertEquals('test', $placeholder->/** @scrutinizer ignore-call */ getName());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
    }
107
}