PHP code example of dholmes / bga-workbench

1. Go to this page and download the library: Download dholmes/bga-workbench library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dholmes / bga-workbench example snippets




namespace Game\Tests;

use PHPUnit\Framework\TestCase;
use BGAWorkbench\Test\TestHelp;
use Doctrine\DBAL\Connection;
use BGAWorkbench\Utils;

class ChooseAttackTest extends TestCase
{
    use TestHelp;
    
    protected function createGameTableInstanceBuilder() : TableInstanceBuilder
    {
        return $this->gameTableInstanceBuilder()
            ->setPlayersWithIds([66, 77])
            ->overridePlayersPostSetup([
                66 => ['player_color' => 'ff0000'],
                77 => ['player_color' => '00ff00']
            ]);
    }
    
    public function testAction()
    {
        $action = $this->table
            ->setupNewGame()
            ->withDbConnection(function (Connection $db) {
                $db->exec('INSERT battlefield_card (player_id, type, x, y) VALUES (' .
                    join('), (', [
                        [77, '"infantry"', 0, -1],  
                        [66, '"infantry"', 0, 1],  
                        [66, '"artillery"', 6, 1],  
                    ])
                . ')');
            })
            ->createActionInstanceForCurrentPlayer(66)
            ->stubActivePlayerId(66)
            ->stubArgs(['x' => 5, 'y' => 5]);

        $action->chooseAttack();
        
        // TODO: Run some asserts on the db
    }
    
    public function testStateFunc()
    {
        $game = $this->table
            ->setupNewGame()
            ->createGameInstanceWithNoBoundedPlayer()
            ->stubActivePlayerId(66);
        
        $game->stNextPlayer();
    }
    
    public function testGetAllDatas()
    {
        $game = $this->table
            ->setupNewGame()
            ->withDbConnection(function (Connection $db) {
                $db->exec('DELETE FROM deck_card');
                $db->exec('DELETE FROM playable_card');
                $db->exec('INSERT INTO battlefield_card (player_id, type, x, y) VALUES (66, "tank", 0, 2)');
                $db->executeUpdate('UPDATE player SET player_score_aux = 1 WHERE player_id = 66');
            })
            ->createGameInstanceForCurrentPlayer(66);

        $datas = Utils::callProtectedMethod($game, 'getAllDatas');
        
        // TODO: Some asserts on $datas
    }
}