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