-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuilderTest.php
More file actions
73 lines (57 loc) · 2.04 KB
/
BuilderTest.php
File metadata and controls
73 lines (57 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace ThisData\Api;
use ThisData\Api\Event\EventDispatcher;
class BuilderTest extends \PHPUnit_Framework_TestCase
{
const API_KEY = 'apikey';
/**
* @var Builder
*/
private $builder;
public $buildFlag = false;
public function setUp()
{
$this->builder = new Builder(self::API_KEY);
}
public function testSetVersion()
{
$this->assertFluentAttributeChange('version', '1', 'setVersion', '99');
}
public function testSetAsync()
{
$this->assertFluentAttributeChange('async', true, 'setAsync', false);
$this->builder->setAsync('badvalue');
$this->assertAttributeSame(true, 'async', $this->builder);
$this->builder->setAsync(0);
$this->assertAttributeSame(false, 'async', $this->builder);
}
public function testSetClientOption()
{
$result = $this->builder->setClientOption('option', 'value');
$this->assertInstanceOf(Builder::class, $result);
$ref = new \ReflectionClass($this->builder);
$property = $ref->getProperty('clientOptions');
$property->setAccessible(true);
$clientOptions = $property->getValue($this->builder);
$this->assertTrue(array_key_exists('option', $clientOptions));
$this->assertSame($clientOptions['option'], 'value');
}
public function testSetDispatcher()
{
$dispatcher = $this->getMock(EventDispatcher::class);
$this->builder->setDispatcher($dispatcher);
$this->assertAttributeSame($dispatcher, 'dispatcher', $this->builder);
}
public function testBuild()
{
$client = $this->builder->build();
$this->assertInstanceOf(ThisData::class, $client);
}
private function assertFluentAttributeChange($attribute, $initial, $setter, $new)
{
$this->assertAttributeSame($initial, $attribute, $this->builder);
$result = $this->builder->$setter($new);
$this->assertAttributeSame($new, $attribute, $this->builder);
$this->assertInstanceOf(Builder::class, $result);
}
}