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:
<?php
namespace Nethgui\Test\Unit\Nethgui\View;
class CommandTest extends \PHPUnit_Framework_TestCase
{
protected $object;
private $origin;
protected function setUp()
{
$this->origin = $this->getMockBuilder('Nethgui\View\ViewInterface')->getMock();
$this->object = new \Nethgui\View\Command($this->origin, '../Id', 'test', array(1, 'A'));
}
public function testExecuteSuccess()
{
$receiver = $this->createReceiverMock();
$this->object->setReceiver($receiver)->execute();
}
public function testExecuteAlreadyFail()
{
$this->testExecuteSuccess();
try {
$this->object->execute();
} catch (\Exception $ex) {
$this->assertInstanceOf('LogicException', $ex);
}
}
private function createReceiverMock()
{
$receiver = $this->getMockBuilder('Nethgui\View\CommandReceiverInterface')
->setMethods(array('executeCommand'))
->getMock();
$receiver->expects($this->once())
->method('executeCommand')
->with($this->origin, '../Id', 'test', array(1, 'A'))
->will($this->returnValue('success'));
return $receiver;
}
public function testGetOrigin()
{
$this->assertSame($this->origin, $this->object->getOrigin());
}
public function testGetSelector()
{
$this->assertEquals('../Id', $this->object->getSelector());
}
public function testSetSelector()
{
$this->object->setSelector('/Id2');
$this->assertEquals('/Id2', $this->object->getSelector());
}
public function testExecuteFail()
{
try {
$this->object->execute();
} catch (\Exception $ex) {
$this->assertInstanceOf('LogicException', $ex);
}
}
public function testIsExecuted1()
{
$this->testExecuteSuccess();
$this->assertTrue($this->object->isExecuted());
}
public function testIsExecuted2()
{
$this->testExecuteFail();
$this->assertFalse($this->object->isExecuted());
}
public function testIsExecuted3()
{
$this->testExecuteSuccess();
$this->assertTrue($this->object->isExecuted());
try {
$this->object->execute();
} catch (\Exception $ex) {
$this->assertInstanceOf('LogicException', $ex);
}
}
}