IterZipErrorTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace MathPHP\Tests\Util;
  3. use MathPHP\Util\Iter;
  4. class IterZipErrorTest extends \PHPUnit\Framework\TestCase
  5. {
  6. /**
  7. * @test Zipping a non-iterable is a type error
  8. * @dataProvider dataProviderForNonIterables
  9. * @param mixed $nonIterable
  10. */
  11. public function testNonIterableTypeError($nonIterable)
  12. {
  13. // Then
  14. $this->expectException(\TypeError::class);
  15. // When
  16. Iter::zip($nonIterable);
  17. }
  18. /**
  19. * @return array
  20. */
  21. public function dataProviderForNonIterables(): array
  22. {
  23. return [
  24. 'int' => [5],
  25. 'float' => [5.5],
  26. 'string' => ['abc def'],
  27. 'bool' => [true],
  28. 'object' => [new \stdClass()],
  29. ];
  30. }
  31. /**
  32. * @test Nothing to iterate does nothing
  33. */
  34. public function testNothingToIterate()
  35. {
  36. // Given
  37. $nothing = [];
  38. $result = [];
  39. // When
  40. foreach (Iter::zip($nothing) as $_) {
  41. $result[] = $_;
  42. }
  43. // Then
  44. $this->assertEmpty($result);
  45. }
  46. }