Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

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.
Passed
Pull Request — master (#813)
by Alexander
04:01
created

FunctionalTestCase::importSolrDocuments()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 18
rs 9.8333
1
<?php
2
3
namespace Kitodo\Dlf\Tests\Functional;
4
5
use GuzzleHttp\Client as HttpClient;
6
use Kitodo\Dlf\Common\Solr;
7
use Symfony\Component\Yaml\Yaml;
8
use TYPO3\CMS\Core\Utility\GeneralUtility;
9
use TYPO3\CMS\Extbase\Object\ObjectManager;
10
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
11
12
/**
13
 * Base class for functional test cases. This provides some common configuration
14
 * and collects utility methods for functional tests.
15
 */
16
class FunctionalTestCase extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
17
{
18
    protected $testExtensionsToLoad = [
19
        'typo3conf/ext/dlf',
20
    ];
21
22
    protected $configurationToUseInTestInstance = [
23
        'SYS' => [
24
            'caching' => [
25
                'cacheConfigurations' => [
26
                    'tx_dlf_doc' => [
27
                        'backend' => \TYPO3\CMS\Core\Cache\Backend\NullBackend::class,
28
                    ],
29
                ],
30
            ],
31
        ],
32
        'EXTENSIONS' => [
33
            'dlf' => [], // = $this->getDlfConfiguration(), set in constructor
34
        ],
35
        'DB' => [
36
            'Connections' => [
37
                'Default' => [
38
                    // TODO: This is taken from the base class, minus "ONLY_FULL_GROUP_BY"; should probably rather be changed in DocumentRepository::getOaiDocumentList
39
                    'initCommands' => 'SET SESSION sql_mode = \'STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE\';',
40
                ],
41
            ],
42
        ],
43
    ];
44
45
    /**
46
     * By default, the testing framework wraps responses into a JSON object
47
     * that contains status code etc. as fields. Set this field to true to avoid
48
     * this behavior by not loading the json_response extension.
49
     *
50
     * @var bool
51
     */
52
    protected $disableJsonWrappedResponse = false;
53
54
    /** @var ObjectManager */
55
    protected $objectManager;
56
57
    /**
58
     * @var string
59
     */
60
    protected $baseUrl;
61
62
    /**
63
     * @var HttpClient
64
     */
65
    protected $httpClient;
66
67
    public function __construct()
68
    {
69
        parent::__construct();
70
71
        $this->configurationToUseInTestInstance['EXTENSIONS']['dlf'] = $this->getDlfConfiguration();
72
73
        if ($this->disableJsonWrappedResponse) {
74
            $this->frameworkExtensionsToLoad = array_filter($this->frameworkExtensionsToLoad, function ($ext) {
0 ignored issues
show
Deprecated Code introduced by
The property TYPO3\TestingFramework\C...ameworkExtensionsToLoad has been deprecated. ( Ignorable by Annotation )

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

74
            /** @scrutinizer ignore-deprecated */ $this->frameworkExtensionsToLoad = array_filter($this->frameworkExtensionsToLoad, function ($ext) {
Loading history...
75
                return $ext !== 'Resources/Core/Functional/Extensions/json_response';
76
            });
77
        }
78
    }
79
80
    public function setUp(): void
81
    {
82
        parent::setUp();
83
84
        $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
85
86
        $this->baseUrl = 'http://web:8000/public/typo3temp/var/tests/functional-' . $this->identifier . '/';
87
        $this->httpClient = new HttpClient([
88
            'base_uri' => $this->baseUrl,
89
            'http_errors' => false,
90
        ]);
91
92
        $this->addSiteConfig('dlf-testing', $this->baseUrl);
93
    }
94
95
    protected function getDlfConfiguration()
96
    {
97
        return [
98
            'solrFieldAutocomplete' => 'autocomplete',
99
            'solrFieldCollection' => 'collection',
100
            'solrFieldDefault' => 'default',
101
            'solrFieldFulltext' => 'fulltext',
102
            'solrFieldGeom' => 'geom',
103
            'solrFieldId' => 'id',
104
            'solrFieldLicense' => 'license',
105
            'solrFieldLocation' => 'location',
106
            'solrFieldPage' => 'page',
107
            'solrFieldPartof' => 'partof',
108
            'solrFieldPid' => 'pid',
109
            'solrFieldPurl' => 'purl',
110
            'solrFieldRecordId' => 'record_id',
111
            'solrFieldRestrictions' => 'restrictions',
112
            'solrFieldRoot' => 'root',
113
            'solrFieldSid' => 'sid',
114
            'solrFieldTerms' => 'terms',
115
            'solrFieldThumbnail' => 'thumbnail',
116
            'solrFieldTimestamp' => 'timestamp',
117
            'solrFieldTitle' => 'title',
118
            'solrFieldToplevel' => 'toplevel',
119
            'solrFieldType' => 'type',
120
            'solrFieldUid' => 'uid',
121
            'solrFieldUrn' => 'urn',
122
            'solrFieldVolume' => 'volume',
123
124
            'solrHost' => getenv('dlfTestingSolrHost'),
125
        ];
126
    }
127
128
    protected function addSiteConfig($identifier, $baseUrl)
129
    {
130
        $siteConfig = Yaml::parseFile(__DIR__ . '/../Fixtures/siteconfig.yaml');
131
        $siteConfig['base'] = $baseUrl;
132
        $siteConfig['languages'][0]['base'] = $baseUrl;
133
134
        $siteConfigPath = $this->instancePath . '/typo3conf/sites/' . $identifier;
135
        @mkdir($siteConfigPath, 0775, true);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for mkdir(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

135
        /** @scrutinizer ignore-unhandled */ @mkdir($siteConfigPath, 0775, true);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
136
        file_put_contents($siteConfigPath . '/config.yaml', Yaml::dump($siteConfig));
137
    }
138
139
    protected function initializeRepository(string $className, int $storagePid)
140
    {
141
        $repository = $this->objectManager->get($className);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Object\ObjectManager::get() has been deprecated: since TYPO3 10.4, will be removed in version 12.0 ( Ignorable by Annotation )

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

141
        $repository = /** @scrutinizer ignore-deprecated */ $this->objectManager->get($className);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
142
143
        $querySettings = $this->objectManager->get(Typo3QuerySettings::class);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Object\ObjectManager::get() has been deprecated: since TYPO3 10.4, will be removed in version 12.0 ( Ignorable by Annotation )

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

143
        $querySettings = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(Typo3QuerySettings::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
144
        $querySettings->setStoragePageIds([$storagePid]);
145
        $repository->setDefaultQuerySettings($querySettings);
146
147
        return $repository;
148
    }
149
150
    protected function importSolrDocuments(Solr $solr, string $path)
151
    {
152
        $jsonDocuments = json_decode(file_get_contents($path), true);
153
154
        $updateQuery = $solr->service->createUpdate();
155
        $documents = array_map(function ($jsonDoc) use ($updateQuery) {
156
            $document = $updateQuery->createDocument();
157
            foreach ($jsonDoc as $key => $value) {
158
                $document->setField($key, $value);
0 ignored issues
show
Bug introduced by
The method setField() does not exist on Solarium\Core\Query\DocumentInterface. It seems like you code against a sub-type of Solarium\Core\Query\DocumentInterface such as Solarium\Plugin\MinimumScoreFilter\Document or Solarium\QueryType\Update\Query\Document. ( Ignorable by Annotation )

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

158
                $document->/** @scrutinizer ignore-call */ 
159
                           setField($key, $value);
Loading history...
159
            }
160
            if (isset($jsonDoc['collection'])) {
161
                $document->setField('collection_faceting', $jsonDoc['collection']);
162
            }
163
            return $document;
164
        }, $jsonDocuments);
165
        $updateQuery->addDocuments($documents);
166
        $updateQuery->addCommit();
167
        $solr->service->update($updateQuery);
168
    }
169
}
170