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