Passed
Pull Request — master (#173)
by
unknown
02:46
created

PropertyTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Functional\Bundle\Extractor;
4
5
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6
use Zenstruck\Foundry\Bundle\Extractor\DoctrineTypes;
7
use Zenstruck\Foundry\Bundle\Extractor\Property;
8
9
class PropertyTest extends KernelTestCase
10
{
11
    /**
12
     * @var Property|object|null
13
     */
14
    private $property;
15
16
    protected function setUp(): void
17
    {
18
        self::bootKernel();
19
        $em = static::getContainer()->get('doctrine.orm.default_entity_manager');
20
        $this->property = new Property($em);
0 ignored issues
show
Bug introduced by
It seems like $em can also be of type null; however, parameter $em of Zenstruck\Foundry\Bundle...Property::__construct() does only seem to accept Doctrine\ORM\EntityManagerInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

20
        $this->property = new Property(/** @scrutinizer ignore-type */ $em);
Loading history...
21
    }
22
23
    /**
24
     * @before
25
     */
26
    public function skipIfNotUsingFoundryBundle(): void
27
    {
28
        if (!\getenv('KERNEL_CLASS')) {
29
            $this->markTestSkipped('App Kernel not found.');
30
        }
31
32
        if (!\getenv('USE_FOUNDRY_BUNDLE')) {
33
            $this->markTestSkipped('ZenstruckFoundryBundle not enabled.');
34
        }
35
    }
36
37
    /**
38
     * @test
39
     * @dataProvider doctrineTypes
40
     */
41
    public function generated_faker_method(string $doctrineType)
42
    {
43
        $createdFakerMethodAsString = $this->property->createFakerMethodFromDoctrineType($doctrineType);
0 ignored issues
show
Bug introduced by
The method createFakerMethodFromDoctrineType() does not exist on null. ( Ignorable by Annotation )

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

43
        /** @scrutinizer ignore-call */ 
44
        $createdFakerMethodAsString = $this->property->createFakerMethodFromDoctrineType($doctrineType);

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...
44
45
        $this->assertEquals(DoctrineTypes::DOCTRINE_TYPES[$doctrineType], $createdFakerMethodAsString);
46
    }
47
48
    public function doctrineTypes()
49
    {
50
        return [
51
            ['ARRAY'],
52
            ['ASCII_STRING'],
53
            ['BIGINT'],
54
            ['BLOB'],
55
            ['BOOLEAN'],
56
            ['DATE_MUTABLE'],
57
            ['DATE_IMMUTABLE'],
58
            ['DATETIME_MUTABLE'],
59
            ['DATETIME_IMMUTABLE'],
60
            ['DATETIMETZ_MUTABLE'],
61
            ['DATETIMETZ_IMMUTABLE'],
62
            ['DECIMAL'],
63
            ['FLOAT'],
64
            ['INTEGER'],
65
            ['JSON'],
66
            ['JSON_ARRAY'],
67
            ['SIMPLE_ARRAY'],
68
            ['SMALLINT'],
69
            ['STRING'],
70
            ['TEXT'],
71
            ['TIME_MUTABLE'],
72
            ['TIME_IMMUTABLE'],
73
        ];
74
    }
75
}
76