php/tests/Feature/ScheduledAttributeTest.php
Snider 208cb93c95
All checks were successful
CI / PHP 8.3 (pull_request) Successful in 2m32s
CI / PHP 8.4 (pull_request) Successful in 2m17s
fix(dx): code style fixes, strict_types, and test repair
- Remove non-existent src/Core/Service/ from CLAUDE.md L1 packages list
- Fix LifecycleEventsTest: remove dependency on McpToolHandler interface
  (lives in core-mcp, not needed since McpToolsRegistering stores class
  name strings)
- Run Laravel Pint to fix PSR-12 violations across all source and test files
- Add missing declare(strict_types=1) to 18 PHP files (tests, seeders,
  Layout.php, GenerateServiceOgImages.php)

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-17 09:03:50 +00:00

60 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Tests\Feature;
use Core\Actions\Scheduled;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
class ScheduledAttributeTest extends TestCase
{
public function test_attribute_can_be_instantiated_with_frequency(): void
{
$attr = new Scheduled(frequency: 'dailyAt:09:00');
$this->assertSame('dailyAt:09:00', $attr->frequency);
$this->assertNull($attr->timezone);
$this->assertTrue($attr->withoutOverlapping);
$this->assertTrue($attr->runInBackground);
}
public function test_attribute_accepts_all_parameters(): void
{
$attr = new Scheduled(
frequency: 'weeklyOn:1,09:00',
timezone: 'Europe/London',
withoutOverlapping: false,
runInBackground: false,
);
$this->assertSame('weeklyOn:1,09:00', $attr->frequency);
$this->assertSame('Europe/London', $attr->timezone);
$this->assertFalse($attr->withoutOverlapping);
$this->assertFalse($attr->runInBackground);
}
public function test_attribute_targets_class_only(): void
{
$ref = new ReflectionClass(Scheduled::class);
$attrs = $ref->getAttributes(\Attribute::class);
$this->assertNotEmpty($attrs);
$instance = $attrs[0]->newInstance();
$this->assertSame(\Attribute::TARGET_CLASS, $instance->flags);
}
public function test_attribute_can_be_read_from_class(): void
{
$ref = new ReflectionClass(ScheduledAttributeTest_Stub::class);
$attrs = $ref->getAttributes(Scheduled::class);
$this->assertCount(1, $attrs);
$instance = $attrs[0]->newInstance();
$this->assertSame('everyMinute', $instance->frequency);
}
}
#[Scheduled(frequency: 'everyMinute')]
class ScheduledAttributeTest_Stub {}