Skip to content

Commit 47a86ef

Browse files
committed
feat: add PHPUnit testing infrastructure and initial unit tests
1 parent 897076d commit 47a86ef

9 files changed

Lines changed: 151 additions & 1 deletion

File tree

.github/workflows/phpunit.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: PHPUnit Tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Setup PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: '8.3'
19+
extensions: pdo_firebird, dom, xml, mbstring
20+
coverage: none
21+
22+
- name: Install dependencies
23+
run: composer install --prefer-dist --no-progress
24+
25+
- name: Run tests
26+
run: vendor/bin/phpunit

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@
1313
# Node dependencies
1414

1515
node_modules/
16+
17+
# PHP dependencies
18+
vendor/
19+
composer.lock

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ While there is no exhaustive manual, users familiar with Firebird will find the
7070
* **Ubuntu Guide:** [How to install Firebird on Ubuntu](https://help.ubuntu.com/community/Firebird3.0)
7171
* **Firebird Official Docs:** [Firebird Documentation](https://www.firebirdsql.org/en/documentation/)
7272

73+
## 🧪 Testing
74+
75+
### Unit Tests (PHPUnit)
76+
The project uses PHPUnit for unit testing core functions.
77+
1. Install dependencies: `composer install`
78+
2. Run tests: `./vendor/bin/phpunit`
79+
80+
### End-to-End Tests (Playwright)
81+
The project uses Playwright for E2E testing.
82+
1. Install dependencies: `npm install`
83+
2. Run tests: `npx playwright test`
84+
7385
---
7486

7587
## 📄 ChangeLog

composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "mariuz/firebirdwebadmin",
3+
"description": "FirebirdWebAdmin is a web frontend for the Firebird database server",
4+
"type": "project",
5+
"license": "GPL-2.0",
6+
"require-dev": {
7+
"phpunit/phpunit": "^10.5"
8+
},
9+
"autoload": {
10+
"files": [
11+
"inc/configuration.inc.php",
12+
"inc/functions.inc.php",
13+
"inc/firebird.inc.php"
14+
]
15+
}
16+
}

inc/configuration.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
// are not deleted when isql is finished
164164

165165

166-
if ('' != SESSION_NAME) {
166+
if ('' != SESSION_NAME && PHP_SAPI !== 'cli') {
167167
session_name(SESSION_NAME);
168168
}
169169

phpunit.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
colors="true">
6+
<testsuites>
7+
<testsuite name="Unit">
8+
<directory>tests/Unit</directory>
9+
</testsuite>
10+
</testsuites>
11+
<source>
12+
<include>
13+
<directory suffix=".php">inc</directory>
14+
</include>
15+
</source>
16+
</phpunit>

tests/Unit/FirebirdTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
class FirebirdTest extends TestCase
6+
{
7+
public function testGetPresetCharsets()
8+
{
9+
$charsets = get_preset_charsets();
10+
$this->assertIsArray($charsets);
11+
$this->assertContains('UTF8', $charsets);
12+
$this->assertContains('NONE', $charsets);
13+
}
14+
15+
public function testGetDatatypes()
16+
{
17+
$datatypes = get_datatypes();
18+
$this->assertIsArray($datatypes);
19+
$this->assertArrayHasKey(37, $datatypes); // VARCHAR
20+
$this->assertEquals('VARCHAR', $datatypes[37]);
21+
}
22+
}

tests/Unit/FunctionsTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
class FunctionsTest extends TestCase
6+
{
7+
protected function setUp(): void
8+
{
9+
// build_title depends on these globals
10+
$GLOBALS['s_connected'] = false;
11+
$GLOBALS['s_login'] = ['database' => 'test.fdb'];
12+
}
13+
14+
public function testBuildTitleDisconnected()
15+
{
16+
$GLOBALS['s_connected'] = false;
17+
$title = build_title('Database');
18+
$this->assertEquals('Firebird Web Admin / Database', $title);
19+
}
20+
21+
public function testBuildTitleConnected()
22+
{
23+
$GLOBALS['s_connected'] = true;
24+
$title = build_title('Database');
25+
$this->assertEquals('Firebird Web Admin / Database: test.fdb', $title);
26+
}
27+
}

tests/bootstrap.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
// Define Firebird constants if the extension is not loaded
4+
if (!defined('IBASE_COMMITTED')) {
5+
define('IBASE_COMMITTED', 1);
6+
}
7+
if (!defined('IBASE_NOWAIT')) {
8+
define('IBASE_NOWAIT', 1);
9+
}
10+
if (!defined('IBASE_READ')) {
11+
define('IBASE_READ', 1);
12+
}
13+
if (!defined('IBASE_WRITE')) {
14+
define('IBASE_WRITE', 1);
15+
}
16+
if (!defined('IBASE_STS_HDR_PAGES')) {
17+
define('IBASE_STS_HDR_PAGES', 1);
18+
}
19+
20+
// Load Composer autoloader
21+
require_once __DIR__ . '/../vendor/autoload.php';
22+
23+
// Load language file needed for some tests
24+
if (!defined('LANGUAGE')) {
25+
define('LANGUAGE', 'english');
26+
}
27+
require_once __DIR__ . '/../lang/english.inc.php';

0 commit comments

Comments
 (0)