1: <?php
2:
3: namespace PHPixie\Test;
4:
5: class Testcase extends \PHPUnit_Framework_TestCase
6: {
7: protected function quickMock($class, $methods = array())
8: {
9: return $this->getMock($class, $methods, array(), '', false);
10: }
11:
12: protected function abstractMock($class, $methods = array())
13: {
14: if(empty($methods)){
15: $reflection = new \ReflectionClass($class);
16: foreach($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method)
17: $methods[]=$method->getName();
18: }
19: return $this->getMockForAbstractClass($class, array(), '', false, false, true, $methods);
20: }
21:
22: protected function method($mock, $method, $return, $with = null, $at = null, $returnCallable = false) {
23:
24: if($at === null) {
25: $at = $this->any();
26: }elseif($at === 'once')
27: {
28: $at = $this->once();
29: }else{
30: $at = $this->at($at);
31: }
32:
33: $method = $mock
34: ->expects($at)
35: ->method($method);
36: if ($with !== null) {
37: foreach($with as $key => $value)
38: $with[$key] = $this->identicalTo($value);
39: $method = call_user_func_array(array($method, 'with'), $with);
40: }
41: $method
42: ->will($this->returnValue($return));
43: if (is_callable($return) && !$returnCallable && !is_array($return)) {
44: $method->will($this->returnCallback($return));
45: }else
46: $method->will($this->returnValue($return));
47: }
48:
49: protected function assertException($callback, $exceptionClass)
50: {
51: $except = false;
52: try{
53: $callback();
54: }catch(\Exception $e){
55: $except = $e instanceof $exceptionClass;
56: }
57: $this->assertEquals(true, $except);
58: }
59:
60: protected function assertInstance($object, $class, $propertyMap = array())
61: {
62: $this->assertInstanceOf($class, $object);
63: foreach($propertyMap as $name => $value) {
64: $this->assertAttributeEquals($value, $name, $object);
65: }
66: }
67:
68: }