GitHubCheckerTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2017 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 $input
  20. */
  21. public function testExceptionInvocation($input)
  22. {
  23. $checker = $this->getMockBuilder('Psy\\VersionUpdater\\GitHubChecker')
  24. ->setMethods(array('fetchLatestRelease'))
  25. ->getMock();
  26. $checker->expects($this->once())->method('fetchLatestRelease')->willReturn($input);
  27. $checker->isLatest();
  28. }
  29. /**
  30. * @dataProvider jsonResults
  31. *
  32. * @param $assertion
  33. * @param $input
  34. */
  35. public function testDataSetResults($assertion, $input)
  36. {
  37. $checker = $this->getMockBuilder('Psy\\VersionUpdater\\GitHubChecker')
  38. ->setMethods(array('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 array(
  49. array(false, json_decode('{"tag_name":"v9.0.0"}')),
  50. array(true, json_decode('{"tag_name":"v' . Shell::VERSION . '"}')),
  51. array(true, json_decode('{"tag_name":"v0.0.1"}')),
  52. array(true, json_decode('{"tag_name":"v0.4.1-alpha"}')),
  53. array(true, json_decode('{"tag_name":"v0.4.2-beta3"}')),
  54. array(true, json_decode('{"tag_name":"v0.0.1"}')),
  55. array(true, json_decode('{"tag_name":""}')),
  56. );
  57. }
  58. /**
  59. * @return array
  60. */
  61. public function malformedResults()
  62. {
  63. return array(
  64. array(null),
  65. array(false),
  66. array(true),
  67. array(json_decode('{"foo":"bar"}')),
  68. array(json_decode('{}')),
  69. array(json_decode('[]')),
  70. array(array()),
  71. array(json_decode('{"tag_name":false"}')),
  72. array(json_decode('{"tag_name":true"}')),
  73. );
  74. }
  75. }