FunctionsTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /*
  3. * This file is a part of the DiscordPHP project.
  4. *
  5. * Copyright (c) 2015-present David Cole <david.cole1340@gmail.com>
  6. *
  7. * This file is subject to the MIT license that is bundled
  8. * with this source code in the LICENSE.md file.
  9. */
  10. use PHPUnit\Framework\TestCase;
  11. use function Discord\contains;
  12. use function Discord\getColor;
  13. use function Discord\poly_strlen;
  14. final class FunctionsTest extends TestCase
  15. {
  16. public function containsProvider()
  17. {
  18. return [
  19. [true, 'hello, world!', ['hello']],
  20. [true, 'phpunit tests', ['p', 'u']],
  21. [false, 'phpunit tests', ['a']],
  22. ];
  23. }
  24. /**
  25. * @dataProvider containsProvider
  26. */
  27. public function testContains($expected, $needle, $haystack)
  28. {
  29. $this->assertEquals($expected, contains($needle, $haystack));
  30. }
  31. public function colorProvider()
  32. {
  33. return [
  34. [0xcd5c5c, 'indianred'],
  35. [0x00bfff, 'deepskyblue'],
  36. [0x00bfff, 0x00bfff],
  37. [0, 0],
  38. [0x00bfff, '0x00bfff'],
  39. ];
  40. }
  41. /**
  42. * @dataProvider colorProvider
  43. */
  44. public function testGetColor($expected, $color)
  45. {
  46. $this->assertEquals($expected, getColor($color));
  47. }
  48. public function strlenProvider()
  49. {
  50. return [
  51. [5, 'abcde'],
  52. [0, ''],
  53. [1, ' '],
  54. ];
  55. }
  56. /**
  57. * @dataProvider strlenProvider
  58. */
  59. public function testPolyStrlen($expected, $string)
  60. {
  61. $this->assertEquals($expected, poly_strlen($string));
  62. }
  63. }