Skip to content

Commit 8f2f57a

Browse files
committed
Implement another chunk of tests
1 parent 4fa194f commit 8f2f57a

8 files changed

+386
-10
lines changed

tests/Data/CollectionTest.php

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php namespace HybridauthTest\Hybridauth\Data;
2+
3+
use Hybridauth\Data\Collection;
4+
5+
class CollectionTest extends \PHPUnit_Framework_TestCase
6+
{
7+
public function some_random_id()
8+
{
9+
return 69;
10+
}
11+
12+
public function some_random_year()
13+
{
14+
return 2020;
15+
}
16+
17+
public function some_random_array()
18+
{
19+
return ['id' => 69, 'slugs' => ['Γεια σας', 'Bonjour', '안녕하세요', 'year' => 2020]];
20+
}
21+
22+
public function some_random_object()
23+
{
24+
$object = new \StdClass();
25+
$object->id = 69;
26+
$object->slugs = ['Γεια σας', 'Bonjour', '안녕하세요', 'year' => 2020];
27+
28+
return $object;
29+
}
30+
31+
public function test_instance_of()
32+
{
33+
$collection = new Collection;
34+
35+
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection);
36+
}
37+
38+
public function test_identity()
39+
{
40+
$array = $this->some_random_array();
41+
42+
$collection = new Collection($array);
43+
44+
$result = $collection->toArray();
45+
46+
$this->assertEquals($result, $array);
47+
}
48+
49+
/**
50+
* @covers Collection::exists
51+
*/
52+
public function test_exists()
53+
{
54+
$array = $this->some_random_array();
55+
56+
$collection = new Collection($array);
57+
58+
$this->assertTrue($collection->exists('id'));
59+
60+
$this->assertFalse($collection->exists('_non_existant_'));
61+
62+
//
63+
64+
$object = $this->some_random_object();
65+
66+
$collection = new Collection($object);
67+
68+
$this->assertTrue($collection->exists('id'));
69+
70+
$this->assertFalse($collection->exists('_non_existant_'));
71+
}
72+
73+
/**
74+
* @covers Collection::get
75+
*/
76+
public function test_get()
77+
{
78+
$array = $this->some_random_array();
79+
80+
$collection = new Collection($array);
81+
82+
$this->assertEquals($collection->get('id'), $this->some_random_id());
83+
84+
$this->assertNull($collection->get('_non_existant_'));
85+
86+
//
87+
88+
$object = $this->some_random_object();
89+
90+
$collection = new Collection($object);
91+
92+
$this->assertEquals($collection->get('id'), $this->some_random_id());
93+
94+
$this->assertNull($collection->get('_non_existant_'));
95+
}
96+
97+
/**
98+
* @covers Collection::filter
99+
*/
100+
public function test_filter()
101+
{
102+
$array = $this->some_random_array();
103+
104+
$collection = new Collection($array);
105+
106+
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('id'));
107+
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('slugs'));
108+
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('_non_existant_'));
109+
110+
$this->assertNull($collection->filter('slugs')->get('_non_existant_'));
111+
112+
$this->assertEquals($collection->filter('slugs')->get('year'), $this->some_random_year());
113+
114+
//
115+
116+
$object = $this->some_random_object();
117+
118+
$collection = new Collection($object);
119+
120+
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('id'));
121+
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('slugs'));
122+
$this->assertInstanceOf('\\Hybridauth\\Data\\Collection', $collection->filter('_non_existant_'));
123+
124+
$this->assertNull($collection->filter('slugs')->get('_non_existant_'));
125+
126+
$this->assertEquals($collection->filter('slugs')->get('year'), $this->some_random_year());
127+
}
128+
}

tests/Data/ParserTest.php

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php namespace HybridauthTest\Hybridauth\Data;
2+
3+
use Hybridauth\Data\Parser;
4+
5+
class ParserTest extends \PHPUnit_Framework_TestCase
6+
{
7+
public function test_instance_of()
8+
{
9+
$parser = new Parser;
10+
11+
$this->assertInstanceOf('\\Hybridauth\\Data\\Parser', $parser);
12+
}
13+
14+
/**
15+
* @covers Parser::parse
16+
* @covers Parser::parseJson
17+
*/
18+
public function test_parser_json()
19+
{
20+
$parser = new Parser;
21+
22+
$object = new \StdClass();
23+
$object->id = 69;
24+
$object->slugs = ['Γεια σας', 'Bonjour', '안녕하세요'];
25+
26+
$json = json_encode($object);
27+
28+
//
29+
30+
$result = $parser->parse($json);
31+
32+
$this->assertInstanceOf('\\StdClass', $result);
33+
34+
$this->assertEquals($result, $object);
35+
36+
//
37+
38+
$result = $parser->parseJson($json);
39+
40+
$this->assertInstanceOf('\\StdClass', $result);
41+
42+
$this->assertEquals($result, $object);
43+
}
44+
45+
/**
46+
* @covers Parser::parse
47+
* @covers Parser::parseQueryString
48+
*/
49+
public function test_parser_querystring()
50+
{
51+
$parser = new Parser;
52+
53+
$object = new \StdClass();
54+
$object->id = 69;
55+
$object->slug = 'oauth';
56+
57+
$string = 'id=69&slug=oauth';
58+
59+
//
60+
61+
$result = $parser->parse($string);
62+
63+
$this->assertInstanceOf('\\StdClass', $result);
64+
65+
$this->assertEquals($result, $object);
66+
67+
//
68+
69+
$result = $parser->parseQueryString($string);
70+
71+
$this->assertInstanceOf('\\StdClass', $result);
72+
73+
$this->assertEquals($result, $object);
74+
}
75+
}

