Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
language: php
php:
- 7.3
- 7.2
- 7.1
- 7.0
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@
"psr-4": {
"predictionio\\": "src/predictionio/"
}
},
"autoload-dev": {
"psr-4": {
"predictionio\\tests\\Unit\\": "tests/Unit/"
}
}
}
3 changes: 2 additions & 1 deletion tests/Unit/EngineClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;

class EngineClientTest extends \PHPUnit_Framework_TestCase
class EngineClientTest extends TestCase
{
/** @var EngineClient $engineClient */
protected $engineClient;
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/EventClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use predictionio\EventClient;
use PHPUnit\Framework\TestCase;

class EventClientTest extends \PHPUnit_Framework_TestCase
class EventClientTest extends TestCase
{
/** @var EventClient $eventClient */
protected $eventClient;
Expand Down Expand Up @@ -319,7 +320,7 @@ public function testGetEvent()
$result=array_shift($this->container);
/** @var Request $request */
$request=$result['request'];
$body=json_decode($request->getBody(), true);
json_decode($request->getBody(), true);

$this->assertEquals('GET', $request->getMethod());
$this->assertEquals(
Expand Down
35 changes: 18 additions & 17 deletions tests/Unit/ExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace predictionio\tests\Unit;

use predictionio\Exporter;
use PHPUnit\Framework\TestCase;

class TestExporter
{
Expand Down Expand Up @@ -46,7 +47,7 @@ public function export($json)
}
}

class ExporterTest extends \PHPUnit_Framework_TestCase
class ExporterTest extends TestCase
{

/** @var TestExporter $exporter */
Expand All @@ -63,18 +64,18 @@ public function testTimeIsNow()

$this->exporter->createEvent('event', 'entity-type', 'entity-id');

$this->assertEquals(1, count($this->exporter->data));
$this->assertCount(1, $this->exporter->data);
$data = $this->exporter->data[0];
$this->assertEquals(4, count($data));
$this->assertCount(4, $data);
$this->assertEquals('event', $data['event']);
$this->assertEquals('entity-type', $data['entityType']);
$this->assertEquals('entity-id', $data['entityId']);
$this->assertEquals($time->format(\DateTime::ISO8601), $data['eventTime'], 'time is now', 1);

$this->assertEquals(1, count($this->exporter->json));
$this->assertCount(1, $this->exporter->json);
$json = $this->exporter->json[0];
$pattern = '/^{"event":"event","entityType":"entity-type","entityId":"entity-id","eventTime":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}"}$/';
$this->assertTrue(preg_match($pattern, $json) === 1, 'json');
$this->assertRegExp($pattern, $json, 'json');
}

public function testTimeIsString()
Expand All @@ -83,18 +84,18 @@ public function testTimeIsString()

$this->exporter->createEvent('event', 'entity-type', 'entity-id', null, null, null, '2015-04-01');

$this->assertEquals(1, count($this->exporter->data));
$this->assertCount(1, $this->exporter->data);
$data = $this->exporter->data[0];
$this->assertEquals(4, count($data));
$this->assertCount(4, $data);
$this->assertEquals('event', $data['event']);
$this->assertEquals('entity-type', $data['entityType']);
$this->assertEquals('entity-id', $data['entityId']);
$this->assertEquals($time->format(\DateTime::ISO8601), $data['eventTime'], 'time is string', 1);

$this->assertEquals(1, count($this->exporter->json));
$this->assertCount(1, $this->exporter->json);
$json = $this->exporter->json[0];
$pattern = '/^{"event":"event","entityType":"entity-type","entityId":"entity-id","eventTime":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}"}$/';
$this->assertTrue(preg_match($pattern, $json) === 1, 'json');
$this->assertRegExp($pattern, $json, 'json');
}

public function testTimeIsDateTime()
Expand All @@ -103,18 +104,18 @@ public function testTimeIsDateTime()

$this->exporter->createEvent('event', 'entity-type', 'entity-id', null, null, null, $time);

$this->assertEquals(1, count($this->exporter->data));
$this->assertCount(1, $this->exporter->data);
$data = $this->exporter->data[0];
$this->assertEquals(4, count($data));
$this->assertCount(4, $data);
$this->assertEquals('event', $data['event']);
$this->assertEquals('entity-type', $data['entityType']);
$this->assertEquals('entity-id', $data['entityId']);
$this->assertEquals($time->format(\DateTime::ISO8601), $data['eventTime'], 'time is DateTime', 1);

$this->assertEquals(1, count($this->exporter->json));
$this->assertCount(1, $this->exporter->json);
$json = $this->exporter->json[0];
$pattern = '/^{"event":"event","entityType":"entity-type","entityId":"entity-id","eventTime":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}"}$/';
$this->assertTrue(preg_match($pattern, $json) === 1, 'json');
$this->assertRegExp($pattern, $json, 'json');
}

public function testOptionalFields()
Expand All @@ -131,9 +132,9 @@ public function testOptionalFields()
$time
);

$this->assertEquals(1, count($this->exporter->data));
$this->assertCount(1, $this->exporter->data);
$data = $this->exporter->data[0];
$this->assertEquals(7, count($data));
$this->assertCount(7, $data);
$this->assertEquals('event', $data['event']);
$this->assertEquals('entity-type', $data['entityType']);
$this->assertEquals('entity-id', $data['entityId']);
Expand All @@ -142,9 +143,9 @@ public function testOptionalFields()
$this->assertEquals('target-entity-id', $data['targetEntityId']);
$this->assertEquals(['property'=>true], $data['properties']);

$this->assertEquals(1, count($this->exporter->json));
$this->assertCount(1, $this->exporter->json);
$json = $this->exporter->json[0];
$pattern = '/^{"event":"event","entityType":"entity-type","entityId":"entity-id","eventTime":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}","targetEntityType":"target-entity-type","targetEntityId":"target-entity-id","properties":{"property":true}}$/';
$this->assertTrue(preg_match($pattern, $json) === 1, 'json');
$this->assertRegExp($pattern, $json, 'json');
}
}
5 changes: 3 additions & 2 deletions tests/Unit/FileExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
namespace predictionio\tests\Unit;

use predictionio\FileExporter;
use PHPUnit\Framework\TestCase;

class FileExporterTest extends \PHPUnit_Framework_TestCase
class FileExporterTest extends TestCase
{
public function setUp()
protected function setUp()
{
register_shutdown_function(function () {
if (file_exists('temp.file')) {
Expand Down