Skip to content

Commit a37fa62

Browse files
added test for repo list component
1 parent 7e89147 commit a37fa62

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

tests/components/RepoListTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php namespace PKleindienst\GithubProjects\Tests\Components;
2+
3+
use PKleindienst\GithubProjects\Components\RepoList;
4+
use PKleindienst\GithubProjects\Classes\Github;
5+
use PluginTestCase;
6+
7+
class RepoListTest extends PluginTestCase
8+
{
9+
/**
10+
* @var \PKleindienst\GithubProjects\Components\RepoList
11+
*/
12+
protected $repoList;
13+
14+
/**
15+
* Setup
16+
*/
17+
public function setUp()
18+
{
19+
parent::setUp();
20+
$this->repoList = new RepoList();
21+
}
22+
23+
/**
24+
* Tests
25+
*/
26+
27+
public function testComponentsDetails()
28+
{
29+
$details = $this->repoList->componentDetails();
30+
$this->assertTrue(is_array($details));
31+
$this->assertCount(2, $details);
32+
}
33+
34+
/**
35+
* @dependsOn testComponentsDetails
36+
*/
37+
public function testComponentsDetailsKeys()
38+
{
39+
$details = $this->repoList->componentDetails();
40+
$this->assertArrayHasKey('name', $details);
41+
$this->assertArrayHasKey('description', $details);
42+
}
43+
44+
public function testDefineProperties()
45+
{
46+
$props = $this->repoList->defineProperties();
47+
$this->assertTrue(is_array($props));
48+
$this->assertCount(4, $props);
49+
$this->assertArrayHasKey('user', $props);
50+
$this->assertArrayHasKey('type', $props);
51+
$this->assertArrayHasKey('sort', $props);
52+
$this->assertArrayHasKey('direction', $props);
53+
}
54+
55+
/**
56+
* @dependsOn testDefineProperties
57+
*/
58+
public function testDefinePropertiesKeys()
59+
{
60+
$props = $this->repoList->defineProperties();
61+
$this->assertArrayHasKey('title', $props['user']);
62+
$this->assertArrayHasKey('title', $props['type']);
63+
$this->assertArrayHasKey('title', $props['sort']);
64+
$this->assertArrayHasKey('title', $props['direction']);
65+
}
66+
67+
public function testOnRun()
68+
{
69+
// mock github dependency
70+
$mock = $this->getMock(RepoList::class, ['getGithub'], [], '', false);
71+
$mock->expects($this->once())
72+
->method('getGithub')
73+
->will($this->returnCallback(function () {
74+
$ghMock = $this->getMock(Github::class, ['repos'], [], '', false);
75+
$ghMock->expects($this->once())
76+
->method('repos')
77+
->will($this->returnCallback(function () {
78+
return [new \stdClass()];
79+
}));
80+
81+
return $ghMock;
82+
}));
83+
84+
// run Method
85+
$mock->onRun();
86+
$this->assertNotEmpty($mock->list);
87+
}
88+
89+
public function testGetGithub()
90+
{
91+
$this->assertInstanceOf(Github::class, $this->repoList->getGithub());
92+
}
93+
}

0 commit comments

Comments
 (0)