From a23cd7b961fc7c0d8d52cf2d914bdee36e2a40bc Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 24 May 2022 13:26:58 +0200 Subject: [PATCH 1/3] Fix a bunch of deprecation in the phpunit for core Signed-off-by: Carl Schwan --- .drone.yml | 10 ++-- tests/Core/Command/Apps/AppsDisableTest.php | 2 +- tests/Core/Command/Apps/AppsEnableTest.php | 2 +- tests/Core/Controller/LoginControllerTest.php | 58 +++++++++---------- .../Controller/NavigationControllerTest.php | 29 +++++----- .../TwoFactorChallengeControllerTest.php | 10 ++-- .../Service/LoginFlowV2ServiceUnitTest.php | 2 +- 7 files changed, 56 insertions(+), 57 deletions(-) diff --git a/.drone.yml b/.drone.yml index cb20021cfd7..4c372703337 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1842,7 +1842,7 @@ steps: XDEBUG_MODE: coverage commands: - phpenmod xdebug - - TEST_SELECTION=NODB ./autotest.sh sqlite + - PHPUNIT_EXE=build/integration/vendor/bin/phpunit TEST_SELECTION=NODB ./autotest.sh sqlite - wget https://codecov.io/bash -O codecov.sh - bash codecov.sh -Z -C $DRONE_COMMIT -f tests/autotest-clover-sqlite.xml @@ -1874,7 +1874,7 @@ steps: XDEBUG_MODE: coverage commands: - phpenmod xdebug - - TEST_SELECTION=QUICKDB ./autotest.sh sqlite + - PHPUNIT_EXE=build/integration/vendor/bin/phpunit TEST_SELECTION=QUICKDB ./autotest.sh sqlite - wget https://codecov.io/bash -O codecov.sh - bash codecov.sh -Z -C $DRONE_COMMIT -f tests/autotest-clover-sqlite.xml @@ -1916,7 +1916,7 @@ steps: commands: - phpenmod xdebug - ./tests/drone-wait-objectstore.sh - - TEST_SELECTION=PRIMARY-s3 ./autotest.sh sqlite + - PHPUNIT_EXE=build/integration/vendor/bin/phpunit TEST_SELECTION=PRIMARY-s3 ./autotest.sh sqlite - wget https://codecov.io/bash -O codecov.sh - bash codecov.sh -C $DRONE_COMMIT -f tests/autotest-clover-sqlite.xml @@ -1946,7 +1946,7 @@ steps: commands: - phpenmod xdebug - ./tests/drone-wait-objectstore.sh - - TEST_SELECTION=PRIMARY-azure ./autotest.sh sqlite + - PHPUNIT_EXE=build/integration/vendor/bin/phpunit TEST_SELECTION=PRIMARY-azure ./autotest.sh sqlite - wget https://codecov.io/bash -O codecov.sh - bash codecov.sh -C $DRONE_COMMIT -f tests/autotest-clover-sqlite.xml @@ -1978,7 +1978,7 @@ steps: commands: - phpenmod xdebug - service memcached restart - - ./autotest.sh sqlite tests/lib/Memcache/MemcachedTest.php + - PHPUNIT_EXE=build/integration/vendor/bin/phpunit ./autotest.sh sqlite tests/lib/Memcache/MemcachedTest.php - wget https://codecov.io/bash -O codecov.sh - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 117641e2-a9e8-4b7b-984b-ae872d9b05f5 -f tests/autotest-clover-sqlite.xml; fi" - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 117641e2-a9e8-4b7b-984b-ae872d9b05f5 -f tests/autotest-clover-sqlite.xml; fi" diff --git a/tests/Core/Command/Apps/AppsDisableTest.php b/tests/Core/Command/Apps/AppsDisableTest.php index 8995ee2673f..2b276948b04 100644 --- a/tests/Core/Command/Apps/AppsDisableTest.php +++ b/tests/Core/Command/Apps/AppsDisableTest.php @@ -61,7 +61,7 @@ class AppsDisableTest extends TestCase { $this->commandTester->execute($input); - $this->assertRegExp('/' . $pattern . '/', $this->commandTester->getDisplay()); + $this->assertMatchesRegularExpression('/' . $pattern . '/', $this->commandTester->getDisplay()); $this->assertSame($statusCode, $this->commandTester->getStatusCode()); } diff --git a/tests/Core/Command/Apps/AppsEnableTest.php b/tests/Core/Command/Apps/AppsEnableTest.php index 02bf86cfd43..6e577464103 100644 --- a/tests/Core/Command/Apps/AppsEnableTest.php +++ b/tests/Core/Command/Apps/AppsEnableTest.php @@ -66,7 +66,7 @@ class AppsEnableTest extends TestCase { $this->commandTester->execute($input); - $this->assertRegExp('/' . $pattern . '/', $this->commandTester->getDisplay()); + $this->assertMatchesRegularExpression('/' . $pattern . '/', $this->commandTester->getDisplay()); $this->assertSame($statusCode, $this->commandTester->getStatusCode()); } diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index c97ed53d331..b10a042059d 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -249,27 +249,30 @@ class LoginControllerTest extends TestCase { ], ] ); - $this->initialStateService->expects($this->at(0)) + $this->initialStateService->expects($this->exactly(10)) ->method('provideInitialState') - ->with( + ->withConsecutive([ 'core', 'loginMessages', [ 'MessageArray1', 'MessageArray2', 'This community release of Nextcloud is unsupported and push notifications are limited.', - ] - ); - $this->initialStateService->expects($this->at(1)) - ->method('provideInitialState') - ->with( + ], + ], + [ 'core', 'loginErrors', [ 'ErrorArray1', 'ErrorArray2', - ] - ); + ], + ], + [ + 'core', + 'loginUsername', + '', + ]); $expectedResponse = new TemplateResponse( 'core', @@ -288,13 +291,17 @@ class LoginControllerTest extends TestCase { ->expects($this->once()) ->method('isLoggedIn') ->willReturn(false); - $this->initialStateService->expects($this->at(4)) + $this->initialStateService->expects($this->exactly(11)) ->method('provideInitialState') - ->with( + ->withConsecutive([], [], [], [ + 'core', + 'loginAutocomplete', + false + ], [ 'core', 'loginRedirectUrl', 'login/flow' - ); + ]); $expectedResponse = new TemplateResponse( 'core', @@ -355,20 +362,17 @@ class LoginControllerTest extends TestCase { ->method('get') ->with('LdapUser') ->willReturn($user); - $this->initialStateService->expects($this->at(2)) + $this->initialStateService->expects($this->exactly(10)) ->method('provideInitialState') - ->with( + ->withConsecutive([], [], [ 'core', 'loginUsername', 'LdapUser' - ); - $this->initialStateService->expects($this->at(6)) - ->method('provideInitialState') - ->with( + ], [], [], [], [ 'core', 'loginCanResetPassword', $expectedResult - ); + ]); $expectedResponse = new TemplateResponse( 'core', @@ -408,27 +412,21 @@ class LoginControllerTest extends TestCase { ->method('get') ->with('0') ->willReturn($user); - $this->initialStateService->expects($this->at(3)) + $this->initialStateService->expects($this->exactly(10)) ->method('provideInitialState') - ->with( + ->withConsecutive([], [], [], [ 'core', 'loginAutocomplete', true - ); - $this->initialStateService->expects($this->at(5)) - ->method('provideInitialState') - ->with( + ], [], [ 'core', 'loginResetPasswordLink', false - ); - $this->initialStateService->expects($this->at(6)) - ->method('provideInitialState') - ->with( + ], [ 'core', 'loginCanResetPassword', false - ); + ]); $expectedResponse = new TemplateResponse( 'core', diff --git a/tests/Core/Controller/NavigationControllerTest.php b/tests/Core/Controller/NavigationControllerTest.php index 39f389faa5e..ddf307ec06d 100644 --- a/tests/Core/Controller/NavigationControllerTest.php +++ b/tests/Core/Controller/NavigationControllerTest.php @@ -74,14 +74,13 @@ class NavigationControllerTest extends TestCase { $this->urlGenerator->expects($this->any()) ->method('getBaseURL') ->willReturn('http://localhost/'); - $this->urlGenerator->expects($this->at(1)) + $this->urlGenerator->expects($this->exactly(2)) ->method('getAbsoluteURL') - ->with('/index.php/apps/files') - ->willReturn('http://localhost/index.php/apps/files'); - $this->urlGenerator->expects($this->at(3)) - ->method('getAbsoluteURL') - ->with('icon') - ->willReturn('http://localhost/icon'); + ->withConsecutive(['/index.php/apps/files'], ['icon']) + ->willReturnOnConsecutiveCalls( + 'http://localhost/index.php/apps/files', + 'http://localhost/icon' + ); $actual = $this->controller->getAppsNavigation($absolute); $this->assertInstanceOf(DataResponse::class, $actual); $this->assertEquals('http://localhost/index.php/apps/files', $actual->getData()[0]['href']); @@ -104,14 +103,16 @@ class NavigationControllerTest extends TestCase { $this->urlGenerator->expects($this->any()) ->method('getBaseURL') ->willReturn('http://localhost/'); - $this->urlGenerator->expects($this->at(1)) + $this->urlGenerator->expects($this->exactly(2)) ->method('getAbsoluteURL') - ->with('/index.php/settings/user') - ->willReturn('http://localhost/index.php/settings/user'); - $this->urlGenerator->expects($this->at(3)) - ->method('getAbsoluteURL') - ->with('/core/img/settings.svg') - ->willReturn('http://localhost/core/img/settings.svg'); + ->withConsecutive( + ['/index.php/settings/user'], + ['/core/img/settings.svg'] + ) + ->willReturnOnConsecutiveCalls( + 'http://localhost/index.php/settings/user', + 'http://localhost/core/img/settings.svg' + ); $actual = $this->controller->getSettingsNavigation($absolute); $this->assertInstanceOf(DataResponse::class, $actual); $this->assertEquals('http://localhost/index.php/settings/user', $actual->getData()[0]['href']); diff --git a/tests/Core/Controller/TwoFactorChallengeControllerTest.php b/tests/Core/Controller/TwoFactorChallengeControllerTest.php index 27b0f476b61..baf7feaa068 100644 --- a/tests/Core/Controller/TwoFactorChallengeControllerTest.php +++ b/tests/Core/Controller/TwoFactorChallengeControllerTest.php @@ -316,12 +316,12 @@ class TwoFactorChallengeControllerTest extends TestCase { ->method('verifyChallenge') ->with('myprovider', $user, 'token') ->will($this->throwException($exception)); - $this->session->expects($this->at(0)) + $this->session->expects($this->exactly(2)) ->method('set') - ->with('two_factor_auth_error_message', "2FA failed"); - $this->session->expects($this->at(1)) - ->method('set') - ->with('two_factor_auth_error', true); + ->withConsecutive( + ['two_factor_auth_error_message', '2FA failed'], + ['two_factor_auth_error', true] + ); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->with('core.TwoFactorChallenge.showChallenge', [ diff --git a/tests/Core/Service/LoginFlowV2ServiceUnitTest.php b/tests/Core/Service/LoginFlowV2ServiceUnitTest.php index c3128dca334..57443ca1328 100644 --- a/tests/Core/Service/LoginFlowV2ServiceUnitTest.php +++ b/tests/Core/Service/LoginFlowV2ServiceUnitTest.php @@ -350,7 +350,7 @@ class LoginFlowV2ServiceUnitTest extends TestCase { // app password is encrypted and must look like: // ZACZOOzxTpKz4+KXL5kZ/gCK0xvkaVi/8yzupAn6Ui6+5qCSKvfPKGgeDRKs0sivvSLzk/XSp811SZCZmH0Y3g== - $this->assertRegExp('/[a-zA-Z\/0-9+=]+/', $loginFlowV2->getAppPassword()); + $this->assertMatchesRegularExpression('/[a-zA-Z\/0-9+=]+/', $loginFlowV2->getAppPassword()); $this->assertEquals('server', $loginFlowV2->getServer()); } From 5b0f7f7501f3705f112216771f2e4971a9885096 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Fri, 27 May 2022 15:33:15 +0200 Subject: [PATCH 2/3] Use phpunit from composer if available Signed-off-by: Carl Schwan --- .drone.yml | 10 +++++----- autotest.sh | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.drone.yml b/.drone.yml index 4c372703337..cb20021cfd7 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1842,7 +1842,7 @@ steps: XDEBUG_MODE: coverage commands: - phpenmod xdebug - - PHPUNIT_EXE=build/integration/vendor/bin/phpunit TEST_SELECTION=NODB ./autotest.sh sqlite + - TEST_SELECTION=NODB ./autotest.sh sqlite - wget https://codecov.io/bash -O codecov.sh - bash codecov.sh -Z -C $DRONE_COMMIT -f tests/autotest-clover-sqlite.xml @@ -1874,7 +1874,7 @@ steps: XDEBUG_MODE: coverage commands: - phpenmod xdebug - - PHPUNIT_EXE=build/integration/vendor/bin/phpunit TEST_SELECTION=QUICKDB ./autotest.sh sqlite + - TEST_SELECTION=QUICKDB ./autotest.sh sqlite - wget https://codecov.io/bash -O codecov.sh - bash codecov.sh -Z -C $DRONE_COMMIT -f tests/autotest-clover-sqlite.xml @@ -1916,7 +1916,7 @@ steps: commands: - phpenmod xdebug - ./tests/drone-wait-objectstore.sh - - PHPUNIT_EXE=build/integration/vendor/bin/phpunit TEST_SELECTION=PRIMARY-s3 ./autotest.sh sqlite + - TEST_SELECTION=PRIMARY-s3 ./autotest.sh sqlite - wget https://codecov.io/bash -O codecov.sh - bash codecov.sh -C $DRONE_COMMIT -f tests/autotest-clover-sqlite.xml @@ -1946,7 +1946,7 @@ steps: commands: - phpenmod xdebug - ./tests/drone-wait-objectstore.sh - - PHPUNIT_EXE=build/integration/vendor/bin/phpunit TEST_SELECTION=PRIMARY-azure ./autotest.sh sqlite + - TEST_SELECTION=PRIMARY-azure ./autotest.sh sqlite - wget https://codecov.io/bash -O codecov.sh - bash codecov.sh -C $DRONE_COMMIT -f tests/autotest-clover-sqlite.xml @@ -1978,7 +1978,7 @@ steps: commands: - phpenmod xdebug - service memcached restart - - PHPUNIT_EXE=build/integration/vendor/bin/phpunit ./autotest.sh sqlite tests/lib/Memcache/MemcachedTest.php + - ./autotest.sh sqlite tests/lib/Memcache/MemcachedTest.php - wget https://codecov.io/bash -O codecov.sh - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 117641e2-a9e8-4b7b-984b-ae872d9b05f5 -f tests/autotest-clover-sqlite.xml; fi" - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 117641e2-a9e8-4b7b-984b-ae872d9b05f5 -f tests/autotest-clover-sqlite.xml; fi" diff --git a/autotest.sh b/autotest.sh index f748cbbed12..84ffa0a1c78 100755 --- a/autotest.sh +++ b/autotest.sh @@ -30,8 +30,13 @@ if [ -z "$PHP_EXE" ]; then fi PHP=$(which "$PHP_EXE") if [ -z "$PHPUNIT_EXE" ]; then - PHPUNIT_EXE=phpunit + if [ -f "build/integration/vendor/bin/phpunit" ]; then + PHPUNIT_EXE="./build/integration/vendor/bin/phpunit" + else + PHPUNIT_EXE=phpunit + fi fi + PHPUNIT=$(which "$PHPUNIT_EXE") set -e @@ -56,7 +61,7 @@ else fi if ! [ -x "$PHPUNIT" ]; then - echo "phpunit executable not found, please install phpunit version >= 6.5" >&2 + echo "phpunit executable not found, please install phpunit version >= 9.0" >&2 exit 3 fi From 003cc2b45a585d3739daf3219fced21ca256f904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 24 Jan 2023 09:38:20 +0100 Subject: [PATCH 3/3] Fix tests failures (number of calls differed with last rebase) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- tests/Core/Controller/LoginControllerTest.php | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index b10a042059d..ae033582d3c 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -249,7 +249,7 @@ class LoginControllerTest extends TestCase { ], ] ); - $this->initialStateService->expects($this->exactly(10)) + $this->initialStateService->expects($this->exactly(11)) ->method('provideInitialState') ->withConsecutive([ 'core', @@ -260,19 +260,19 @@ class LoginControllerTest extends TestCase { 'This community release of Nextcloud is unsupported and push notifications are limited.', ], ], - [ - 'core', - 'loginErrors', [ - 'ErrorArray1', - 'ErrorArray2', + 'core', + 'loginErrors', + [ + 'ErrorArray1', + 'ErrorArray2', + ], ], - ], - [ - 'core', - 'loginUsername', - '', - ]); + [ + 'core', + 'loginUsername', + '', + ]); $expectedResponse = new TemplateResponse( 'core', @@ -291,7 +291,7 @@ class LoginControllerTest extends TestCase { ->expects($this->once()) ->method('isLoggedIn') ->willReturn(false); - $this->initialStateService->expects($this->exactly(11)) + $this->initialStateService->expects($this->exactly(12)) ->method('provideInitialState') ->withConsecutive([], [], [], [ 'core', @@ -362,7 +362,7 @@ class LoginControllerTest extends TestCase { ->method('get') ->with('LdapUser') ->willReturn($user); - $this->initialStateService->expects($this->exactly(10)) + $this->initialStateService->expects($this->exactly(11)) ->method('provideInitialState') ->withConsecutive([], [], [ 'core', @@ -412,7 +412,7 @@ class LoginControllerTest extends TestCase { ->method('get') ->with('0') ->willReturn($user); - $this->initialStateService->expects($this->exactly(10)) + $this->initialStateService->expects($this->exactly(11)) ->method('provideInitialState') ->withConsecutive([], [], [], [ 'core',