Skip to content

Commit a5c5881

Browse files
committed
feat: Add docs test suites for MySQL nested sets behavior, covering cache management, exception handling, extensibility, node operations, and validation.
1 parent 9b727f7 commit a5c5881

12 files changed

+273
-1
lines changed

tests/mysql/CacheManagementTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@
88
use yii2\extensions\nestedsets\tests\base\AbstractCacheManagement;
99
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

11+
/**
12+
* Test suite for cache invalidation in nested sets tree behaviors using MySQL.
13+
*
14+
* Verifies correct cache management, invalidation, and memoization for nested sets tree structures in MySQL
15+
* environments, covering node insertions, updates, deletions, and structural changes for both single and multiple tree
16+
* models.
17+
*
18+
* Inherits integration and unit tests from {@see AbstractCacheManagement} to ensure cache lifecycle correctness,
19+
* including depth, left, and right attribute handling, and supports both manual and automatic cache invalidation
20+
* scenarios.
21+
*
22+
* Key features.
23+
* - Ensures compatibility and correctness of cache logic on the MySQL platform.
24+
* - Full coverage of cache population, invalidation, and memoization for nested sets behaviors.
25+
* - MySQL-specific configuration for database connection and credentials.
26+
*
27+
* @see AbstractCacheManagement for test logic and scenarios.
28+
*
29+
* @copyright Copyright (C) 2023 Terabytesoftw.
30+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
31+
*/
1132
#[Group('mysql')]
1233
final class CacheManagementTest extends AbstractCacheManagement
1334
{

tests/mysql/ExceptionHandlingTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@
88
use yii2\extensions\nestedsets\tests\base\AbstractExceptionHandling;
99
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

11+
/**
12+
* Test suite for exception handling in nested sets tree behaviors using MySQL.
13+
*
14+
* Verifies correct exception throwing and error messages for invalid node operations and edge cases in nested sets tree
15+
* structures on MySQL, covering both single and multiple tree models.
16+
*
17+
* Inherits unit tests from {@see AbstractExceptionHandling} to ensure robustness of the nested sets behavior by
18+
* simulating invalid operations such as appending, inserting, deleting, and making root nodes under unsupported
19+
* conditions.
20+
*
21+
* Key features.
22+
* - Ensures error handling consistency for unsupported operations on MySQL.
23+
* - Full coverage for invalid append, insert, delete, and makeRoot operations.
24+
* - MySQL-specific configuration for database connection and credentials.
25+
* - Support for both single-tree and multi-tree models.
26+
* - Tests for exception messages and types in various edge cases.
27+
*
28+
* @see AbstractExceptionHandling for test logic and scenarios.
29+
*
30+
* @copyright Copyright (C) 2023 Terabytesoftw.
31+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
32+
*/
1133
#[Group('mysql')]
1234
final class ExceptionHandlingTest extends AbstractExceptionHandling
1335
{

tests/mysql/ExtensibilityTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@
88
use yii2\extensions\nestedsets\tests\base\AbstractExtensibility;
99
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

11+
/**
12+
* Test suite for extensibility in nested sets tree behaviors using MySQL.
13+
*
14+
* Verifies that protected methods in the nested sets behavior remain accessible and customizable for subclassing
15+
* scenarios on MySQL, ensuring extensibility for advanced use cases in both single-tree and multi-tree models.
16+
*
17+
* Inherits unit tests from {@see AbstractExtensibility} to validate the exposure and correct execution of key internal
18+
* methods, supporting framework extension and advanced customization in descendant classes.
19+
*
20+
* Key features.
21+
* - Ensures protected methods are accessible for subclass extension.
22+
* - MySQL-specific configuration for database connection and credentials.
23+
* - Supports both single-tree and multi-tree model scenarios.
24+
* - Tests before-insert and move operations for extensibility.
25+
* - Validates extensibility for root and non-root node operations.
26+
* - Verifies correct attribute assignment by protected methods.
27+
*
28+
* @see AbstractExtensibility for test logic and scenarios.
29+
*
30+
* @copyright Copyright (C) 2023 Terabytesoftw.
31+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
32+
*/
1133
#[Group('mysql')]
1234
final class ExtensibilityTest extends AbstractExtensibility
1335
{

tests/mysql/MutationTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,28 @@
55
namespace yii2\extensions\nestedsets\tests\mysql;
66

77
use PHPUnit\Framework\Attributes\Group;
8+
use yii\db\Exception;
89
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
910
use yii2\extensions\nestedsets\tests\support\model\MultipleTree;
1011
use yii2\extensions\nestedsets\tests\TestCase;
1112

13+
/**
14+
* Test suite for mutation operations in nested sets tree behaviors using MySQL.
15+
*
16+
* Verifies correct handling of leaf node ordering and left attribute consistency in multiple tree models on MySQL.
17+
*
18+
* Ensures that the `leaves()` method returns nodes in the expected order after direct manipulation of left and right
19+
* attributes, maintaining data integrity and predictable query results.
20+
*
21+
* Key features.
22+
* - Ensures consistent results from the `leaves()` method.
23+
* - MySQL-specific configuration for database connection and credentials.
24+
* - Uses the multiple tree model for mutation scenarios.
25+
* - Validates leaf node detection and ordering after manual updates.
26+
*
27+
* @copyright Copyright (C) 2023 Terabytesoftw.
28+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
29+
*/
1230
#[Group('mutation')]
1331
final class MutationTest extends TestCase
1432
{
@@ -19,6 +37,9 @@ protected function setUp(): void
1937
parent::setUp();
2038
}
2139

40+
/**
41+
* @throws Exception if an unexpected error occurs during execution.
42+
*/
2243
public function testLeavesMethodRequiresLeftAttributeOrderingForConsistentResults(): void
2344
{
2445
$this->createDatabase();
@@ -51,7 +72,7 @@ public function testLeavesMethodRequiresLeftAttributeOrderingForConsistentResult
5172

5273
$leaves = MultipleTree::find()->leaves()->all();
5374

54-
/** @phpstan-var array<array{name: string, lft: int}> */
75+
/** @phpstan-var array<array{name: string, lft: int}> $expectedLeaves */
5576
$expectedLeaves = [
5677
['name' => 'Leaf B', 'lft' => 3],
5778
['name' => 'Leaf A', 'lft' => 5],

tests/mysql/NodeAppendTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88
use yii2\extensions\nestedsets\tests\base\AbstractNodeAppend;
99
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

11+
/**
12+
* Test suite for node append and root promotion in nested sets tree behaviors using MySQL.
13+
*
14+
* Provides comprehensive unit and integration tests for appending nodes and promoting nodes to root in nested sets tree
15+
* structures on MySQL, ensuring correct tree structure, attribute updates, and validation logic for both single-tree
16+
* and multi-tree models.
17+
*
18+
* Inherits tests from {@see AbstractNodeAppend} to validate node append operations, strict validation scenarios, root
19+
* promotion, and XML dataset matching after structural changes, covering edge cases such as validation bypass,
20+
* attribute refresh requirements, and cross-tree operations.
21+
*
22+
* Key features.
23+
* - Covers both {@see Tree} and {@see MultipleTree} model scenarios.
24+
* - Cross-tree append operations for multi-tree models.
25+
* - Ensures correct left, right, depth, and tree attribute updates for MySQL.
26+
* - MySQL-specific configuration for database connection and credentials.
27+
* - Root promotion and attribute refresh verification.
28+
* - Validation of strict and non-strict append operations.
29+
* - XML dataset matching after structural changes.
30+
*
31+
* @see AbstractNodeAppend for test logic and scenarios.
32+
*
33+
* @copyright Copyright (C) 2023 Terabytesoftw.
34+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
35+
*/
1136
#[Group('mysql')]
1237
final class NodeAppendTest extends AbstractNodeAppend
1338
{

tests/mysql/NodeDeleteTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@
88
use yii2\extensions\nestedsets\tests\base\AbstractNodeDelete;
99
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

11+
/**
12+
* Test suite for node deletion in nested sets tree behaviors using MySQL.
13+
*
14+
* Provides comprehensive unit tests for node and subtree deletion operations in nested sets tree structures on MySQL,
15+
* ensuring correct state transitions, affected row counts, and data integrity after deletions for both single-tree and
16+
* multi-tree models.
17+
*
18+
* Inherits tests from {@see AbstractNodeDelete} to validate node deletion, subtree removals, abort scenarios,
19+
* transactional behavior, and update operations on node attributes, covering edge cases and XML dataset consistency
20+
* after deletions.
21+
*
22+
* Key features.
23+
* - Covers update operations and affected row count for node attribute changes.
24+
* - Ensures correct affected row counts for node and subtree deletions in both {@see Tree} and {@see MultipleTree} models.
25+
* - MySQL-specific configuration for database connection and credentials.
26+
* - Tests aborting deletions via `beforeDelete()` and transactional behavior.
27+
* - Validates XML dataset consistency after deletions.
28+
* - Verifies node state transitions after `deleteWithChildren()` (new record status, old attributes).
29+
*
30+
* @see AbstractNodeDelete for test logic and scenarios.
31+
*
32+
* @copyright Copyright (C) 2023 Terabytesoftw.
33+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
34+
*/
1135
#[Group('mysql')]
1236
final class NodeDeleteTest extends AbstractNodeDelete
1337
{

tests/mysql/NodeInsertTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@
88
use yii2\extensions\nestedsets\tests\base\AbstractNodeInsert;
99
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

11+
/**
12+
* Test suite for node insertion in nested sets tree behaviors using MySQL.
13+
*
14+
* Provides comprehensive unit tests for node insertion operations in nested sets tree structures on MySQL, ensuring
15+
* correct behavior for inserting nodes before and after targets, with and without validation, and across both
16+
* single-tree and multi-tree models.
17+
*
18+
* Inherits tests from {@see AbstractNodeInsert} to validate insertion logic, strict validation scenarios, cross-tree
19+
* insertions, and XML dataset matching after structural changes, covering edge cases such as validation bypass,
20+
* attribute refresh requirements, and multi-tree operations.
21+
*
22+
* Key features.
23+
* - Covers both {@see Tree} and {@see MultipleTree} model scenarios.
24+
* - Edge case handling for strict validation and cross-tree insertions.
25+
* - Ensures correct left, right, depth, and tree attribute updates for MySQL.
26+
* - MySQL-specific configuration for database connection and credentials.
27+
* - Validation of strict and non-strict insert operations.
28+
* - XML dataset matching after structural changes.
29+
*
30+
* @see AbstractNodeInsert for test logic and scenarios.
31+
*
32+
* @copyright Copyright (C) 2023 Terabytesoftw.
33+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
34+
*/
1135
#[Group('mysql')]
1236
final class NodeInsertTest extends AbstractNodeInsert
1337
{

tests/mysql/NodePrependTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@
88
use yii2\extensions\nestedsets\tests\base\AbstractNodePrepend;
99
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

11+
/**
12+
* Test suite for node prepend operations in nested sets tree behaviors using MySQL.
13+
*
14+
* Provides comprehensive unit and integration tests for prepending nodes in nested sets tree structures on MySQL,
15+
* ensuring correct tree structure, attribute updates, and validation logic for both single-tree and multi-tree models.
16+
*
17+
* Inherits tests from {@see AbstractNodePrepend} to validate node prepend operations, strict validation scenarios, and
18+
* XML dataset matching after structural changes, covering edge cases such as validation bypass, attribute refresh
19+
* requirements, and cross-tree operations.
20+
*
21+
* Key features.
22+
* - Covers both {@see Tree} and {@see MultipleTree} model scenarios.
23+
* - Ensures correct left, right, depth, and tree attribute updates after prepend operations for MySQL.
24+
* - MySQL-specific configuration for database connection and credentials.
25+
* - Tests for prepending new and existing nodes, including cross-tree operations.
26+
* - Validation of strict and non-strict prepend operations.
27+
* - XML dataset matching after structural changes.
28+
*
29+
* @see AbstractNodePrepend for test logic and scenarios.
30+
*
31+
* @copyright Copyright (C) 2023 Terabytesoftw.
32+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
33+
*/
1134
#[Group('mysql')]
1235
final class NodePrependTest extends AbstractNodePrepend
1336
{

tests/mysql/NodeStateTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@
88
use yii2\extensions\nestedsets\tests\base\AbstractNodeState;
99
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

11+
/**
12+
* Test suite for node state and relationship in nested sets tree behaviors using MySQL.
13+
*
14+
* Provides comprehensive unit tests for verifying node state, parent-child relationships, and root/leaf detection in
15+
* both single-tree and multi-tree nested sets models on MySQL.
16+
*
17+
* Inherits tests from {@see AbstractNodeState} to ensure correctness of methods that determine node ancestry, root
18+
* status, and leaf status by testing various edge cases and boundary conditions, such as equal left/right values and
19+
* ancestor chains.
20+
*
21+
* Key features.
22+
* - Coverage for both {@see Tree} and {@see MultipleTree} model implementations.
23+
* - Ensures correct behavior for left/right value manipulations and ancestor checks.
24+
* - MySQL-specific configuration for database connection and credentials.
25+
* - Tests for `isChildOf()` under different ancestor and boundary scenarios.
26+
* - Validation of `isRoot()` and `isLeaf()` logic for root, leaf, and intermediate nodes.
27+
*
28+
* @see AbstractNodeState for test logic and scenarios.
29+
*
30+
* @copyright Copyright (C) 2023 Terabytesoftw.
31+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
32+
*/
1133
#[Group('mysql')]
1234
final class NodeStateTest extends AbstractNodeState
1335
{

tests/mysql/QueryBehaviorTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@
88
use yii2\extensions\nestedsets\tests\base\AbstractQueryBehavior;
99
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

11+
/**
12+
* Test suite for query behavior in nested sets tree behaviors using MySQL.
13+
*
14+
* Provides comprehensive unit tests for query methods related to leaf and root node retrieval, ordering, and behavior
15+
* attachment in both single-tree and multi-tree nested sets models on MySQL, ensuring correctness of query methods
16+
* such as `leaves()` and `roots()`, including ordering guarantees, SQL generation, and error handling when the behavior
17+
* is detached or not attached to the owner.
18+
*
19+
* Inherits tests from {@see AbstractQueryBehavior} to validate deterministic ordering, correct node retrieval, SQL
20+
* structure, and exception handling for query behaviors.
21+
*
22+
* Key features.
23+
* - Ensures deterministic ordering of results by left and tree attributes.
24+
* - MySQL-specific configuration for database connection and credentials.
25+
* - Tests for correct leaf and root node retrieval in {@see Tree} and {@see MultipleTree} models.
26+
* - Validates SQL query structure for ordering requirements.
27+
* - Verifies exception handling when the behavior is detached or not attached to the query owner.
28+
*
29+
* @see AbstractQueryBehavior for test logic and scenarios.
30+
*
31+
* @copyright Copyright (C) 2023 Terabytesoftw.
32+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
33+
*/
1134
#[Group('mysql')]
1235
final class QueryBehaviorTest extends AbstractQueryBehavior
1336
{

0 commit comments

Comments
 (0)