This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
/
MagicMethodsTest.php
93 lines (80 loc) · 2.53 KB
/
MagicMethodsTest.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
83
84
85
86
87
88
89
90
91
92
93
<?php
/*
* This file is part of the Witchcraft package
*
* Copyright (c) 2014-2016 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Project home:
* https://github.com/tuupola/witchcraft
*
*/
namespace Witchcraft\Test;
class MagicMethodsTest extends \PHPUnit_Framework_TestCase
{
public function testShouldGetAndSetOwner()
{
$unicorn = new Unicorn();
$this->assertEquals($unicorn->owner(), "tuupola");
$unicorn->owner("viemero");
$this->assertEquals($unicorn->owner(), "viemero");
}
public function testShouldGetAndSetColor()
{
$unicorn = new Unicorn();
$this->assertEquals($unicorn->color(), "rainbow");
$unicorn->color("black");
$this->assertEquals($unicorn->color(), "black");
}
public function testShouldGetAndSetBirthday()
{
$unicorn = new Unicorn();
$unicorn->birthday("1930-24-12");
$test = \DateTime::createFromFormat("Y-m-d", "1930-24-12");
$this->assertEquals($unicorn->birthday(), $test);
}
public function testShouldGetAge()
{
$unicorn = new Unicorn();
$unicorn->birthday("1930-24-10");
$this->assertEquals($unicorn->age(), "84 years");
}
public function testGetShouldThrowException()
{
$this->setExpectedException("Exception");
$unicorn = new Unicorn();
$unicorn->nosuch();
}
public function testSetShouldThrowException()
{
$this->setExpectedException("Exception");
$unicorn = new Unicorn();
$unicorn->nosuch(666);
}
public function testShouldGetAndSetDynamicFunction()
{
$unicorn = new Unicorn();
$unicorn->dynamic(function ($input) {
return "Got {$input}!";
});
$this->assertEquals($unicorn->dynamic("milk"), "Got milk!");
$unicorn->dynamic = function ($input) {
return "No {$input}!";
};
$this->assertEquals($unicorn->dynamic("beer"), "No beer!");
}
public function testShouldGetAndSetDynamicFunctionWithManyParameters()
{
$unicorn = new Unicorn();
$unicorn->dynamic(function ($foo, $bar) {
return "Got {$foo} and {$bar}!";
});
$this->assertEquals($unicorn->dynamic("milk", "honey"), "Got milk and honey!");
$unicorn->dynamic = function ($foo, $bar) {
return "No {$foo} or {$bar}!";
};
$this->assertEquals($unicorn->dynamic("beer", "vodka"), "No beer or vodka!");
}
}