forked from gabrielrcouto/php-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Test; | ||
|
||
use Gui\Color; | ||
|
||
class ColorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testColorToLazarus() | ||
{ | ||
$lazarusColor = Color::toLazarus('#112233'); | ||
|
||
$this->assertTrue(is_int($lazarusColor)); | ||
$this->assertEquals(3351057, $lazarusColor); | ||
|
||
$lazarusColor = Color::toLazarus('112233'); | ||
$this->assertTrue(is_int($lazarusColor)); | ||
$this->assertEquals(3351057, $lazarusColor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Test\Components; | ||
|
||
use Gui\Application; | ||
use Gui\Components\Window; | ||
|
||
class ObjectTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testMagicCall() | ||
{ | ||
$mock = $this->getMockForAbstractClass( | ||
'Gui\Components\Object', | ||
[ | ||
[], | ||
null, | ||
new Application() | ||
] | ||
); | ||
|
||
$mock->expects($this->any()) | ||
->method('__call'); | ||
|
||
|
||
$mock->setFoo(1); | ||
$this->assertEquals(1, $mock->getFoo()); | ||
} | ||
|
||
public function testOnAndFire() | ||
{ | ||
$appMock = $this->getMockBuilder('Gui\Application') | ||
->setMethods(['sendCommand']) | ||
->getMock(); | ||
|
||
$appMock->expects($this->any()) | ||
->method('sendCommand'); | ||
|
||
$mock = $this->getMockForAbstractClass( | ||
'Gui\Components\Object', | ||
[ | ||
[], | ||
null, | ||
$appMock | ||
] | ||
); | ||
|
||
$bar = 0; | ||
$mock->on('foo', function () use (&$bar) { | ||
$bar++; | ||
}); | ||
|
||
$mock->fire('onfoo'); | ||
|
||
$this->assertEquals(1, $bar); | ||
} | ||
|
||
public function testGetLazarusClass() | ||
{ | ||
$mock = $this->getMockForAbstractClass( | ||
'Gui\Components\Object', | ||
[ | ||
[], | ||
null, | ||
new Application | ||
] | ||
); | ||
|
||
$this->assertEquals('TObject', $mock->getLazarusClass()); | ||
} | ||
|
||
public function testGetLazarusObjectId() | ||
{ | ||
$mock = $this->getMockForAbstractClass( | ||
'Gui\Components\Object', | ||
[ | ||
[], | ||
null, | ||
new Application | ||
] | ||
); | ||
|
||
$this->assertEquals(1, $mock->getLazarusObjectId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Test\Ipc; | ||
|
||
use Gui\Ipc\CommandMessage; | ||
|
||
class CommandMessageTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testConstructor() | ||
{ | ||
$method = 'method'; | ||
$params = ['param1' => 'param1']; | ||
$foo = 0; | ||
$msg = new CommandMessage( | ||
$method, | ||
$params, | ||
function () use (&$foo) { | ||
$foo++; | ||
} | ||
); | ||
|
||
$this->assertEquals($msg->method, $method); | ||
$this->assertEquals($msg->params, $params); | ||
$callback = $msg->callback; | ||
$callback(); | ||
$this->assertEquals(1, $foo); | ||
$this->assertInstanceOf('Gui\Ipc\MessageInterface', $msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Test\Ipc; | ||
|
||
use Gui\Ipc\CommandMessage; | ||
|
||
class EventMessageTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testConstructor() | ||
{ | ||
$method = 'method'; | ||
$params = ['param1' => 'param1']; | ||
$foo = 0; | ||
$event = new CommandMessage( | ||
$method, | ||
$params | ||
); | ||
|
||
$this->assertEquals($event->method, $method); | ||
$this->assertEquals($event->params, $params); | ||
$this->assertInstanceOf('Gui\Ipc\MessageInterface', $event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Test\Ipc; | ||
|
||
use Gui\Application; | ||
use Gui\Ipc\Receiver; | ||
|
||
class ReceiverTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testConstructor() | ||
{ | ||
$receiver = new Receiver(new Application()); | ||
|
||
$this->assertInstanceOf('Gui\Application', $receiver->application); | ||
} | ||
|
||
public function testAddMessageCallback() | ||
{ | ||
$receiver = new Receiver(new Application()); | ||
|
||
$foo = 0; | ||
$receiver->addMessageCallback( | ||
1, | ||
function () use (&$foo) { | ||
$foo++; | ||
} | ||
); | ||
|
||
$this->assertTrue(is_array($receiver->messageCallbacks)); | ||
$receiver->messageCallbacks[1](); | ||
$this->assertEquals(1, $foo); | ||
} | ||
|
||
public function testCallObjectEventListener() | ||
{ | ||
$application = new Application(); | ||
|
||
$obj = $this->getMockBuilder('Gui\Components\Window') | ||
->setConstructorArgs([[], null, $application]) | ||
->setMethods(['fire']) | ||
->getMock(); | ||
|
||
$obj->expects($this->once()) | ||
->method('fire') | ||
->with('foo'); | ||
|
||
$application->addObject($obj); | ||
|
||
$receiver = new Receiver($application); | ||
|
||
$receiver->callObjectEventListener(1, 'foo'); | ||
} | ||
|
||
public function testCallMessageCallback() | ||
{ | ||
$receiver = new Receiver(new Application()); | ||
|
||
$foo = null; | ||
$receiver->addMessageCallback( | ||
1, | ||
function ($result) use (&$foo) { | ||
$foo = $result; | ||
} | ||
); | ||
|
||
$receiver->callMessageCallback(1, 1); | ||
$this->assertEquals(1, $foo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Test\Ipc; | ||
|
||
use Gui\Application; | ||
use Gui\Ipc\Receiver; | ||
use Gui\Ipc\Sender; | ||
|
||
class SenderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testConstructor() | ||
{ | ||
$application = new Application(); | ||
$receiver = new Receiver($application); | ||
|
||
$sender = new Sender($application, $receiver); | ||
|
||
$this->assertInstanceOf('Gui\Application', $sender->application); | ||
$this->assertInstanceOf('Gui\Ipc\Receiver', $sender->receiver); | ||
} | ||
} |