What is the best way to make an extension testable?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
FredQ
Registered User
Posts: 138
Joined: Sat Nov 01, 2014 10:48 am
Location: Northeast Scotland
Name: Fred Q
Contact:

What is the best way to make an extension testable?

Post by FredQ »

I think the phpBB team is doing a great job of moving the code standards to the right direction:
All the new stuff is now relying on Symfony Dependency Injection and that's great. Unfortunately there's still some legacy code in phpBB that you cannot avoid.

I find particularly difficult to unit test some parts of my extension, especially the part that make use of the global variables and/or the global functions.

For that purpose I had to create some wrapper classes like this to be able to test my code:

Code: Select all


class functions implements functions_interface
{
	public function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_body.html', $u_action = '')
	{
		confirm_box($check, $title, $hidden, $html_body, $u_action);
	}
}

By using an interface I'm able to mock the confirm_box functionality inside a unit test. For the normal path, I'm making sure it's added as a dependency to the classes needing access to global functions.

It is something you guys came across as well? Have you found a better way to build a fully testable extension?

Or do you think that would be something useful to share?
My board (converted from vBulletin)
Senky
Extension Customisations
Extension Customisations
Posts: 2289
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Re: What is the best way to make an extension testable?

Post by Senky »

It's a wrong wrong way but this is how we do it:
https://github.com/phpbb-extensions/ad- ... r_test.php
‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎📝‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎ ‎‏‎‏‏‎ ‎ ‎ ‎🔔 ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎ ‎‎ ‎ ‎ ‎ ‎ ‎ ‎‏‏‎ ‎‏‏‎ ‎ ‎🛠
Forms Extension | Browser & Mobile Notifications Extension | Mixed Content Fixer Extension
User avatar
FredQ
Registered User
Posts: 138
Joined: Sat Nov 01, 2014 10:48 am
Location: Northeast Scotland
Name: Fred Q
Contact:

Re: What is the best way to make an extension testable?

Post by FredQ »

I see.
Well I did that for a few other tests as well but then I ran into issues where some functions were re-declared.

Typically you cannot run unit tests and functional tests in the same batch. I tried with the "separate process" option of phpunit but then it takes 3 hours to complete all my tests.

I'm not sure there's a better solution :roll:
My board (converted from vBulletin)
Post Reply

Return to “Extension Writers Discussion”