FieldFactoryTest.php 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. namespace Cron\Tests;
  4. use Cron\FieldFactory;
  5. use InvalidArgumentException;
  6. use PHPUnit\Framework\TestCase;
  7. /**
  8. * @author Michael Dowling <mtdowling@gmail.com>
  9. */
  10. class FieldFactoryTest extends TestCase
  11. {
  12. /**
  13. * @covers \Cron\FieldFactory::getField
  14. */
  15. public function testRetrievesFieldInstances()
  16. {
  17. $mappings = [
  18. 0 => 'Cron\MinutesField',
  19. 1 => 'Cron\HoursField',
  20. 2 => 'Cron\DayOfMonthField',
  21. 3 => 'Cron\MonthField',
  22. 4 => 'Cron\DayOfWeekField',
  23. ];
  24. $f = new FieldFactory();
  25. foreach ($mappings as $position => $class) {
  26. $this->assertSame($class, \get_class($f->getField($position)));
  27. }
  28. }
  29. /**
  30. * @covers \Cron\FieldFactory::getField
  31. */
  32. public function testValidatesFieldPosition()
  33. {
  34. $this->expectException(InvalidArgumentException::class);
  35. $f = new FieldFactory();
  36. $f->getField(-1);
  37. }
  38. }