icon picker
Testing Guide

🎯 Test Philosophy

This document defines how the package will be tested, what will be tested, and why, following the principles of:
Test-Driven Development (TDD)
Simplicity without over-testing
Full functional coverage
Focus on real behavior, not unnecessary edge-cases
No UI, no API — purely model-driven, Laravel-based behavior.

📦 Package Core Areas to Test

📁 Models

Tag
Category
TagGroup

📁 Traits

HasTags
HasCategories

📁 Service Provider

Config merging
Model bindings from config
Migrations loading

📁 Core Business Logic

Tag creation
Category creation
Tag group creation
Assigning/removing tags from models
Assigning/removing categories from models
Querying models via tags and groups
Config model overriding

📦 Core Testing Zones

HasTags Trait
HasCategories Trait
TagGroup similarity resolution
Direct tag logic vs category-attached tag access
Edge & invalid input handling

✅ UNIT TESTS

🔹 HasTagsTraitTest.php

Table 2
Test
Purpose
it_has_tags_relationship_method
tags() morphToMany exists
it_defines_attach_sync_detach_methods
attachTags, syncTags, detachTags
it_defines_all_query_scopes
withTag, withTagGroup, etc.
it_defines_all_helper_methods
hasTag, hasTagGroup, etc.
There are no rows in this table

🔹 HasCategoriesTraitTest.php

Table 3
Test
Purpose
it_has_categories_method
categories() morphToMany exists
it_defines_attach_sync_detach_methods
attachCategories, syncCategories, detachCategories
it_has_all_query_scopes_defined
withCategory, withAnyCategory, etc.
it_has_all_helper_methods_defined
hasCategory, hasAllCategories, etc.
There are no rows in this table

🌐 FEATURE TESTS

🔹 TaggingTest.php — for HasTags

🔄 Tag Attachment

Table 4
Test
Description
it_can_attach_a_tag
Tag attaches correctly
it_can_sync_multiple_tags
Sync replaces tags
it_can_detach_a_tag
Tag detaches cleanly
it_does_not_duplicate_tags_on_repeated_attach
Safe repeat-attach
There are no rows in this table

❌ Failure Handling

Table 5
Test
Description
it_throws_exception_for_unknown_tag_name
Invalid string tag
it_throws_exception_for_invalid_tag_input_type
Invalid data types
There are no rows in this table

🔍 Tag Scopes

Table 6
Test
Description
it_can_query_with_tag
it_can_query_without_tag
it_can_query_with_all_tags
it_can_query_with_any_tag
it_can_query_without_any_tag
There are no rows in this table

🔍 Tag Group Scopes

Table 7
Test
Description
it_can_query_with_tag_group
it_can_query_with_any_tag_group
it_can_query_with_all_tag_groups
it_can_query_with_similar_tags
There are no rows in this table

🧪 Helper Checks

Table 8
Test
Description
it_can_check_has_tag
it_can_check_has_any_tag
it_can_check_has_all_tags_flexible
it_can_check_has_all_tags_strict
it_can_check_has_tag_group
it_can_check_has_any_tag_group
it_can_check_has_all_tag_groups_flexible
it_can_check_has_all_tag_groups_strict
it_can_return_all_tag_names
There are no rows in this table

⚙️ Edge Cases

Table 9
Test
Description
it_handles_empty_input_to_attach
it_ignores_duplicates_in_input
There are no rows in this table

🔹 CategorizingTest.php — for HasCategories

🔄 Category Attachment

Table 10
Test
Description
it_can_attach_a_category
it_can_sync_multiple_categories
it_can_detach_a_category
it_only_attaches_new_categories
There are no rows in this table

❌ Failures

Table 11
Test
Description
it_throws_exception_for_unknown_category_name
it_throws_exception_for_invalid_type_input
There are no rows in this table

🔍 Category Scopes

Table 12
Test
Description
it_can_query_with_specific_category
it_can_query_without_specific_category
it_can_query_with_all_categories
it_can_query_with_any_category
it_can_query_without_any_category
There are no rows in this table

🧪 Helper Checks

Table 13
Test
Description
it_can_check_if_model_has_category
it_can_check_if_model_has_any_category
it_can_check_if_model_has_all_categories_flexible
it_can_check_if_model_has_all_categories_strict
it_returns_all_attached_category_names
There are no rows in this table

⚙️ Edge Cases

Table 14
Test
Description
it_does_not_crash_on_empty_category_input
it_ignores_duplicates_in_array_input
There are no rows in this table

🔹 Optional (Read-Only) Category Tag Access

Table 15
Test
Description
it_can_access_tags_through_attached_categories
via tagsViaCategories() or category_tags
it_does_not_duplicate_tags_across_multiple_categories
There are no rows in this table

📁 Test Folder Structure

tests/
├── Feature/
│ ├── TaggingTest.php
│ ├── CategorizingTest.php
│ ├── OverridableModelsTest.php
│ ├── MigrationStructureTest.php
├── Unit/
│ ├── Models/
│ │ ├── TagTest.php
│ │ ├── CategoryTest.php
│ │ ├── TagGroupTest.php
│ ├── Traits/
│ │ ├── HasTagsTraitTest.php
│ │ ├── HasCategoriesTraitTest.php
│ ├── Providers/
│ │ └── ServiceProviderTest.php

⚙️ Test Setup Instructions

Use in-memory SQLite database
Load package migrations dynamically in TestCase
Use factories for Tag, Category, TagGroup, and TestModel
orchestra/testbench is used to simulate Laravel environment
pestphp/pest for clean, expressive test syntax

✅ Development Approach

TDD workflow: Red ➔ Green ➔ Refactor
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.