Unittests for my own Joomla extension

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
LordRazen
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Tue Jul 07, 2020 1:51 pm

Unittests for my own Joomla extension

Post by LordRazen » Sun Nov 07, 2021 11:38 am

Hi,

I just work on a new Joomla 3 extension (I know Joomla 4 is out dont worry) and I would like to create unittests for several of my helper methods. Now I've spend the last two days reading all kind of documentations I could find, but I cant get it to work.

Main Problem: I cant get the phpunit to work so it recognizes my Joomla classes.

What I did so far:
I've setup a folder with some very easy phpunit tests to make the system run. I tryed the "phpunit" command with a phpunit.xml, but this always result in the following error:

Code: Select all

PHP Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 277
I've read this is some kind of compatibility error and I also updated XAMPP to the newest version, but it didnt help. So I run PHPUnit with this command: ".\vendor\bin\phpunit .\tests\" and it runs the tests. So far so good.

I also try to bootstrap Joomla with files like those here:
https://github.com/joomla/test-integrat ... tstrap.php
Which I adjust for my personal usage, but all of those bootstrap files are several years old and might not work properly, even with my changes.

Since the "phpunit" command didnt work, I load this with ".\vendor\bin\phpunit .\tests\ --bootstrap .\bootstrap.php" or add a "require_once(__DIR__ . '/../../bootstrap.php');" to my PHPUnit Test files.

However... the class loading of Joomla Classes in the Testfiles don't work. I try to establish a very simple example with this Joomla method: "FilterOutput::stringURLSafe($test)", Just to see if the classes are loaded, but I cant get it to work.

Any input for any mentioned point here would be very helpful since I'm really kinda lost..

Thanks already ^^
Last edited by toivo on Mon Nov 08, 2021 4:39 am, edited 1 time in total.
Reason: mod note: moved from 3.x Extensions

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17426
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Unittests for my own Joomla extension

Post by toivo » Mon Nov 08, 2021 4:39 am

Mod note: moved to 3.x Coding.
Toivo Talikka, Global Moderator

LordRazen
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Tue Jul 07, 2020 1:51 pm

Re: Unittests for my own Joomla extension

Post by LordRazen » Mon Nov 15, 2021 7:48 am

Hm... I'm wondering there's no easy solution for Unittests that I overlooked somehow.

So I've a simple question in the end: How do you test the applications you build?


Locked

Return to “Joomla! 3.x Coding”