GitHubCheckerTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2018 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Psy\Test\VersionUpdater;
  11. use Psy\Shell;
  12. class GitHubCheckerTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @dataProvider malformedResults
  16. * @expectedException \InvalidArgumentException
  17. * @expectedExceptionMessage Unable to check for updates
  18. *
  19. * @param mixed $input
  20. */
  21. public function testExceptionInvocation($input)
  22. {
  23. $checker = $this->getMockBuilder('Psy\\VersionUpdater\\GitHubChecker')
  24. ->setMethods(['fetchLatestRelease'])
  25. ->getMock();
  26. $checker->expects($this->once())->method('fetchLatestRelease')->willReturn($input);
  27. $checker->isLatest();
  28. }
  29. /**
  30. * @dataProvider jsonResults
  31. *
  32. * @param bool $assertion
  33. * @param mixed $input
  34. */
  35. public function testDataSetResults($assertion, $input)
  36. {
  37. $checker = $this->getMockBuilder('Psy\\VersionUpdater\\GitHubChecker')
  38. ->setMethods(['fetchLatestRelease'])
  39. ->getMock();
  40. $checker->expects($this->once())->method('fetchLatestRelease')->willReturn($input);
  41. $this->assertSame($assertion, $checker->isLatest());
  42. }
  43. /**
  44. * @return array
  45. */
  46. public function jsonResults()
  47. {
  48. return [
  49. [false, \json_decode('{"tag_name":"v9.0.0"}')],
  50. [true, \json_decode('{"tag_name":"v' . Shell::VERSION . '"}')],
  51. [true, \json_decode('{"tag_name":"v0.0.1"}')],
  52. [true, \json_decode('{"tag_name":"v0.4.1-alpha"}')],
  53. [true, \json_decode('{"tag_name":"v0.4.2-beta3"}')],
  54. [true, \json_decode('{"tag_name":"v0.0.1"}')],
  55. [true, \json_decode('{"tag_name":""}')],
  56. ];
  57. }
  58. /**
  59. * @return array
  60. */
  61. public function malformedResults()
  62. {
  63. return [
  64. [null],
  65. [false],
  66. [true],
  67. [\json_decode('{"foo":"bar"}')],
  68. [\json_decode('{}')],
  69. [\json_decode('[]')],
  70. [[]],
  71. [\json_decode('{"tag_name":false"}')],
  72. [\json_decode('{"tag_name":true"}')],
  73. ];
  74. }
  75. }