GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ProxiesTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 68
c 1
b 0
f 0
dl 0
loc 110
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A proxyObjectsCanGetGettersAndSetters() 0 39 1
A getClassMetaDatas() 0 9 2
A setupProxyFactory() 0 8 1
A getTestEntityFqns() 0 9 1
A setup() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\A;
6
7
use Doctrine\Common\Proxy\Proxy as DeprecatedProxy;
8
use Doctrine\ORM\Proxy\Proxy;
9
use Doctrine\ORM\Proxy\ProxyFactory;
10
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
11
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest;
12
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest;
13
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator;
14
15
use function array_map;
16
17
/**
18
 * @coversNothing
19
 */
20
class ProxiesTest extends AbstractLargeTest
21
{
22
    public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_MEDIUM . '/ProxiesTest/';
23
    protected static $buildOnce = true;
24
    /**
25
     * @var ProxyFactory
26
     */
27
    private $proxyFactory;
28
    /**
29
     * It is a Proxy, the others are just to make PHPStan happy
30
     *
31
     * @var Proxy|DeprecatedProxy|EntityInterface
32
     */
33
    private $proxy;
34
    private $testEntityFqns;
35
36
    public function setup()
37
    {
38
        parent::setUp();
39
        if (false === self::$built) {
40
            $this->getTestCodeGenerator()
41
                 ->copyTo(self::WORK_DIR);
42
            self::$built = true;
43
        }
44
        $this->setupCopiedWorkDirAndCreateDatabase();
45
        $this->setupProxyFactory();
46
        $this->testEntityFqns = $this->getTestEntityFqns();
47
        $this->proxyFactory->generateProxyClasses($this->getClassMetaDatas());
48
        $testEntity = current($this->testEntityFqns);
49
        $this->getEntitySaver()->save($this->createEntity($testEntity));
50
        $this->proxy = $this->proxyFactory->getProxy($testEntity, ['id' => 1]);
51
    }
52
53
    private function setupProxyFactory(): void
54
    {
55
        $proxyDir = $this->copiedWorkDir . '/proxies';
56
        mkdir($proxyDir, 0777, true);
57
        $this->proxyFactory = new ProxyFactory(
58
            $this->getEntityManager(),
59
            $proxyDir,
60
            $this->copiedRootNamespace . '\\Proxies'
61
        );
62
    }
63
64
    private function getTestEntityFqns(): array
65
    {
66
        $copiedRootNamespace = $this->copiedRootNamespace;
67
68
        return array_map(
69
            static function (string $entityFqn) use ($copiedRootNamespace): string {
70
                return $copiedRootNamespace . $entityFqn;
71
            },
72
            TestCodeGenerator::TEST_ENTITIES
73
        );
74
    }
75
76
    private function getClassMetaDatas(): array
77
    {
78
        $return        = [];
79
        $entityManager = $this->getEntityManager();
80
        foreach ($this->testEntityFqns as $entityFqn) {
81
            $return[] = $entityManager->getClassMetadata($entityFqn);
82
        }
83
84
        return $return;
85
    }
86
87
    /**
88
     * @test
89
     * @large
90
     */
91
    public function proxyObjectsCanGetGettersAndSetters(): void
92
    {
93
        $expectedSetters = [
94
            'getAttributesAddress' => 'setAttributesAddress',
95
            'getAttributesEmails'  => 'setAttributesEmails',
96
            'getCompanyDirector'   => 'setCompanyDirector',
97
            'getLargeRelation'     => 'setLargeRelation',
98
            'getId'                => 'setId',
99
            'getString'            => 'setString',
100
            'getDatetime'          => 'setDatetime',
101
            'getFloat'             => 'setFloat',
102
            'getDecimal'           => 'setDecimal',
103
            'getInteger'           => 'setInteger',
104
            'getText'              => 'setText',
105
            'isBoolean'            => 'setBoolean',
106
            'getArray'             => 'setArray',
107
            'getObject'            => 'setObject',
108
        ];
109
        $actualSetters   = $this->proxy::getDoctrineStaticMeta()->getSetters();
0 ignored issues
show
Bug introduced by
The method getDoctrineStaticMeta() does not exist on Doctrine\Common\Proxy\Proxy. ( Ignorable by Annotation )

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

109
        $actualSetters   = $this->proxy::/** @scrutinizer ignore-call */ getDoctrineStaticMeta()->getSetters();

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 getDoctrineStaticMeta() does not exist on Doctrine\ORM\Proxy\Proxy. ( Ignorable by Annotation )

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

109
        $actualSetters   = $this->proxy::/** @scrutinizer ignore-call */ getDoctrineStaticMeta()->getSetters();

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...
110
        self::assertSame($expectedSetters, $actualSetters);
111
        $expectedGetters = [
112
            'getAttributesAddress',
113
            'getAttributesEmails',
114
            'getCompanyDirector',
115
            'getLargeRelation',
116
            'getId',
117
            'getUuid',
118
            'getString',
119
            'getDatetime',
120
            'getFloat',
121
            'getDecimal',
122
            'getInteger',
123
            'getText',
124
            'isBoolean',
125
            'getArray',
126
            'getObject',
127
        ];
128
        $actualGetters   = $this->proxy::getDoctrineStaticMeta()->getGetters();
129
        self::assertSame($expectedGetters, $actualGetters);
130
    }
131
}
132