generateReturnsIntegerIfParameterCanBeConvertedToInteger()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TildBJ\Seeder\Tests\Unit\Generator;
4
5
use TildBJ\Seeder\Generator;
6
use TildBJ\Seeder\Generator\MethodNameGenerator;
7
use Nimut\TestingFramework\TestCase\UnitTestCase;
8
9
/**
10
 * Class MethodNameGeneratorTest
11
 *
12
 * @package TildBJ\Seeder\Tests\Generator
13
 */
14
class MethodNameGeneratorTest extends UnitTestCase
15
{
16
    /**
17
     * @var Generator $subject
18
     */
19
    protected $subject;
20
21
    public function setUp()
22
    {
23
        $faker = $this->createMock(\TildBJ\Seeder\Faker::class);
24
        $this->subject = new MethodNameGenerator($faker);
0 ignored issues
show
Documentation introduced by
$faker is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Faker>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25
    }
26
27
    /**
28
     * @method generate
29
     * @test
30
     */
31
    public function generateReturnsIntegerIfParameterIsInteger()
32
    {
33
        $this->assertSame(4, $this->subject->generate(4));
34
    }
35
36
    /**
37
     * @method generate
38
     * @test
39
     */
40
    public function generateReturnsIntegerIfParameterCanBeConvertedToInteger()
41
    {
42
        $this->assertSame(4, $this->subject->generate('4'));
43
    }
44
45
    /**
46
     * @method generate
47
     * @test
48
     */
49
    public function generateReturnsMethodName()
50
    {
51
        $this->assertSame('$faker->getName()', $this->subject->generate('name'));
52
    }
53
54
    /**
55
     * @method generate
56
     * @test
57
     */
58
    public function generateReturnsNullWithInvalidParameter()
59
    {
60
        $faker = $this->createMock(\TildBJ\Seeder\Faker::class);
61
        $faker->method('get')->willThrowException(new \TildBJ\Seeder\Provider\NotFoundException());
62
        $generator = new MethodNameGenerator($faker);
0 ignored issues
show
Documentation introduced by
$faker is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Faker>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
        $this->assertSame(null, $generator->generate('InvalidParameter'));
64
    }
65
}
66