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: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161:
<?php
namespace Nethgui\Test\Unit\Test\Tool;
class MockStateTest extends \PHPUnit_Framework_TestCase
{
protected $object;
protected function setUp()
{
$this->object = new \Nethgui\Test\Tool\MockState;
}
protected function tearDown()
{
}
public function testReturnValues()
{
$o1 = $this->object->set('getV1', 1);
$this->assertSame($o1, $this->object);
$o2 = $this->object->set('getV2', 2);
$this->assertSame($o2, $this->object);
$t = $this->object->transition('setV3');
$this->assertNotSame($t, $this->object);
}
public function testSetValuesThenExec()
{
$this->object->set('getV1', 1);
$this->object->set('getV2', 2);
$v1 = NULL;
$v2 = NULL;
$this->object->exec('getV1', $v1);
$this->object->exec('getV2', $v2);
$this->assertEquals(1, $v1);
$this->assertEquals(2, $v2);
}
public function testTransition()
{
$o0 = $this->object;
$o0->set('a', 1);
$o1 = $o0->transition('a++');
$o1->set('a', 2);
$aOut = NULL;
$o0->exec('a', $aOut);
$this->assertEquals(1, $aOut);
$o1->exec('a', $aOut);
$this->assertEquals(2, $aOut);
$fOut = '';
$this->assertSame($o1, $o0->exec('a++', $fOut));
$this->assertNull($fOut);
}
public function testFull()
{
$o = $this->object;
$o->set('k', 3);
for ($i = 0; $i < 3; $i ++ ) {
$o = $o->set('i', $i)->transition('i++');
}
$o = $this->object;
for ($i = 0; $i < 3; $i ++ ) {
$kOut = NULL;
$o = $o->exec('k', $kOut);
$this->assertEquals(3, $kOut);
$iOut = NULL;
$o = $o->exec('i', $iOut);
$this->assertEquals($i, $iOut);
$o = $o->exec('i++', $iOut);
$this->assertNull($iOut);
}
}
public function testCall()
{
$this->assertEquals(array('m', array(1, 2, 3)), $this->object->call('m', 1, 2, 3));
$this->assertEquals(array('n', array()), $this->object->call('n'));
}
public function testCallInvalid()
{
$v = $this->object->call();
}
public function testExecFail()
{
$output = NULL;
$this->object->exec('FAIL', $output);
$this->assertEquals(NULL, $output);
}
public function testSetFinal()
{
$this->object->setFinal();
$this->assertTrue($this->object->isFinal());
}
}