Completed
Pull Request — master (#133)
by Simone
05:25
created

testPropertyCannotContainWrongCustomValidato()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 15

Duplication

Lines 26
Ratio 100 %

Importance

Changes 0
Metric Value
dl 26
loc 26
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of sensorario/resources repository
5
 *
6
 * (c) Simone Gentili <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sensorario\Resources\Test\Resources;
13
14
use PHPUnit\Framework\TestCase;
15
use Sensorario\Resources\Configurator;
16
use Sensorario\Resources\Container;
17
use Sensorario\Resources\Resource;
18
use Sensorario\Resources\Rulers\Ruler;
19
20
class RulerTest extends TestCase
21
{
22
    /**
23
     * @expectedException \Sensorario\Resources\Exceptions\InvalidCustomValidatorException
24
     * @expectedExceptionMessage Oops! `custom-validator` custom validator is not available. Only email is.
25
     */
26 View Code Duplication
    public function testPropertyCannotContainWrongCustomValidato()
0 ignored issues
show
Duplication introduced by
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...
27
    {
28
        $configurator = new Configurator(
29
            'foo',
30
            new Container([
31
                'resources' => [
32
                    'foo' => [
33
                        'constraints' => [
34
                            'allowed' => [
35
                                'property_name',
36
                            ],
37
                            'rules' => [
38
                                'property_name' => [
39
                                    'custom-validator' => 'foo',
40
                                ]
41
                            ]
42
                        ],
43
                    ],
44
                ]
45
            ])
46
        );
47
48
        Resource::box([
49
            'property_name' => '42',
50
        ], $configurator);
51
    }
52
53
    public function setUp()
54
    {
55
        $this->ruler = new Ruler();
0 ignored issues
show
Bug introduced by
The property ruler does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
56
    }
57
58
    /**
59
     * @expectedException \Sensorario\Resources\Exceptions\UndefinedResourceException
60
     * @expectedExceptionMessage Oops! Cant get rule without resource
61
     */
62
    public function testCantGetRuleWithoutRecource()
63
    {
64
        $this->ruler->getRuleFromResource();
65
    }
66
}
67