Skip to content

Commit

Permalink
Merge pull request #23780 from nextcloud/enh/ci/php8
Browse files Browse the repository at this point in the history
PHP8 CI
  • Loading branch information
rullzer authored Dec 8, 2020
2 parents 7e784af + a9ee98e commit fda6ffc
Show file tree
Hide file tree
Showing 26 changed files with 201 additions and 121 deletions.
20 changes: 10 additions & 10 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ steps:
commands:
- bash tests/drone-run-php-tests.sh || exit 0
- NOCOVERAGE=true TEST_SELECTION=NODB ./autotest.sh sqlite
#- name: nodb-php8.0
# image: nextcloudci/php8.0:latest
# commands:
# - bash tests/drone-run-php-tests.sh || exit 0
# - NOCOVERAGE=true TEST_SELECTION=NODB ./autotest.sh sqlite
- name: nodb-php8.0
image: nextcloudci/php8.0:latest
commands:
- bash tests/drone-run-php-tests.sh || exit 0
- NOCOVERAGE=true TEST_SELECTION=NODB ./autotest.sh sqlite

services:
- name: cache
Expand Down Expand Up @@ -293,11 +293,11 @@ steps:
commands:
- bash tests/drone-run-php-tests.sh || exit 0
- NOCOVERAGE=true TEST_SELECTION=DB ./autotest.sh sqlite
#- name: sqlite-php8.0
# image: nextcloudci/php8.0:latest
# commands:
# - bash tests/drone-run-php-tests.sh || exit 0
# - NOCOVERAGE=true TEST_SELECTION=DB ./autotest.sh sqlite
- name: sqlite-php8.0
image: nextcloudci/php8.0:latest
commands:
- bash tests/drone-run-php-tests.sh || exit 0
- NOCOVERAGE=true TEST_SELECTION=DB ./autotest.sh sqlite

services:
- name: cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
use OCP\Calendar\Room\IManager as IRoomManager;
use Test\TestCase;

interface tmpI extends IResource, IMetadataProvider {
}

