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

Game development with Board Game Arena Studio
Post Reply
zim921
Posts: 11
Joined: 12 October 2022, 05:25

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

Post 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 🙏
User avatar
RicardoRix
Posts: 2540
Joined: 29 April 2012, 23:43

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

Post 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.
User avatar
ric1950
Posts: 24
Joined: 22 January 2025, 09:06

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

Post 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.
Yopai
Posts: 5
Joined: 26 November 2023, 16:54

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

Post 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.
Post Reply

Return to “Developers”