-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
PhpUnit tests #1312
base: master
Are you sure you want to change the base?
PhpUnit tests #1312
Conversation
I have absolutely no experience with phpunit |
@ggoffy, XOOPS Core and all our modules in the future will have to have PhpUnit tests included, either directly or via tools like Codeception. If we want to increase the quality of our code and avoid introducing bugs by changes to our code, it will be a must. As next step, we'll need to enhance our ModuleBuilder to generate automatically the basic PhpUnit tests for the modules, as well as the "datatools" entries for wgTestUI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check ok
Hi,
You mean "my own tests" ? An example to understand, perhaps ? ;-) |
To be discussed for the next version of xoops. Not yet in version 2.5.11 |
Sure, |
Are these test made for PHPUnit 9? I have PHPUnit 10 and the assertObjectHasAttribute() method was removed and will be replaced with assertObjectHasProperty() in PHPUnit 10.1 (https://github.com/sebastianbergmann/phpunit/milestone/54?closed=1) |
I was testing it on PHPUnit 9.6.4 |
As it will be a while until the next PHPUnit release with the new functions, I'll use PHPUnit 9.6.5. Is there an automated way to install XOOPS and Modules using a PHP script? |
no automated way using a PHP script. |
Thanks. I'll manually install XOOPS for now. I just configured PhpStorm, with PHPUnit (running in a vagrant box) (https://www.jetbrains.com/help/phpstorm/using-phpunit-framework.html ). They made it so easy to configure, it was way easier than I thought it would be. |
If I find time, and that's the big IF, I was thinking to about adding to the ModuleInstaller an option to group modules together, which then would allow to install/uninstall/activate/deactivate a particular group of modules, which would help in testing of modules that have dependencies on other modules. Also, there are some PhpStorm plugins for PHPUnit, so if you're using them, let me know if any of them are good: I don't use Vagrant, but maybe we could create a standard Docker setup, that we could use as a base for testing? We had couple of those, but they are outdated now: |
I just started using PHPUnit this week. Watched a few YouTube videos. 😅 Yeah a docker container wouldn't hurt, could be useful. |
// echo 'XOOPS_TU_ROOT_PATH = ' . XOOPS_TU_ROOT_PATH. "\n"; | ||
|
||
//temporary patch, we still need mainfile until we have a config file | ||
$xoopsOption['nocommon'] = true; // don't include common.php file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we not including common.php?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question.
It comes from here: https://github.com/XOOPS/XoopsCore/blob/master/tests/unit/init_new.php
|
||
$actual = $this->object->getColumnAttributes($tableName, $columnName); | ||
|
||
$this->assertNotFalse(stristr($actual, 'mediumint(8)')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On my new install of XOOPS (MySQL 8.0.32) I noticed that the mediumint(8) is only showing up as mediumint in MySQL.
It looks like some of the width attributes for integer data types were removed. https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-19.html#mysqld-8-0-19-deprecation-removal
Display width specification for integer data types was deprecated in MySQL 8.0.17, and now statements that include data type definitions in their output no longer show the display width for integer types, with these exceptions:
The type is TINYINT(1). MySQL Connectors make the assumption that TINYINT(1) columns originated as BOOLEAN columns; this exception enables them to continue to make that assumption.
The type includes the ZEROFILL attribute.
This change applies to tables, views, and stored routines, and affects the output from SHOW CREATE and DESCRIBE statements, and from INFORMATION_SCHEMA tables.
For DESCRIBE statements and INFORMATION_SCHEMA queries, output is unaffected for objects created in previous MySQL 8.0 versions because information already stored in the data dictionary remains unchanged. This exception does not apply for upgrades from MySQL 5.7 to 8.0, for which all data dictionary information is re-created such that data type definitions do not include display width. (Bug #30556657, Bug #97680, WL #13528)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm converting ("downporting") these tests from XOOPS 2.6.0 , so most of the time I'm just focusing on making sure that they run, hoping that it will be a good start for all of us to review and improve them, while keeping them compatible to XOOPS 2.6.0 as much as we can, in order to make it easier to transition the XOOPS 2.5.11 code to XOOPS 2.6.0 by having similar tests.
Of course, the XOOPS 2.6.0 tests are pretty old, so some of the things there might be outdated, so if you see anything strange, please make a comment, and hopefully we'll be able to figure that out together, as we learn PHPUnit and Unit testing
Richard has updated some of the XMF tests directly in XMF, so we'll need to use those, as XMF should be tested directly with own tests. I just saw this as an exercise for to test the conversion and see if it works.
As I've mentioned earlier, it's all new to me and I'm still learning, but we need it, so it's a good opportunity to learn something new while helping XOOPS 2.5.11 to become more "testable" :)
No description provided.