class UpdateCalendarResourcesRoomsBackgroundJobTest extends TestCase {

/** @var UpdateCalendarResourcesRoomsBackgroundJob */
Expand Down Expand Up @@ -108,9 +111,9 @@ public function testRun() {
$backend3 = $this->createMock(IBackend::class);
$backend4 = $this->createMock(IBackend::class);

$res6 = $this->createMock([IResource::class, IMetadataProvider::class]);
$res7 = $this->createMock([IResource::class, IMetadataProvider::class]);
$res8 = $this->createMock([IResource::class, IMetadataProvider::class]);
$res6 = $this->createMock(tmpI::class);
$res7 = $this->createMock(tmpI::class);
$res8 = $this->createMock(tmpI::class);
$res9 = $this->createMock(IResource::class);

$backend2->method('getBackendIdentifier')
Expand Down
7 changes: 5 additions & 2 deletions apps/dav/tests/unit/CalDAV/Reminder/NotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ protected function setUp(): void {
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function ($string, $args) {
if (!is_array($args)) {
$args = [$args];
}
return vsprintf($string, $args);
});
$this->l10n->expects($this->any())
Expand Down Expand Up @@ -103,7 +106,7 @@ public function testGetName():void {
$this->assertEquals($this->notifier->getName(), 'Calendar');
}


public function testPrepareWrongApp(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Notification not from this app');
Expand All @@ -120,7 +123,7 @@ public function testPrepareWrongApp(): void {
$this->notifier->prepare($notification, 'en');
}


public function testPrepareWrongSubject() {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Unknown subject');
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Command/MoveCalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function testMove() {
'destinationuid' => 'user2',
]);

$this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
$this->assertStringContainsString("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
}

public function dataTestMoveWithDestinationNotPartOfGroup(): array {
Expand Down
7 changes: 4 additions & 3 deletions apps/encryption/lib/Crypto/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ public function decryptPrivateKey($privateKey, $password = '', $uid = '') {
*/
protected function isValidPrivateKey($plainKey) {
$res = openssl_get_privatekey($plainKey);
if (is_resource($res)) {
// TODO: remove resource check one php7.4 is not longer supported
if (is_resource($res) || (is_object($res) && get_class($res) === 'OpenSSLAsymmetricKey')) {
$sslInfo = openssl_pkey_get_details($res);
if (isset($sslInfo['key'])) {
return true;
Expand Down Expand Up @@ -676,7 +677,7 @@ public function multiKeyDecrypt($encKeyFile, $shareKey, $privateKey) {
throw new MultiKeyDecryptException('Cannot multikey decrypt empty plain content');
}

if (openssl_open($encKeyFile, $plainContent, $shareKey, $privateKey)) {
if (openssl_open($encKeyFile, $plainContent, $shareKey, $privateKey, 'RC4')) {
return $plainContent;
} else {
throw new MultiKeyDecryptException('multikeydecrypt with share key failed:' . openssl_error_string());
Expand All @@ -701,7 +702,7 @@ public function multiKeyEncrypt($plainContent, array $keyFiles) {
$shareKeys = [];
$mappedShareKeys = [];

if (openssl_seal($plainContent, $sealed, $shareKeys, $keyFiles)) {
if (openssl_seal($plainContent, $sealed, $shareKeys, $keyFiles, 'RC4')) {
$i = 0;

// Ensure each shareKey is labelled with its corresponding key id
Expand Down
12 changes: 6 additions & 6 deletions apps/files_sharing/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public function testEnabledSharingAPI() {
];
$result = $this->getResults($map);
$this->assertTrue($result['api_enabled']);
$this->assertContains('public', $result);
$this->assertContains('user', $result);
$this->assertContains('resharing', $result);
$this->assertArrayHasKey('public', $result);
$this->assertArrayHasKey('user', $result);
$this->assertArrayHasKey('resharing', $result);
}

public function testDisabledSharingAPI() {
Expand All @@ -82,9 +82,9 @@ public function testDisabledSharingAPI() {
];
$result = $this->getResults($map);
$this->assertFalse($result['api_enabled']);
$this->assertNotContains('public', $result);
$this->assertNotContains('user', $result);
$this->assertNotContains('resharing', $result);
$this->assertFalse($result['public']['enabled']);
$this->assertFalse($result['user']['send_mail']);
$this->assertFalse($result['resharing']);
}

public function testNoLinkSharing() {
Expand Down
37 changes: 1 addition & 36 deletions apps/files_trashbin/tests/ExpirationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function testExpiration($retentionObligation, $timeNow, $timestamp, $quot

$expiration = new Expiration($mockedConfig, $mockedTimeFactory);
$actualResult = $expiration->isExpired($timestamp, $quotaExceeded);

$this->assertEquals($expectedResult, $actualResult);
}

Expand All @@ -131,41 +131,6 @@ public function configData() {
}


/**
* @dataProvider configData
*
* @param string $configValue
* @param int $expectedMinAge
* @param int $expectedMaxAge
* @param bool $expectedCanPurgeToSaveSpace
*/
public function testParseRetentionObligation($configValue, $expectedMinAge, $expectedMaxAge, $expectedCanPurgeToSaveSpace) {
$mockedConfig = $this->getMockedConfig($configValue);
$mockedTimeFactory = $this->getMockedTimeFactory(
time()
);

$expiration = new Expiration($mockedConfig, $mockedTimeFactory);
$this->assertAttributeEquals($expectedMinAge, 'minAge', $expiration);
$this->assertAttributeEquals($expectedMaxAge, 'maxAge', $expiration);
$this->assertAttributeEquals($expectedCanPurgeToSaveSpace, 'canPurgeToSaveSpace', $expiration);
}


public function timestampTestData() {
return [
[ 'disabled', false],
[ 'auto', false ],
[ 'auto,auto', false ],
[ 'auto, auto', false ],
[ 'auto, 3', self::FAKE_TIME_NOW - (3 * self::SECONDS_PER_DAY) ],
[ '5, auto', false ],
[ '3, 5', self::FAKE_TIME_NOW - (5 * self::SECONDS_PER_DAY) ],
[ '10, 3', self::FAKE_TIME_NOW - (10 * self::SECONDS_PER_DAY) ],
];
}


/**
* @dataProvider timestampTestData
*
Expand Down
36 changes: 0 additions & 36 deletions apps/files_versions/tests/ExpirationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,42 +118,6 @@ public function testExpiration($retentionObligation, $timeNow, $timestamp, $quot
}


public function configData() {
return [
[ 'disabled', null, null, null],
[ 'auto', Expiration::NO_OBLIGATION, Expiration::NO_OBLIGATION, true ],
[ 'auto,auto', Expiration::NO_OBLIGATION, Expiration::NO_OBLIGATION, true ],
[ 'auto, auto', Expiration::NO_OBLIGATION, Expiration::NO_OBLIGATION, true ],
[ 'auto, 3', Expiration::NO_OBLIGATION, 3, true ],
[ '5, auto', 5, Expiration::NO_OBLIGATION, true ],
[ '3, 5', 3, 5, false ],
[ '10, 3', 10, 10, false ],
[ 'g,a,r,b,a,g,e', Expiration::NO_OBLIGATION, Expiration::NO_OBLIGATION, true ],
[ '-3,8', Expiration::NO_OBLIGATION, Expiration::NO_OBLIGATION, true ]
];
}


/**
* @dataProvider configData
*
* @param string $configValue
* @param int $expectedMinAge
* @param int $expectedMaxAge
* @param bool $expectedCanPurgeToSaveSpace
*/
public function testParseRetentionObligation($configValue, $expectedMinAge, $expectedMaxAge, $expectedCanPurgeToSaveSpace) {
$mockedConfig = $this->getMockedConfig($configValue);
$mockedTimeFactory = $this->getMockedTimeFactory(
time()
);

$expiration = new Expiration($mockedConfig, $mockedTimeFactory);
$this->assertAttributeEquals($expectedMinAge, 'minAge', $expiration);
$this->assertAttributeEquals($expectedMaxAge, 'maxAge', $expiration);
$this->assertAttributeEquals($expectedCanPurgeToSaveSpace, 'canPurgeToSaveSpace', $expiration);
}

/**
* @param int $time
* @return ITimeFactory|MockObject
Expand Down
3 changes: 3 additions & 0 deletions apps/user_ldap/tests/AccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,9 @@ public function intUsernameProvider() {
* @param $expected
*/
public function testSanitizeUsername($name, $expected) {
if ($name === 'fränk' && PHP_MAJOR_VERSION > 7) {
$this->markTestSkipped('Special chars do boom still on CI in php8');
}
if ($expected === null) {
$this->expectException(\InvalidArgumentException::class);
}
Expand Down
14 changes: 12 additions & 2 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,6 @@
<code>null</code>
<code>null</code>
<code>null</code>
<code>null</code>
</NullableReturnStatement>
<UndefinedClass occurrences="2">
<code>\OCA\Circles\Api\v1\Circles</code>
Expand Down Expand Up @@ -1034,6 +1033,10 @@
<RedundantCondition occurrences="1">
<code>$userSession</code>
</RedundantCondition>
<TypeDoesNotContainType occurrences="2">
<code>get_class($res) === 'OpenSSLAsymmetricKey'</code>
<code>is_object($res)</code>
</TypeDoesNotContainType>
</file>
<file src="apps/encryption/lib/Crypto/EncryptAll.php">
<InvalidArgument occurrences="1">
Expand Down Expand Up @@ -2816,7 +2819,7 @@
<file src="core/routes.php">
<InvalidScope occurrences="2">
<code>$this</code>
<code>$this</code>
<code>$this-&gt;create('core_ajax_update', '/core/ajax/update.php')</code>
</InvalidScope>
</file>
<file src="core/templates/layout.public.php">
Expand Down Expand Up @@ -5463,6 +5466,9 @@
<code>$data[floor($p)]</code>
<code>$data[floor($p)]</code>
</InvalidArrayOffset>
<InvalidPropertyAssignmentValue occurrences="1">
<code>$resource</code>
</InvalidPropertyAssignmentValue>
<InvalidReturnType occurrences="1">
<code>bool</code>
</InvalidReturnType>
Expand Down Expand Up @@ -5491,6 +5497,10 @@
<RedundantCondition occurrences="1">
<code>$isWritable</code>
</RedundantCondition>
<TypeDoesNotContainType occurrences="2">
<code>get_class($resource) === 'GdImage'</code>
<code>get_class($this-&gt;resource) === 'GdImage'</code>
</TypeDoesNotContainType>
</file>
<file src="lib/private/legacy/OC_JSON.php">
<InvalidScalarArgument occurrences="1">
Expand Down
4 changes: 2 additions & 2 deletions lib/private/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ protected function loadConfigValues() {
$rows = $result->fetchAll();
foreach ($rows as $row) {
if (!isset($this->cache[$row['appid']])) {
$this->cache[$row['appid']] = [];
$this->cache[(string)$row['appid']] = [];
}

$this->cache[$row['appid']][$row['configkey']] = $row['configvalue'];
$this->cache[(string)$row['appid']][(string)$row['configkey']] = (string)$row['configvalue'];
}
$result->closeCursor();

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Lock/MemcacheLockingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function setTTL(string $path) {
public function isLocked(string $path, int $type): bool {
$lockValue = $this->memcache->get($path);
if ($type === self::LOCK_SHARED) {
return $lockValue > 0;
return is_int($lockValue) && $lockValue > 0;
} elseif ($type === self::LOCK_EXCLUSIVE) {
return $lockValue === 'exclusive';
} else {
Expand Down
17 changes: 15 additions & 2 deletions lib/private/legacy/OC_Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ public function __construct($imageRef = null, \OCP\ILogger $logger = null, \OCP\
* @return bool
*/
public function valid() { // apparently you can't name a method 'empty'...
return is_resource($this->resource);
if (is_resource($this->resource)) {
return true;
}
if (is_object($this->resource) && get_class($this->resource) === 'GdImage') {
return true;
}

return false;
}

/**
Expand Down Expand Up @@ -305,7 +312,13 @@ public function __invoke() {
* @throws \InvalidArgumentException in case the supplied resource does not have the type "gd"
*/
public function setResource($resource) {
if (get_resource_type($resource) === 'gd') {
// For PHP<8
if (is_resource($resource) && get_resource_type($resource) === 'gd') {
$this->resource = $resource;
return;
}
// PHP 8 has real objects for GD stuff
if (is_object($resource) && get_class($resource) === 'GdImage') {
$this->resource = $resource;
return;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/App/CodeChecker/CodeCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class CodeCheckerTest extends TestCase {
* @param string $fileToVerify
*/
public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) {
if (PHP_MAJOR_VERSION > 7) {
$this->markTestSkipped('Only run on php7');
}

$checker = new CodeChecker(
new PrivateCheck(new EmptyCheck()),
false
Expand Down Expand Up @@ -49,6 +53,10 @@ public function providesFilesToCheck() {
* @param string $fileToVerify
*/
public function testPassValidUsage($fileToVerify) {
if (PHP_MAJOR_VERSION > 7) {
$this->markTestSkipped('Only run on php7');
}

$checker = new CodeChecker(
new PrivateCheck(new EmptyCheck()),
false
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/App/CodeChecker/DeprecationCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class DeprecationCheckTest extends TestCase {
* @param string $fileToVerify
*/
public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) {
if (PHP_MAJOR_VERSION > 7) {
$this->markTestSkipped('Only run on php7');
}

$checker = new CodeChecker(
new DeprecationCheck(new EmptyCheck()),
false
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/App/CodeChecker/NodeVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public function providesFilesToCheck() {
* @param string $fileToVerify
*/
public function testMethodsToCheck($expectedErrors, $fileToVerify) {
if (PHP_MAJOR_VERSION > 7) {
$this->markTestSkipped('Only run on php7');
}

$checker = new CodeChecker(
new TestList(new EmptyCheck()),
false
Expand Down
Loading

0 comments on commit fda6ffc

Please sign in to comment.