Skip to content

Commit

Permalink
Adding test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
reisraff committed Mar 26, 2016
1 parent 4d296d9 commit 0325b1b
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 19 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
vendor/
composer.lock
vendor/
material/
lazarus/backup/
lazarus/backup/
bin/*
!bin/.gitkeep
phpunit.xml
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: php

php:
- 5.6
- 7.0
- hhvm

before_install:
- travis_retry composer self-update

install:
- travis_retry composer install --no-interaction --prefer-source --dev

script:
- bin/phing

matrix:
allow_failures:
- php: hhvm
fast_finish: true
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ cd lazarus/
lazbuild phpgui.lpr
```

### Test

First install the dependencies, and after you can run:

```bash
bin/phing
```

## TO-DO

The "Issues" page from this repository is being used for TO-DO management, just search for the "to-do" tag.
Expand Down
Empty file added bin/.gitkeep
Empty file.
28 changes: 28 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="php-gui" basedir="." default="main">
<property name="examples" value="examples" />
<property name="source" value="src" />
<property name="bindir" value="bin" />

<fileset id="php-files" dir="${project.basedir}">
<include name="${project.source}/**/*.php"/>
</fileset>

<target name="main" description="Start analyzing our application">
<echo msg="Start Build" />

<phingCall target="phpunit" />
<phingCall target="phpcs" />

<echo msg="Finished Build" />
</target>

<target name="phpunit" description="Run unit tests using PHPUnit and generates junit.xml and clover.xml">
<exec passthru="true" command="${bindir}/phpunit" checkreturn="true"/>
</target>

<target name="phpcs" description="Coding Standards Analysis">
<exec passthru="true" command="${bindir}/phpcs --standard=PSR2 ${source}" checkreturn="true" />
<exec passthru="true" command="${bindir}/phpcs --standard=PSR2 ${examples}" checkreturn="true" />
</target>
</project>
11 changes: 10 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@
"require": {
"react/child-process": "^0.4.0"
},
"require-dev" : {
"phing/phing": "2.*",
"phpunit/phpunit": "4.5.*",
"squizlabs/php_codesniffer": "2.0.*@dev"
},
"config" : {
"bin-dir" : "bin/"
},
"autoload": {
"psr-4": {
"Gui\\": "src/"
"Gui\\": "src/",
"Test\\": "test/"
}
}
}
8 changes: 5 additions & 3 deletions examples/01-basic/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
$button->setValue('Ouch ' . $button->getCounter() . 'x');
$button->setCounter($button->getCounter() + 1);

if ($button->getCounter() == 20) {
if ($button->getCounter() >= 20) {
$text = 'Please, stop! You already clicked ' . preg_replace('/[^0-9]/', '', $button->getValue()) . ' times';
$input->setValue($text);
} else if ($button->getCounter() == 30) {
}

if ($button->getCounter() == 30) {
$button->setVisible(false);
}
});
});

$application->run();
$application->run();
31 changes: 31 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
syntaxCheck="true"
stopOnFailure="false"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Test Suite">
<directory>test/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<directory suffix="Interface.php">src</directory>
<directory suffix="Aware.php">src</directory>
<directory suffix="Trait.php">src</directory>
</exclude>
</whitelist>
<blacklist>
<directory>vendor</directory>
</blacklist>
</filter>
</phpunit>
10 changes: 5 additions & 5 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public function run()
if (OsDetector::isMacOS()) {
$processName = './phpgui-i386-darwin';
$processPath = __DIR__ . '/../lazarus/phpgui-i386-darwin.app/Contents/MacOS/';
} else if (OsDetector::isUnix()) {
} elseif (OsDetector::isUnix()) {
$processName = './phpgui-x86_64-linux';
$processPath = __DIR__ . '/../lazarus/';
} else if (OsDetector::isWindows()) {
} elseif (OsDetector::isWindows()) {
// @TODO: Windows binary
} else {
throw new RuntimeException('Operational System not identified by PHP-GUI.');
Expand All @@ -95,10 +95,10 @@ public function run()
$this->receiver = $receiver = new Receiver($this);
$this->sender = new Sender($this, $receiver);

$this->loop->addTimer(0.001, function($timer) use ($process, $application, $receiver) {
$this->loop->addTimer(0.001, function ($timer) use ($process, $application, $receiver) {
$process->start($timer->getLoop());

$process->stdout->on('data', function($data) use ($receiver) {
$process->stdout->on('data', function ($data) use ($receiver) {
$receiver->onData($data);
});

Expand Down Expand Up @@ -128,4 +128,4 @@ public function waitCommand($method, $params)

return $this->sender->waitReturn($message);
}
}
}
8 changes: 4 additions & 4 deletions src/Components/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct($defaultAttributes = null, $application = null)
'lazarusObjectId' => $this->lazarusObjectId,
]
],
function($result) use ($object) {
function ($result) use ($object) {
// Ok, object created
}
);
Expand Down Expand Up @@ -88,7 +88,7 @@ protected function set($name, $value)
$name,
$value
],
function($result) {
function ($result) {
// Ok, the property changed
}
);
Expand Down Expand Up @@ -134,7 +134,7 @@ public function on($eventName, $eventHandler)
$this->application->sendCommand('setObjectEventListener', [
$this->lazarusObjectId,
$eventName
], function($result) {
], function ($result) {
// Ok, the event listener created
});

Expand Down Expand Up @@ -332,4 +332,4 @@ public function getLazarusClass()
{
return $this->lazarusClass;
}
}
}
2 changes: 1 addition & 1 deletion src/Ipc/CommandMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ public function __construct($method, $params, $callback = false)
$this->params = $params;
$this->callback = $callback;
}
}
}
2 changes: 1 addition & 1 deletion src/Ipc/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

interface MessageInterface
{
}
}
2 changes: 1 addition & 1 deletion src/Ipc/Receiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ public function onData($data)
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Ipc/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ private function output($json)
{
echo 'Sent: ' . $json . PHP_EOL;
}
}
}
17 changes: 17 additions & 0 deletions test/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Test;

use Gui\Application;

class ApplicationTest extends \PHPUnit_Framework_TestCase
{
public function testGetNextObjectId()
{
$application = new Application();

$this->assertEquals(0, $application->getNextObjectId());
$this->assertEquals(1, $application->getNextObjectId());
$this->assertEquals(2, $application->getNextObjectId());
}
}

0 comments on commit 0325b1b

Please sign in to comment.