mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-09 21:43:22 +09:00
* Improve type safety, auth checks and PHPStan fixes (#3250) * Improve type safety, auth checks and PHPStan fixes * Remove @phpstan-ignore annotations * Improve type safety, auth checks and PHPStan fixes * Remove @phpstan-ignore annotations * Remove redundant @phpstan-ignore comment * Improve code robustness and reliability (#3248) * Harden code against null/undefined values * Update dependency lockfiles * Sanitize ticket input and use IDs in email list * Restructure tests and add test utilities * Move E2E tests to `Library\E2E` namespace * Update `php-build` action ref in workflows * Switch tests to Pest and add test scaffolding * Refactor E2E tests to Pest-style tests m Skip E2E tests when env not configured * Refactor Unit tests and update test config Add test datasets and refine test helpers * Add DEBUG guard, fix API JSON decode, update tests * Refactor tests: add types and Mockery expectations * Adjust tests, phpstan config, and composer script * Instantiate test APIs locally, remove beforeEach * Refactor runtime checks, types & logging * Apply PHP Code Styling Changes m * Add PHPStan ignores, test renames & small fixes * Enable Pest tests in CI workflow * Remove legacy tests; add new unit tests/config * Avoid undefined index in fingerprint comparison * Ignore properties absent in both fingerprints * Remove public_ticket_create API method * Add Fingerprint unit tests * Remove em dash from fingerprint test name * Switch to Pest; assorted bug fixes & refactors * Prefer getDi() and guard DEBUG define * Refactor tests: DBAL, Antispam rename, helpers * Refactor email tests to use Doctrine entities * Update tests, use DBAL mocks & improve Formbuilder admin * Validate plan_id and update unit tests * Replace error_log with DI logger and update tests * Expect db->store in Invoice Service test * Use DI logger instead of error_log; fix tests * Fix typo in Hook Service test * Fix Staff test spelling fixture * Complete Pest test migration * Fix Product test spelling fixtures * Fix Product test spelling fixtures * Run live tests with Pest and load helpers * Migrate tests to ApiClient; remove legacy APIHelper * Fix Email test spelling * Remove unused PHPUnit bridge * Organize Cypress end-to-end tests * Document Pest test directory root * Remove noisy Pest comments
101 lines
2.4 KiB
PHP
101 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Copyright 2022-2026 FOSSBilling
|
|
* SPDX-License-Identifier: Apache-2.0.
|
|
*
|
|
* @copyright FOSSBilling (https://www.fossbilling.org)
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Helpers;
|
|
|
|
/**
|
|
* Create a mock model with the given properties.
|
|
* This replaces the old DummyBean pattern.
|
|
*/
|
|
function model(string $class, array $attributes = []): object
|
|
{
|
|
$instance = new $class();
|
|
|
|
// Handle RedBeanPHP models
|
|
if (method_exists($instance, 'loadBean')) {
|
|
$instance->loadBean(new DummyBean());
|
|
}
|
|
|
|
foreach ($attributes as $key => $value) {
|
|
$instance->$key = $value;
|
|
}
|
|
|
|
return $instance;
|
|
}
|
|
|
|
/**
|
|
* Create a client order model.
|
|
*/
|
|
function order(array $attributes = []): object
|
|
{
|
|
$defaults = [
|
|
'id' => random_int(1, 10000),
|
|
'client_id' => random_int(1, 10000),
|
|
'product_id' => random_int(1, 10000),
|
|
'status' => \Model_ClientOrder::STATUS_ACTIVE,
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
];
|
|
|
|
return model(\Model_ClientOrder::class, array_merge($defaults, $attributes));
|
|
}
|
|
|
|
/**
|
|
* Create a product model.
|
|
*/
|
|
function product(array $attributes = []): object
|
|
{
|
|
$defaults = [
|
|
'id' => random_int(1, 10000),
|
|
'title' => 'Test Product',
|
|
'type' => \Model_ProductTable::CUSTOM,
|
|
'status' => \Model_Product::STATUS_ENABLED,
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
];
|
|
|
|
return model(\Model_Product::class, array_merge($defaults, $attributes));
|
|
}
|
|
|
|
/**
|
|
* Create a client model.
|
|
*/
|
|
function client(array $attributes = []): object
|
|
{
|
|
$defaults = [
|
|
'id' => random_int(1, 10000),
|
|
'email' => 'test' . uniqid() . '@example.com',
|
|
'first_name' => 'Test',
|
|
'last_name' => 'User',
|
|
'status' => \Model_Client::ACTIVE,
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
];
|
|
|
|
return model(\Model_Client::class, array_merge($defaults, $attributes));
|
|
}
|
|
|
|
/**
|
|
* Create an admin model.
|
|
*/
|
|
function admin(array $attributes = []): object
|
|
{
|
|
$defaults = [
|
|
'id' => random_int(1, 10000),
|
|
'email' => 'admin' . uniqid() . '@example.com',
|
|
'name' => 'Admin User',
|
|
'status' => \Model_Admin::STATUS_ACTIVE,
|
|
];
|
|
|
|
return model(\Model_Admin::class, array_merge($defaults, $attributes));
|
|
}
|