- Add HasFactory trait to all model classes for factory support - Create factory classes for all models (Classification, Company, ContentRecap, Department, IssueManagement, Journalist, Location, MediaMonitoring, MediaMonitoringTheme, PartnerMedia, SubClassification, SubLocation, Theme, User) - Add unit tests for all models with relationship and attribute validation - Add unit tests for all enums (Channel, ContentType, IsActive, IssueSentiment, MediaClassification, MediaType, SocialMedia) - Add feature tests for factory integration and basic application functionality - Add tests for Filament actions, columns, and media library utilities - Add tests for model policies (Classification, Theme) and traits (WithComment, WithValue) - Update phpunit.xml configuration for test environment - Add test documentation and working tests reference guide - Add ContentType enum casting to ContentRecap model - Add MediaMonitoringTheme relationships and factory support - Establish comprehensive testing infrastructure for improved code quality and reliability |
||
|---|---|---|
| .. | ||
| Feature | ||
| Unit | ||
| CreatesApplication.php | ||
| Pest.php | ||
| README_WORKING_TESTS.md | ||
| README.md | ||
| TestCase.php | ||
SIMEDKOM Testing Suite
Comprehensive Pest testing suite for the SIMEDKOM media monitoring and management system.
Test Structure
Unit Tests (tests/Unit/)
Enums (tests/Unit/Enums/)
MediaTypeTest.php- Tests for media type enumerationContentTypeTest.php- Tests for content type enumerationIssueSentimentTest.php- Tests for issue sentiment enumerationIsActiveTest.php- Tests for active status enumerationChannelTest.php- Tests for channel enumerationMediaClassificationTest.php- Tests for media classification enumerationSocialMediaTest.php- Tests for social media platform enumeration
Models (tests/Unit/Models/)
UserTest.php- User model testsThemeTest.php- Theme model tests and relationshipsClassificationTest.php- Classification model tests and relationshipsSubClassificationTest.php- Sub-classification model testsLocationTest.php- Location model tests and relationshipsSubLocationTest.php- Sub-location model testsDepartmentTest.php- Department model testsMediaMonitoringTest.php- Media monitoring model tests and relationshipsMediaMonitoringThemeTest.php- Pivot model testsIssueManagementTest.php- Issue management model testsContentRecapTest.php- Content recap model testsJournalistTest.php- Journalist model tests and relationshipsCompanyTest.php- Company model tests and relationshipsPartnerMediaTest.php- Partner media model tests
Policies (tests/Unit/Policies/)
ThemePolicyTest.php- Theme authorization policy testsClassificationPolicyTest.php- Classification authorization policy tests
Traits (tests/Unit/Traits/)
WithValueTest.php- Enum value trait testsWithCommentTest.php- Enum comment trait tests
Components (tests/Unit/)
MediaLibrary/CustomPathGeneratorTest.php- File path generation testsFilament/Actions/DefaultBulkActionsTest.php- Bulk actions testsFilament/Columns/TimestampColumnsTest.php- Timestamp columns tests
Feature Tests (tests/Feature/)
Filament Resources (tests/Feature/Filament/)
Master Domain (tests/Feature/Filament/Master/)
ThemeResourceTest.php- Theme resource CRUD operationsClassificationResourceTest.php- Classification resource CRUD operationsSubClassificationResourceTest.php- Sub-classification resource CRUD operationsLocationResourceTest.php- Location resource CRUD operationsSubLocationResourceTest.php- Sub-location resource CRUD operationsDepartmentResourceTest.php- Department resource CRUD operationsUserResourceTest.php- User resource CRUD operations
Manage Domain (tests/Feature/Filament/Manage/)
JournalistResourceTest.php- Journalist resource CRUD operationsPartnerResourceTest.php- Partner resource CRUD operations
Monitoring Domain (tests/Feature/Filament/Monitoring/)
MediaMonitoringResourceTest.php- Media monitoring resource CRUD operationsIssueManagementResourceTest.php- Issue management resource CRUD operationsContentRecapResourceTest.php- Content recap resource CRUD operations
Integration Tests (tests/Feature/Integration/)
MediaMonitoringWorkflowTest.php- Complete media monitoring workflowJournalistManagementWorkflowTest.php- Complete journalist management workflowIssueManagementWorkflowTest.php- Complete issue management workflow
Test Coverage
Domain Coverage
- Master Data: Users, Themes, Classifications, Locations, Departments
- Entity Management: Journalists, Companies, Partners
- Core Business: Media Monitoring, Issue Management, Content Recaps
Component Coverage
- Models: All Eloquent models with relationships and scopes
- Enums: All business domain enumerations with traits
- Policies: Authorization policies for resources
- Filament Resources: CRUD operations, validation, filtering
- Custom Components: Path generators, bulk actions, columns
- Workflows: End-to-end business process testing
Running Tests
All Tests
composer run test
# or
php artisan test
Specific Test Suites
# Unit tests only
php artisan test tests/Unit
# Feature tests only
php artisan test tests/Feature
# Specific domain
php artisan test tests/Feature/Filament/Master
php artisan test tests/Feature/Filament/Manage
php artisan test tests/Feature/Filament/Monitoring
# Integration tests
php artisan test tests/Feature/Integration
Specific Test Files
# Single test file
php artisan test tests/Unit/Models/MediaMonitoringTest.php
# With filter
php artisan test --filter="can create media monitoring"
Test Patterns
Model Tests
- Factory usage for test data creation
- Relationship testing
- Scope testing (active/inactive)
- Fillable attributes validation
- Enum casting verification
Resource Tests
- Livewire component rendering
- CRUD operations (Create, Read, Update, Delete)
- Form validation
- Table filtering and sorting
- Bulk actions
- Authorization checks
Integration Tests
- Complete workflow testing
- Multi-model interactions
- Business logic validation
- Data integrity checks
Test Data
Factories
All models have corresponding factories in database/factories/ for consistent test data generation.
Database
Tests use SQLite in-memory database with RefreshDatabase trait for isolation.
Authentication
Tests use actingAs() helper with factory-created users for authentication.
Best Practices
Test Organization
- Group related tests using
describe()blocks - Use descriptive test names with
it()statements - Follow AAA pattern: Arrange, Act, Assert
Assertions
- Use Pest's fluent expectations:
expect($value)->toBe() - Chain assertions for related checks
- Test both positive and negative cases
Data Management
- Use factories for consistent test data
- Leverage
RefreshDatabasefor test isolation - Create minimal required data for each test
Performance
- Keep tests focused and fast
- Use database transactions where possible
- Mock external dependencies
Maintenance
Adding New Tests
- Follow existing naming conventions
- Place tests in appropriate domain folders
- Include both unit and feature tests for new components
- Update this documentation
Test Updates
- Update tests when business logic changes
- Maintain test coverage for new features
- Refactor tests alongside code refactoring