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 (#796)
by
unknown
04:18
created

FunctionalTestCase::getDlfConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

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

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

136
        /** @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...
137
        file_put_contents($siteConfigPath . '/config.yaml', Yaml::dump($siteConfig));
138
    }
139
140
    protected function initializeRepository(string $className, int $storagePid)
141
    {
142
        $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

142
        $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...
143
144
        $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

144
        $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...
145
        $querySettings->setStoragePageIds([$storagePid]);
146
        $repository->setDefaultQuerySettings($querySettings);
147
148
        return $repository;
149
    }
150
151
    protected function importSolrDocuments(Solr $solr, string $path)
152
    {
153
        $jsonDocuments = json_decode(file_get_contents($path), true);
154
155
        $updateQuery = $solr->service->createUpdate();
156
        $documents = array_map(function ($jsonDoc) use ($updateQuery) {
157
            $document = $updateQuery->createDocument();
158
            foreach ($jsonDoc as $key => $value) {
159
                $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

159
                $document->/** @scrutinizer ignore-call */ 
160
                           setField($key, $value);
Loading history...
160
            }
161
            if (isset($jsonDoc['collection'])) {
162
                $document->setField('collection_faceting', $jsonDoc['collection']);
163
            }
164
            return $document;
165
        }, $jsonDocuments);
166
        $updateQuery->addDocuments($documents);
167
        $updateQuery->addCommit();
168
        $solr->service->update($updateQuery);
169
    }
170
171
    /**
172
     * Assert that $sub is recursively contained within $super.
173
     */
174
    protected function assertArrayMatches(array $sub, array $super, string $message = '')
175
    {
176
        $this->assertEquals($sub, ArrayUtility::intersectRecursive($super, $sub), $message);
177
    }
178
}
179