tests/HybridauthTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class HybridauthTest extends \PHPUnit_Framework_TestCase
66
{
7-
public function testTodo()
7+
public function test_pass()
88
{
99
$this->assertTrue(true);
1010
}

tests/Storage/SessionTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
use Hybridauth\Storage\Session;
44

5+
session_start(); // they will hate me for this..
6+
57
class SessionTest extends \PHPUnit_Framework_TestCase
68
{
7-
public function some_randome_session_data()
9+
public function some_random_session_data()
810
{
911
return [
1012
[ 'foo', 'bar' ],
@@ -32,7 +34,9 @@ public function test_instance_of()
3234
}
3335

3436
/**
35-
* @dataProvider some_randome_session_data
37+
* @dataProvider some_random_session_data
38+
* @covers Session::get
39+
* @covers Session::set
3640
*/
3741
public function test_set_and_get_data($key, $value)
3842
{
@@ -46,7 +50,8 @@ public function test_set_and_get_data($key, $value)
4650
}
4751

4852
/**
49-
* @dataProvider some_randome_session_data
53+
* @dataProvider some_random_session_data
54+
* @covers Session::delete
5055
*/
5156
public function test_delete_data($key, $value)
5257
{
@@ -62,7 +67,8 @@ public function test_delete_data($key, $value)
6267
}
6368

6469
/**
65-
* @dataProvider some_randome_session_data
70+
* @dataProvider some_random_session_data
71+
* @covers Session::clear
6672
*/
6773
public function test_clear_data($key, $value)
6874
{
@@ -77,25 +83,29 @@ public function test_clear_data($key, $value)
7783
$this->assertNull($data);
7884
}
7985

86+
/**
87+
* @covers Session::clear
88+
*/
8089
public function test_clear_data_bulk()
8190
{
8291
$storage = new Session;
8392

84-
foreach ((array) $this->some_randome_session_data() as $key => $value) {
93+
foreach ((array) $this->some_random_session_data() as $key => $value) {
8594
$storage->set($key, $value);
8695
}
8796

8897
$storage->clear();
8998

90-
foreach ((array) $this->some_randome_session_data() as $key => $value) {
99+
foreach ((array) $this->some_random_session_data() as $key => $value) {
91100
$data = $storage->get($key);
92101

93102
$this->assertNull($data);
94103
}
95104
}
96105

97106
/**
98-
* @dataProvider some_randome_session_data
107+
* @dataProvider some_random_session_data
108+
* @covers Session::deleteMatch
99109
*/
100110
public function test_delete_match_data($key, $value)
101111
{

tests/User/ActivityTest.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php namespace HybridauthTest\Hybridauth\User;
2+
3+
use Hybridauth\User\Activity;
4+
5+
class ActivityTest extends \PHPUnit_Framework_TestCase
6+
{
7+
public function test_instance_of()
8+
{
9+
$activity = new Activity;
10+
11+
$this->assertInstanceOf('\\Hybridauth\\User\\Activity', $activity);
12+
}
13+
14+
public function test_has_attributes()
15+
{
16+
$this->assertClassHasAttribute('id', Activity::class);
17+
$this->assertClassHasAttribute('date', Activity::class);
18+
$this->assertClassHasAttribute('text', Activity::class);
19+
$this->assertClassHasAttribute('user', Activity::class);
20+
}
21+
22+
public function test_set_attributes()
23+
{
24+
$activity = new Activity;
25+
26+
$activity->id = true;
27+
$activity->date = true;
28+
$activity->text = true;
29+
$activity->user = true;
30+
}
31+
32+
/**
33+
* @expectedException Hybridauth\Exception\UnexpectedValueException
34+
*/
35+
public function test_property_overloading()
36+
{
37+
$activity = new Activity;
38+
39+
$activity->slug = true;
40+
}
41+
}

tests/User/ContactTest.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php namespace HybridauthTest\Hybridauth\User;
2+
3+
use Hybridauth\User\Contact;
4+
5+
class ContactTest extends \PHPUnit_Framework_TestCase
6+
{
7+
public function test_instance_of()
8+
{
9+
$contact = new Contact;
10+
11+
$this->assertInstanceOf('\\Hybridauth\\User\\Contact', $contact);
12+
}
13+
14+
public function test_has_attributes()
15+
{
16+
$this->assertClassHasAttribute('identifier', Contact::class);
17+
$this->assertClassHasAttribute('webSiteURL', Contact::class);
18+
$this->assertClassHasAttribute('profileURL', Contact::class);
19+
$this->assertClassHasAttribute('photoURL', Contact::class);
20+
$this->assertClassHasAttribute('displayName', Contact::class);
21+
$this->assertClassHasAttribute('description', Contact::class);
22+
$this->assertClassHasAttribute('email', Contact::class);
23+
}
24+
25+
public function test_set_attributes()
26+
{
27+
$contact = new Contact;
28+
29+
$contact->identifier = true;
30+
$contact->webSiteURL = true;
31+
$contact->profileURL = true;
32+
$contact->photoURL = true;
33+
$contact->displayName = true;
34+
$contact->description = true;
35+
$contact->email = true;
36+
}
37+
38+
/**
39+
* @expectedException Hybridauth\Exception\UnexpectedValueException
40+
*/
41+
public function test_property_overloading()
42+
{
43+
$contact = new Contact;
44+
45+
$contact->slug = true;
46+
}
47+
}

0 commit comments

Comments
 (0)