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

PhpUnit tests #1312

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

PhpUnit tests #1312

wants to merge 12 commits into from

Conversation

mambax7
Copy link
Collaborator

@mambax7 mambax7 commented Mar 7, 2023

No description provided.

@ggoffy
Copy link
Contributor

ggoffy commented Mar 7, 2023

I have absolutely no experience with phpunit

@mambax7
Copy link
Collaborator Author

mambax7 commented Mar 7, 2023

@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.
Personally, I don't like writing tests, but there is no way around it, we have to have them!
And your other tool, wgTestUI, will be a great addition to improve our code.

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.

Copy link
Contributor

@montuy337513 montuy337513 left a comment

Choose a reason for hiding this comment

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

check ok

@alain01
Copy link
Contributor

alain01 commented Mar 8, 2023

Hi,
Please, give me some explanations

  1. Put your tests in a folder called "tests" (with an .htaccess "deny from all")

You mean "my own tests" ?
You mean there is no test, it's up to us to create tests and it's PhpUnit that will manage this?

An example to understand, perhaps ? ;-)

@GregMage
Copy link
Contributor

GregMage commented Mar 8, 2023

To be discussed for the next version of xoops. Not yet in version 2.5.11

@alain01
Copy link
Contributor

alain01 commented Mar 8, 2023

Sure,
no new features added for the current dev version 2.5.11, totally agree with you.

@ihackcode
Copy link
Member

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)

@mambax7
Copy link
Collaborator Author

mambax7 commented Mar 20, 2023

I was testing it on PHPUnit 9.6.4
Feel free to upgrade them to PHPUnit 10

@ihackcode
Copy link
Member

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?

@mambax7
Copy link
Collaborator Author

mambax7 commented Mar 23, 2023

no automated way using a PHP script.
But inside XOOPS you can use the https://github.com/mambax7/moduleinstaller to install several modules at once. You could also use it to activate or deactivate them.

@ihackcode
Copy link
Member

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.

@mambax7
Copy link
Collaborator Author

mambax7 commented Mar 25, 2023

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.
I'm starting learning PHPUnit, so if you have any tips, please share!

Also, there are some PhpStorm plugins for PHPUnit, so if you're using them, let me know if any of them are good:
image

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:
https://github.com/geekwright/xoops_mysql8
https://github.com/mambax7/docker_xoops259
If it's useful, we might update them. What do you think?

@ihackcode
Copy link
Member

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. I'm starting learning PHPUnit, so if you have any tips, please share!

Also, there are some PhpStorm plugins for PHPUnit, so if you're using them, let me know if any of them are good: image

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: https://github.com/geekwright/xoops_mysql8 https://github.com/mambax7/docker_xoops259 If it's useful, we might update them. What do you think?

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
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


$actual = $this->object->getColumnAttributes($tableName, $columnName);

$this->assertNotFalse(stristr($actual, 'mediumint(8)'));
Copy link
Member

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)

Copy link
Collaborator Author

@mambax7 mambax7 Mar 28, 2023

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" :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants