Skip to content

Commit

Permalink
[TASK] Check coverage (FriendsOfTYPO3#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer authored Nov 22, 2018
1 parent 5213bdb commit 46a05fb
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 24 deletions.
41 changes: 41 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
filter:
excluded_paths:
- 'Documentation/*'
- 'Tests/*'
paths:
- 'Classes/*'
tools:

external_code_coverage:
timeout: 2400
runs: 7

php_cpd:
enabled: true

php_code_sniffer:
enabled: true
config:
standard: PSR2

php_cs_fixer:
enabled: true

php_hhvm:
enabled: true
config:
use_undeclared_constant: false

php_mess_detector:
enabled: true
config:
controversial_rules:
superglobals: false

php_pdepend:
enabled: true

php_analyzer:
enabled: true

sensiolabs_security_checker: true
28 changes: 22 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,45 @@ before_install:
- composer --version

before_script:
- phpenv config-rm xdebug.ini
- composer require "typo3/minimal:${TYPO3_VERSION}"
- composer require "typo3/testing-framework:${TESTING_FRAMEWORK}"
- if [[ "$COVERAGE" == "1" ]]; then composer require "phpunit/phpcov"; fi
- mkdir cov
# Restore composer.json
- git checkout composer.json
# - export TYPO3_PATH_WEB=$PWD/.Build/Web

script:
- >
echo;
echo "Running unit tests";
.Build/bin/phpunit --colors -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml Tests/Unit/
if [[ "$COVERAGE" == "0" ]]; then
echo;
echo "Running unit tests";
.Build/bin/phpunit --colors -c Build/UnitTests.xml Tests/Unit/
fi
- >
if [[ "$COVERAGE" == "1" ]]; then
echo;
echo "Running unit tests";
.Build/bin/phpunit --coverage-php cov/coverage-unit.cov --colors -c Build/UnitTests.xml Tests/Unit/
fi
- >
echo;
echo "Running php lint";
find . -name \*.php ! -path "./.Build/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;
- >
if [[ "$COVERAGE" == "1" ]]; then
echo;
export typo3DatabaseName="typo3";
export typo3DatabaseHost="localhost";
export typo3DatabaseUsername="root";
export typo3DatabasePassword="";
.Build/bin/phpunit --colors -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml Tests/Functional/
.Build/bin/phpunit --coverage-php cov/coverage-functional.cov --colors -c Build/FunctionalTests.xml Tests/Functional/
fi
after_script:
- >
if [[ "$COVERAGE" == "1" ]]; then
echo;
.Build/bin/phpcov merge cov --clover build/logs/clover.xml
travis_retry php .Build/bin/php-coveralls -v
fi
39 changes: 39 additions & 0 deletions Build/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
Functional test suites setup
Functional tests should extend from \TYPO3\TestingFramework\Core\Tests\FunctionalTestCase,
take a look at this class for further documentation on how to run the suite.
TYPO3 CMS functional test suite also needs phpunit bootstrap code, the
file is located next to this .xml as FunctionalTestsBootstrap.php
-->
<phpunit
backupGlobals="true"
bootstrap="../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
beStrictAboutTestsThatDoNotTestAnything="false"
>
<testsuites>
<testsuite name="Core tests">
<directory>../Tests/Functional/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>../Classes/</directory>
<exclude>
<directory>../Classes/Updates</directory>
<file>../Classes/Controller/LegacyPluginController.php</file>
<file>../Classes/Hooks/FormEngine/LegacyPluginSelector.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
32 changes: 32 additions & 0 deletions Build/UnitTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<phpunit
backupGlobals="true"
bootstrap="../.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
beStrictAboutTestsThatDoNotTestAnything="false"
>
<testsuites>
<testsuite name="tests">
<directory>../Tests/Unit/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>../Classes/</directory>
<exclude>
<directory>../Classes/Updates</directory>
<file>../Classes/Controller/LegacyPluginController.php</file>
<file>../Classes/Hooks/FormEngine/LegacyPluginSelector.php</file>
</exclude>
</whitelist>
</filter>

</phpunit>
9 changes: 9 additions & 0 deletions BuildLocal/FunctionalTests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@
<directory>../Tests/Functional/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>../Classes/</directory>
<exclude>
<file>../Classes/Controller/LegacyPluginController.php</file>
<file>../Classes/Hooks/FormEngine/LegacyPluginSelector.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
2 changes: 2 additions & 0 deletions BuildLocal/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
<whitelist>
<directory>../Classes/</directory>
<exclude>
<directory>../Classes/Updates</directory>
<file>../Classes/Controller/LegacyPluginController.php</file>
<file>../Classes/Hooks/FormEngine/LegacyPluginSelector.php</file>
</exclude>
</whitelist>
</filter>
Expand Down
34 changes: 31 additions & 3 deletions Classes/Service/CategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function __construct()
*
* @param string $idList list of category ids to start
* @param int $counter
* @param string $additionalWhere additional where clause
* @return string comma separated list of category ids
*/
public function getChildrenCategories($idList, int $counter = 0)
Expand Down Expand Up @@ -75,7 +74,10 @@ protected function getChildrenCategoriesRecursive($idList, $counter = 0): string

// add id list to the output
if ($counter === 0) {
$result[] = $idList;
$newList = $this->getUidListFromRecords($idList);
if ($newList) {
$result[] = $newList;
}
}

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
Expand All @@ -91,7 +93,7 @@ protected function getChildrenCategoriesRecursive($idList, $counter = 0): string
while ($row = $res->fetch()) {
$counter++;
if ($counter > 10000) {
$this->timeTracker->setTSlogMessage('EXT:news: one or more recursive categories where found');
$this->timeTracker->setTSlogMessage('EXT:tt_address: one or more recursive categories where found');
return implode(',', $result);
}
$subcategories = $this->getChildrenCategoriesRecursive($row['uid'], $counter);
Expand All @@ -101,4 +103,30 @@ protected function getChildrenCategoriesRecursive($idList, $counter = 0): string
$result = implode(',', $result);
return $result;
}

/**
* Fetch ids again from DB to avoid false positives
*
* @param string $idList
* @return string
*/
protected function getUidListFromRecords(string $idList): string
{
$list = [];
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_category');
$rows = $queryBuilder
->select('uid')
->from('sys_category')
->where(
$queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter(explode(',', $idList), Connection::PARAM_INT_ARRAY))
)
->execute()
->fetchAll();
foreach ($rows as $row) {
$list[] = $row['uid'];
}

return implode(',', $list);
}
}
25 changes: 11 additions & 14 deletions Classes/Utility/TypoScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,36 @@ class TypoScript
{

/**
* @param array $base
* @param array $overload
* @param array $previousData
* @param array $tsData
* @return array
*/
public function override(array $base, array $overload)
public function override(array $previousData, array $tsData)
{
$validFields = GeneralUtility::trimExplode(',', $overload['settings']['overrideFlexformSettingsIfEmpty'], true);
$validFields = GeneralUtility::trimExplode(',', $tsData['settings']['overrideFlexformSettingsIfEmpty'], true);
foreach ($validFields as $fieldName) {
// Multilevel field
if (strpos($fieldName, '.') !== false) {
$keyAsArray = explode('.', $fieldName);

$foundInCurrentTs = $this->getValue($base, $keyAsArray);
$foundInCurrentTs = $this->getValue($previousData, $keyAsArray);

if (is_string($foundInCurrentTs) && strlen($foundInCurrentTs) === 0) {
$foundInOriginal = $this->getValue($overload['settings'], $keyAsArray);
$foundInOriginal = $this->getValue($tsData['settings'], $keyAsArray);
if ($foundInOriginal) {
$base = $this->setValue($base, $keyAsArray, $foundInOriginal);
$previousData = $this->setValue($previousData, $keyAsArray, $foundInOriginal);
}
}
} else {
// if flexform setting is empty and value is available in TS
if ((!isset($base[$fieldName]) || (strlen($base[$fieldName]) === 0))
&& isset($overload['settings'][$fieldName])
if ((!isset($previousData[$fieldName]) || (strlen($previousData[$fieldName]) === 0))
&& isset($tsData['settings'][$fieldName])
) {
$base[$fieldName] = $overload['settings'][$fieldName];
$previousData[$fieldName] = $tsData['settings'][$fieldName];
}
}
}
return $base;
return $previousData;
}

/**
Expand Down Expand Up @@ -108,9 +108,6 @@ private function setValueByReference(array &$array, array $path, $value)
{
while (count($path) > 1) {
$key = array_shift($path);
if (!isset($array[$key])) {
$array[$key] = [];
}
$array = &$array[$key];
}

Expand Down
Loading

0 comments on commit 46a05fb

Please sign in to comment.