菜谱项目

TextTest.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Faker\Test\Provider\zh_TW;
  3. class TextTest extends \PHPUnit_Framework_TestCase
  4. {
  5. private $textClass;
  6. public function setUp()
  7. {
  8. $this->textClass = new \ReflectionClass('Faker\Provider\zh_TW\Text');
  9. }
  10. protected function getMethod($name) {
  11. $method = $this->textClass->getMethod($name);
  12. $method->setAccessible(true);
  13. return $method;
  14. }
  15. /** @test */
  16. function testItShouldExplodeTheStringToArray()
  17. {
  18. $this->assertSame(
  19. array('中', '文', '測', '試', '真', '有', '趣'),
  20. $this->getMethod('explode')->invokeArgs(null, array('中文測試真有趣'))
  21. );
  22. $this->assertSame(
  23. array('標', '點', ',', '符', '號', '!'),
  24. $this->getMethod('explode')->invokeArgs(null, array('標點,符號!'))
  25. );
  26. }
  27. /** @test */
  28. function testItShouldReturnTheStringLength()
  29. {
  30. $this->assertContains(
  31. $this->getMethod('strlen')->invokeArgs(null, array('中文測試真有趣')),
  32. array(7, 21)
  33. );
  34. }
  35. /** @test */
  36. function testItShouldReturnTheCharacterIsValidStartOrNot()
  37. {
  38. $this->assertTrue($this->getMethod('validStart')->invokeArgs(null, array('中')));
  39. $this->assertTrue($this->getMethod('validStart')->invokeArgs(null, array('2')));
  40. $this->assertTrue($this->getMethod('validStart')->invokeArgs(null, array('Hello')));
  41. $this->assertFalse($this->getMethod('validStart')->invokeArgs(null, array('。')));
  42. $this->assertFalse($this->getMethod('validStart')->invokeArgs(null, array('!')));
  43. }
  44. /** @test */
  45. function testItShouldAppendEndPunctToTheEndOfString()
  46. {
  47. $this->assertSame(
  48. '中文測試真有趣。',
  49. $this->getMethod('appendEnd')->invokeArgs(null, array('中文測試真有趣'))
  50. );
  51. $this->assertSame(
  52. '中文測試真有趣。',
  53. $this->getMethod('appendEnd')->invokeArgs(null, array('中文測試真有趣,'))
  54. );
  55. $this->assertSame(
  56. '中文測試真有趣!',
  57. $this->getMethod('appendEnd')->invokeArgs(null, array('中文測試真有趣!'))
  58. );
  59. }
  60. }