GitHubCheckerTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2023 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. use Psy\VersionUpdater\GitHubChecker;
  13. class GitHubCheckerTest extends \Psy\Test\TestCase
  14. {
  15. /**
  16. * @dataProvider malformedResults
  17. *
  18. * @param mixed $input
  19. */
  20. public function testExceptionInvocation($input)
  21. {
  22. $this->expectException(\InvalidArgumentException::class);
  23. $this->expectExceptionMessage('Unable to check for updates');
  24. $checker = $this->getMockBuilder(GitHubChecker::class)
  25. ->setMethods(['fetchLatestRelease'])
  26. ->getMock();
  27. $checker->expects($this->once())->method('fetchLatestRelease')->willReturn($input);
  28. $checker->isLatest();
  29. $this->fail();
  30. }
  31. /**
  32. * @dataProvider jsonResults
  33. *
  34. * @group isolation-fail
  35. *
  36. * @param bool $assertion
  37. * @param mixed $input
  38. */
  39. public function testDataSetResults($assertion, $input)
  40. {
  41. $checker = $this->getMockBuilder(GitHubChecker::class)
  42. ->setMethods(['fetchLatestRelease'])
  43. ->getMock();
  44. $checker->expects($this->once())->method('fetchLatestRelease')->willReturn($input);
  45. $this->assertSame($assertion, $checker->isLatest());
  46. }
  47. /**
  48. * @return array
  49. */
  50. public function jsonResults()
  51. {
  52. return [
  53. [false, \json_decode('{"tag_name":"v9.0.0"}')],
  54. [true, \json_decode('{"tag_name":"v'.Shell::VERSION.'"}')],
  55. [true, \json_decode('{"tag_name":"v0.0.1"}')],
  56. [true, \json_decode('{"tag_name":"v0.4.1-alpha"}')],
  57. [true, \json_decode('{"tag_name":"v0.4.2-beta3"}')],
  58. [true, \json_decode('{"tag_name":"v0.0.1"}')],
  59. [true, \json_decode('{"tag_name":""}')],
  60. ];
  61. }
  62. /**
  63. * @return array
  64. */
  65. public function malformedResults()
  66. {
  67. return [
  68. [null],
  69. [false],
  70. [true],
  71. [\json_decode('{"foo":"bar"}')],
  72. [\json_decode('{}')],
  73. [\json_decode('[]')],
  74. [[]],
  75. [\json_decode('{"tag_name":false"}')],
  76. [\json_decode('{"tag_name":true"}')],
  77. ];
  78. }
  79. }