-
Notifications
You must be signed in to change notification settings - Fork 627
/
Copy pathSubstitutionTest.php
82 lines (68 loc) · 2.53 KB
/
SubstitutionTest.php
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
74
75
76
77
78
79
80
81
82
<?php
namespace SendGrid\Tests\Unit;
use PHPUnit\Framework\TestCase;
use SendGrid\Mail\Substitution;
use SendGrid\Mail\TypeException;
/**
* This file tests Substitutions.
*
* @package SendGrid\Tests\Unit
*/
class SubstitutionTest extends TestCase
{
public function testSubstitutionSetValue()
{
$substitution = new Substitution();
$testString = 'Twilio SendGrid is awesome!';
$testArray = ['one', 'two', 'three'];
$testObject = (object)array('1' => 'foo');
$testNumberInt = 1;
$testNumberFloat = 1.0;
$testInvalidInput = null;
$substitution->setValue($testString);
$this->assertEquals($substitution->getValue(), $testString);
$substitution->setValue($testArray);
$this->assertEquals($substitution->getValue(), $testArray);
$substitution->setValue($testObject);
$this->assertEquals($substitution->getValue(), $testObject);
$substitution->setValue($testNumberInt);
$this->assertEquals($substitution->getValue(), $testNumberInt);
$substitution->setValue($testNumberFloat);
$this->assertEquals($substitution->getValue(), $testNumberFloat);
$this->expectException('SendGrid\Mail\TypeException');
$substitution->setValue($testInvalidInput);
}
public function testConstructor()
{
$substitution = new Substitution('key', 'value');
$this->assertInstanceOf(Substitution::class, $substitution);
$this->assertSame('key', $substitution->getKey());
$this->assertSame('value', $substitution->getValue());
}
public function testSetKey()
{
$substitution = new Substitution();
$substitution->setKey('key');
$this->assertSame('key', $substitution->getKey());
}
public function testSetKeyOnInvalidType()
{
$this->expectException(TypeException::class);
$this->expectExceptionMessageMatches('/"\$key" must be a string/');
$substitution = new Substitution();
$substitution->setKey(true);
}
public function testSetValue()
{
$substitution = new Substitution();
$substitution->setValue('key');
$this->assertSame('key', $substitution->getValue());
}
public function testSetValueOnInvalidType()
{
$this->expectException(TypeException::class);
$this->expectExceptionMessageMatches('/"\$value" must be an array, object, boolean, string, numeric or integer/');
$substitution = new Substitution();
$substitution->setValue(null);
}
}