AcronymTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * By adding type hints and enabling strict type checking, code can become
  4. * easier to read, self-documenting and reduce the number of potential bugs.
  5. * By default, type declarations are non-strict, which means they will attempt
  6. * to change the original type to match the type specified by the
  7. * type-declaration.
  8. *
  9. * In other words, if you pass a string to a function requiring a float,
  10. * it will attempt to convert the string value to a float.
  11. *
  12. * To enable strict mode, a single declare directive must be placed at the top
  13. * of the file.
  14. * This means that the strictness of typing is configured on a per-file basis.
  15. * This directive not only affects the type declarations of parameters, but also
  16. * a function's return type.
  17. *
  18. * For more info review the Concept on strict type checking in the PHP track
  19. * <link>.
  20. *
  21. * To disable strict typing, comment out the directive below.
  22. */
  23. declare(strict_types=1);
  24. class AcronymTest extends PHPUnit\Framework\TestCase
  25. {
  26. public static function setUpBeforeClass(): void
  27. {
  28. require_once 'Acronym.php';
  29. }
  30. public function testBasicTitleCase(): void
  31. {
  32. $this->assertEquals('PNG', acronym('Portable Network Graphics'));
  33. }
  34. public function testLowerCaseWord(): void
  35. {
  36. $this->assertEquals('ROR', acronym('Ruby on Rails'));
  37. }
  38. public function testCamelCase(): void
  39. {
  40. $this->assertEquals('HTML', acronym('HyperText Markup Language'));
  41. }
  42. public function testAllCapsWords(): void
  43. {
  44. $this->assertEquals('PHP', acronym('PHP: Hypertext Preprocessor'));
  45. }
  46. public function testHyphenated(): void
  47. {
  48. $this->assertEquals('CMOS', acronym('Complementary metal-oxide semiconductor'));
  49. }
  50. // Additional points for making the following tests pass
  51. public function testOneWordIsNotAbbreviated(): void
  52. {
  53. $this->assertEmpty(acronym('Word'));
  54. }
  55. public function testUnicode(): void
  56. {
  57. $phrase = 'Специализированная процессорная часть';
  58. $this->assertEquals('СПЧ', acronym($phrase));
  59. }
  60. }