Page 1 of 1

How can I test my PHP backend code outside the BGA platform?

Posted: 24 July 2025, 13:38
by zim921
Hi! I'm currently developing a game for BGA and I was wondering if there is any way to test or run the PHP backend code outside of the official BGA platform.
For example, can I simulate function calls or run game logic locally without having to always interact through the web interface?

Any suggestions, tools, or best practices would be appreciated!

Thanks in advance 🙏

Re: How can I test my PHP backend code outside the BGA platform?

Posted: 24 July 2025, 19:20
by RicardoRix
almost everything is tied to the BGA framework. It's difficult to know how you'd even attempt to accomplish that.

you can call a function direct from the chat.
or if you want - just put something in a constructor or getAllDatas() which will run on a page refresh.

Re: How can I test my PHP backend code outside the BGA platform?

Posted: 28 July 2025, 05:17
by ric1950
I was able to set up a project in my non-BGA IDE which I used to test the complex scoring algorithms for many different score goals in the game I was developing. I had to get the game to a certain stage, export the database and import it into my offline project. I had to set up Game.php with the scoring algorithms and then run the scoring function with:
<?php
include "Game.php";
$game = New Game();
$game->get_scores();
?>
I remember I had to make a few changes to the code get it to work but they were minor.
It was a bit of a fiddle but to me it was worth it - my testing would have taken forever using the BGA platform. And I enjoyed the challenge of doing it.

Re: How can I test my PHP backend code outside the BGA platform?

Posted: 17 February 2026, 15:33
by Yopai
Difficult to answer without the exact things you want to test, but maybe this principle will help :

Separate your code in individual testable classes.
So these class could be runnable with mocking of same BGA classes.

You can search for "phpunit mocking" on your favorite search engine for more information.

The idea is to have an interface class, emulating the return when you call it.

For the game logic itself, it would be really appreciated to have a complete local version, or at least mock, of the BGA classes.
The class skeleton you got when you start a project could be a good starting point.