Commit Graph

16 Commits

Author SHA1 Message Date
Harald Eilertsen
33c95c810a tests: Make loadFixtures public
Some tests will need to load their own database fixtures. By making this
API public we make it easy for them to do so.

This change is needed by the tests for the Superblock addon.

Project......: Improve Superblock Addon
Sponsored-by.: NLnet NGI0 Commons Fund
2026-03-11 11:40:31 +01:00
Harald Eilertsen
b74a2dff9e Reload test fixtures from db
Reload inserted rows from the DB when loading the test fixtures. This
ensures that we get all default fields and id columns initialized and
validated. Some code under test will require this to work as expected.
2025-11-13 19:51:39 +01:00
Harald Eilertsen
3a2f787f96 Add Zotlabs\Lib\Mailer class to replace z_mail function. 2024-11-22 09:59:14 +00:00
Harald Eilertsen
90bc987ea7 tests: Fix typo in UnitTestCase.
Uncovered by PHP 8.2 because dynamic properties are deprecated.
2024-11-03 08:32:01 +01:00
Harald Eilertsen
350f84913a Skip checking MFA status for WebDAV and CardDAV requests. 2024-06-05 07:59:42 +00:00
Harald Eilertsen
cad82d12d2 Upgrade test framework to PHPUnit 10.5 2024-05-27 06:17:05 +00:00
Harald Eilertsen
4d29cffde5 Improve docs for UnitTestCase class. 2024-05-01 17:03:03 +02:00
Harald Eilertsen
39448a0871 Fix test db setup on MySQL/Mariadb + changed default 2024-03-14 12:42:03 +00:00
Harald Eilertsen
25dbc8a9f6 include/dba: Make Dba driver transaction aware.
This patch introduced database transaction support to the Dba driver via
the DbaTransaction class.

The goal of this is to allow the driver control over the creation and
finalization of database transactions.

Until now code that has needed transaction support has done so directly
by issuing "BEGIN", "ROLLBACK" and "COMMIT" commands to the underlying
database directly.

This has several disadvantages:

  - We do have no control or knowledge of whether any transactions being
	active.

  - Since transactions can not be nested, we run the risk of unrelated
	code trying to create a transaction when one is already active.

  - Code using transactions are not testable, as the test runner wraps
	all tests within a transaction to begin with.

This patch should eliminate all these problems.

A transaction is started by instantiating the DbaTransaction class:

    $my_transaction = new \DbaTransaction();

The transaction will automatically be _rolled back_ if it has not been
committed before the instance is destroyed. (When the variable holding
it goes out of scope, i.e when the containing function returns.)

A transaction is committed like this:

    $my_transaction->commit();

This will immediately commit the changes in the transaction, and the
transaction will be marked as committed, so it will not be attempted to
be rolled back on destruction.

I have chosen to "ignore" the problem of nested transactions by having
the DbaTransaction class _not_ initiate a new transaction if one is
already active. This also makes the rollback and commit actions of the
DbaTransaction class into no-ops.

An alternative would be to simulate nested transactions by using save
points if a transaction is already active. However, I'm unsure about
wether there's any safe way to avoid all potential pitfalls when doing
that.

In any case, nested transactions should preferably be avoided, and
afaict we don't rely on that in any of the existing code. The reason we
need to support it in some way is that it's needed for testing where the
code under test is creating a transaction on it's own. (Since each test
is run within a db transaction to begin with.)

Also, I have taken the liberty to assume a PDO based db driver for this
stuff. I don't think that's going to be a problem, as that's the only
thing supported by the rest of the code in any case.
2024-02-26 15:11:39 +01:00
Harald Eilertsen
ecd4754f6d tests: Enable debug logging during tests
The debug log will be stored in the test/results directory, and archived
as part of the artifacts of the CI run. This should make it easier to
get some debugging info out from the CI runs if they fail.
2024-01-15 19:25:09 +01:00
Harald Eilertsen
43dabee53d tests: Set app config in a known state for each test 2024-01-08 14:09:13 +01:00
Harald Eilertsen
99b5166f21 tests: Clean up unused debug stuff from UnitTestCase 2024-01-08 14:01:02 +01:00
Harald Eilertsen
0a31fc176c Remove behat as dev dependency.
As the Symphony\Yaml stuff disappeared with behat, we need another way
to load read the yaml files with database fixtures for the integration
tests.

As the php yaml extension is not distributed with PHP by default, this
creates it as another dev dependency!
2024-01-07 20:24:52 +01:00
Harald Eilertsen
e3d30763da tests: Integrate the DB in "unit" tests. 2024-01-06 16:34:38 +00:00
Harald Eilertsen
8c85516c57 Unit tests: Book Hubzilla to make app env available in tests.
Not quite unit test clean, but a somewhat pragmatic approach to make the
tests pass as is.
2023-06-14 23:00:44 +02:00
Klaus Weidenbach
b92e3ca3ee [TASK] Restructure tests/ folder.
Move unit tests to tests/unit/. Get the old still working UnitTests
into a working state again.
Updated composer.json with required-dev packages.
Create a new folder tests/acceptance for Behat functional/acceptance
testing. Add a first Feature draft of a Behat functional test for
local login.
2016-10-19 00:46:41 +02:00