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.
Completed
Push — master ( de1ea3...c23e92 )
by Sebastian
17s queued 15s
created

FunctionalTestCase::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
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
            'fileGrpImages' => 'DEFAULT,MAX',
100
            'fileGrpThumbs' => 'THUMBS',
101
            'fileGrpDownload' => 'DOWNLOAD',
102
            'fileGrpFulltext' => 'FULLTEXT',
103
            'fileGrpAudio' => 'AUDIO',
104
105
            'solrFieldAutocomplete' => 'autocomplete',
106
            'solrFieldCollection' => 'collection',
107
            'solrFieldDefault' => 'default',
108
            'solrFieldFulltext' => 'fulltext',
109
            'solrFieldGeom' => 'geom',
110
            'solrFieldId' => 'id',
111
            'solrFieldLicense' => 'license',
112
            'solrFieldLocation' => 'location',
113
            'solrFieldPage' => 'page',
114
            'solrFieldPartof' => 'partof',
115
            'solrFieldPid' => 'pid',
116
            'solrFieldPurl' => 'purl',
117
            'solrFieldRecordId' => 'record_id',
118
            'solrFieldRestrictions' => 'restrictions',
119
            'solrFieldRoot' => 'root',
120
            'solrFieldSid' => 'sid',
121
            'solrFieldTerms' => 'terms',
122
            'solrFieldThumbnail' => 'thumbnail',
123
            'solrFieldTimestamp' => 'timestamp',
124
            'solrFieldTitle' => 'title',
125
            'solrFieldToplevel' => 'toplevel',
126
            'solrFieldType' => 'type',
127
            'solrFieldUid' => 'uid',
128
            'solrFieldUrn' => 'urn',
129
            'solrFieldVolume' => 'volume',
130
131
            'solrHost' => getenv('dlfTestingSolrHost'),
132
        ];
133
    }
134
135
    protected function addSiteConfig($identifier, $baseUrl)
136
    {
137
        $siteConfig = Yaml::parseFile(__DIR__ . '/../Fixtures/siteconfig.yaml');
138
        $siteConfig['base'] = $baseUrl;
139
        $siteConfig['languages'][0]['base'] = $baseUrl;
140
141
        $siteConfigPath = $this->instancePath . '/typo3conf/sites/' . $identifier;
142
        @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

142
        /** @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...
143
        file_put_contents($siteConfigPath . '/config.yaml', Yaml::dump($siteConfig));
144
    }
145
146
    protected function initializeRepository(string $className, int $storagePid)
147
    {
148
        $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

148
        $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...
149
150
        $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

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

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