Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix risky test without assertion #32761

Closed

Conversation

nickvergessen
Copy link
Member

Before:

There was 1 risky test:

1) Test\Files\Node\FolderTest::testGet
This test did not perform any assertions

/home/nickv/Nextcloud/25/server/tests/lib/Files/Node/FolderTest.php:95

phpvfscomposer:///home/nickv/Tools/vendor/phpunit/phpunit/phpunit:97

OK, but incomplete, skipped, or risky tests!
Tests: 64, Assertions: 144, Risky: 1.

Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen nickvergessen added this to the Nextcloud 25 milestone Jun 8, 2022
@nickvergessen nickvergessen requested review from a team, PVince81, CarlSchwan and come-nc and removed request for a team June 8, 2022 12:05
Signed-off-by: Joas Schilling <coding@schilljs.com>
Copy link
Member

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen
Copy link
Member Author

@PVince81 you added tests/lib/Encryption/UtilTest.php last week, but it doesn't work:

here were 7 errors:

1) Test\Encryption\UtilTest::testIsSystemWideMountPoint with data set #0 (false, 'non-matching mount point name', array(), array(), '/mp_another')
PHPUnit\Framework\MockObject\UnknownTypeException: Class or interface "OCA\Files_External\Lib\StorageConfig" does not exist

/home/nickv/Nextcloud/25/server/tests/lib/Encryption/UtilTest.php:221
phpvfscomposer:///home/nickv/Tools/vendor/phpunit/phpunit/phpunit:97

2) Test\Encryption\UtilTest::testIsSystemWideMountPoint with data set #1 (true, 'applicable to all', array(), array())
PHPUnit\Framework\MockObject\UnknownTypeException: Class or interface "OCA\Files_External\Lib\StorageConfig" does not exist

/home/nickv/Nextcloud/25/server/tests/lib/Encryption/UtilTest.php:221
phpvfscomposer:///home/nickv/Tools/vendor/phpunit/phpunit/phpunit:97

3) Test\Encryption\UtilTest::testIsSystemWideMountPoint with data set #2 (true, 'applicable to user directly', array('user1'), array())
PHPUnit\Framework\MockObject\UnknownTypeException: Class or interface "OCA\Files_External\Lib\StorageConfig" does not exist

/home/nickv/Nextcloud/25/server/tests/lib/Encryption/UtilTest.php:221
phpvfscomposer:///home/nickv/Tools/vendor/phpunit/phpunit/phpunit:97

4) Test\Encryption\UtilTest::testIsSystemWideMountPoint with data set #3 (true, 'applicable to group directly', array(), array('group1'))
PHPUnit\Framework\MockObject\UnknownTypeException: Class or interface "OCA\Files_External\Lib\StorageConfig" does not exist

/home/nickv/Nextcloud/25/server/tests/lib/Encryption/UtilTest.php:221
phpvfscomposer:///home/nickv/Tools/vendor/phpunit/phpunit/phpunit:97

5) Test\Encryption\UtilTest::testIsSystemWideMountPoint with data set #4 (false, 'non-applicable to current user', array('user2'), array())
PHPUnit\Framework\MockObject\UnknownTypeException: Class or interface "OCA\Files_External\Lib\StorageConfig" does not exist

/home/nickv/Nextcloud/25/server/tests/lib/Encryption/UtilTest.php:221
phpvfscomposer:///home/nickv/Tools/vendor/phpunit/phpunit/phpunit:97

6) Test\Encryption\UtilTest::testIsSystemWideMountPoint with data set #5 (false, 'non-applicable to current user's group', array(), array('group2'))
PHPUnit\Framework\MockObject\UnknownTypeException: Class or interface "OCA\Files_External\Lib\StorageConfig" does not exist

/home/nickv/Nextcloud/25/server/tests/lib/Encryption/UtilTest.php:221
phpvfscomposer:///home/nickv/Tools/vendor/phpunit/phpunit/phpunit:97

7) Test\Encryption\UtilTest::testIsSystemWideMountPoint with data set #6 (true, 'mount point without leading slash', array(), array(), 'mp')
PHPUnit\Framework\MockObject\UnknownTypeException: Class or interface "OCA\Files_External\Lib\StorageConfig" does not exist

/home/nickv/Nextcloud/25/server/tests/lib/Encryption/UtilTest.php:221
phpvfscomposer:///home/nickv/Tools/vendor/phpunit/phpunit/phpunit:97

Can you have a look?

@PVince81
Copy link
Member

PVince81 commented Jun 8, 2022

hmm, they worked for me locally but I had files_external enabled.

probably because we're using a class from an app that might not be enabled during test run, or only during specific order

I'll see if I can trigger enabling of the app in setUp, otherwise will need to do it in the test setups

Because we have more tests now that require classes from this app.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
@PVince81
Copy link
Member

PVince81 commented Jun 8, 2022

I didn't find code in core where the app would be enabled through tests, so I added it to "enable_apps.php": 6df0a79

turns out other apps like "encryption" is there too

let's see if the tests pass now on CI... they passed locally again for me until I disabled files_external

@PVince81
Copy link
Member

PVince81 commented Jun 8, 2022

looks like enabling files_external makes it worse as now tests are trying to run, I'll revert it for now.

will need another more targetted solution that doesn't require including the class

PVince81 added 2 commits June 8, 2022 22:46
Don't rely on files_external being enabled and mock all the classes from
it.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
@PVince81
Copy link
Member

PVince81 commented Jun 8, 2022

here we go, all mocked: de93d17

not sure how long this PR will live, we might want to cherry pick some fixes into separate PRs ?

$storagesServiceMock->expects($this->atLeastOnce())->method('getAllStorages')
->willReturn($storages);

$this->overwriteService(GlobalStoragesService::class, $storagesServiceMock);
$this->overwriteService('OCA\\Files_External\\Service\\GlobalStoragesService', $storagesServiceMock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why for core class you went from string to ::class and for files-external classes you go the other way around?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because core classes are fine. This class might not be loaded as the test is in core and the app is not force enabled nor default enabled

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe some day... owncloud/core#25422

This was referenced Aug 12, 2022
@blizzz blizzz mentioned this pull request Aug 24, 2022
@blizzz blizzz mentioned this pull request Aug 30, 2022
This was referenced Sep 6, 2022
@skjnldsv skjnldsv mentioned this pull request Sep 15, 2022
This was referenced Sep 20, 2022
@blizzz blizzz modified the milestones: Nextcloud 25, Nextcloud 26 Sep 22, 2022
@skjnldsv skjnldsv deleted the bugfix/noid/risky-test-without-assertion branch March 14, 2024 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants