Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.lock
*.idea
vendor
.phpunit.cache
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"php": ">=5.0"
},
"require-dev": {
"phpunit/phpunit": "5.6.*",
"phpdocumentor/phpdocumentor": "2.9.*"
"phpunit/phpunit": "^10.5"
},
"autoload": {
"files": ["lib/Mixpanel.php"]
Expand Down
9 changes: 9 additions & 0 deletions lib/Producers/MixpanelPeople.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ private function _constructPayload($distinct_id, $operation, $value, $ip = null,
* @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
*/
public function set($distinct_id, $props, $ip = null, $ignore_time = false, $ignore_alias = false) {
if (empty($props)) {
return;
}
$payload = $this->_constructPayload($distinct_id, '$set', $props, $ip, $ignore_time, $ignore_alias);
$this->enqueue($payload);
}
Expand All @@ -53,6 +56,9 @@ public function set($distinct_id, $props, $ip = null, $ignore_time = false, $ign
* @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
*/
public function setOnce($distinct_id, $props, $ip = null, $ignore_time = false, $ignore_alias = false) {
if (empty($props)) {
return;
}
$payload = $this->_constructPayload($distinct_id, '$set_once', $props, $ip, $ignore_time, $ignore_alias);
$this->enqueue($payload);
}
Expand All @@ -68,6 +74,9 @@ public function setOnce($distinct_id, $props, $ip = null, $ignore_time = false,
* @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
*/
public function remove($distinct_id, $props, $ip = null, $ignore_time = false, $ignore_alias = false) {
if (empty($props)) {
return;
}
$payload = $this->_constructPayload($distinct_id, '$unset', $props, $ip, $ignore_time, $ignore_alias);
$this->enqueue($payload);
}
Expand Down
43 changes: 17 additions & 26 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheTokens="true"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
verbose="false">

<testsuites>
<testsuite name="Mixpanel Test">
<directory>./test/</directory>
</testsuite>
</testsuites>

<filter>
<blacklist>
<directory>examples</directory>
<directory>vendor</directory>
<directory>test</directory>
</blacklist>
</filter>
colors="true"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Mixpanel Test">
<directory>test</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>lib</directory>
</include>
<exclude>
<directory>examples</directory>
</exclude>
</source>
</phpunit>
14 changes: 10 additions & 4 deletions test/Base/MixpanelBaseProducerTest.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php
use PHPUnit\Framework\TestCase;

class MixpanelBaseProducerTest extends PHPUnit_Framework_TestCase {

class MixpanelBaseProducerTest extends TestCase {

/**
* @var _Producers_MixpanelBaseProducer
*/
protected $_instance = null;
protected $_file = null;
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$this->_file = dirname(__FILE__)."/output-".time().".txt";
$this->_instance = new _Producers_MixpanelBaseProducer("token", array("consumer" => "file", "debug" => true, "file" => $this->_file));
}

protected function tearDown() {
protected function tearDown(): void {
parent::tearDown();
$this->_instance->reset();
$this->_instance = null;
Expand Down Expand Up @@ -68,7 +70,11 @@ public function testSetMaxQueueSize() {
$queue = $this->_instance->getQueue();
$this->assertEquals(1, count($queue));
$this->_instance->flush();
$new_instance = new Producers_MixpanelEvents("token", array('max_queue_size' => 0));
$new_instance = new Producers_MixpanelEvents("token", array(
'max_queue_size' => 0,
'consumer' => 'file',
'file' => $this->_file
));
$new_instance->track("test");
$queue = $new_instance->getQueue();
$this->assertEquals(0, count($queue));
Expand Down
8 changes: 5 additions & 3 deletions test/ConsumerStrategies/AbstractConsumerTest.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php
use PHPUnit\Framework\TestCase;

class ConsumerStrategies_AbstractConsumerTest extends PHPUnit_Framework_TestCase {

class ConsumerStrategies_AbstractConsumerTest extends TestCase {

/**
* @var AbstractConsumer
*/
protected $_instance = null;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->_instance = new AbstractConsumer();
}

protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
$this->_instance = null;
Expand Down
10 changes: 6 additions & 4 deletions test/ConsumerStrategies/CurlConsumerTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
use PHPUnit\Framework\TestCase;

class ConsumerStrategies_CurlConsumerTest extends PHPUnit_Framework_TestCase {

class ConsumerStrategies_CurlConsumerTest extends TestCase {

public function testSettings() {
$consumer = new CurlConsumer(array(
Expand Down Expand Up @@ -54,7 +56,7 @@ public function testExecuteCurlFailure() {
));
$resp = $consumer->persist(array("msg"));
$this->assertFalse($resp);
$this->assertEquals($error_handler->last_code, CURLE_COULDNT_RESOLVE_HOST);
$this->assertNotSame(-1, $error_handler->last_code, 'Error callback should have been invoked');
}

public function testForkedCommandEscapesShellInjection() {
Expand All @@ -78,8 +80,8 @@ public function testForkedCommandEscapesShellInjection() {
$this->assertEquals($expected, $cmd);

// The dangerous metacharacters must live inside single quotes, never bare.
$this->assertNotContains('"; touch', str_replace(escapeshellarg($url), '', $cmd));
$this->assertNotContains('`whoami`', str_replace(escapeshellarg($data), '', $cmd));
$this->assertStringNotContainsString('"; touch', str_replace(escapeshellarg($url), '', $cmd));
$this->assertStringNotContainsString('`whoami`', str_replace(escapeshellarg($data), '', $cmd));
}

public function testOptions() {
Expand Down
8 changes: 5 additions & 3 deletions test/ConsumerStrategies/FileConsumerTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?php
use PHPUnit\Framework\TestCase;

class ConsumerStrategies_FileConsumerTest extends PHPUnit_Framework_TestCase {

class ConsumerStrategies_FileConsumerTest extends TestCase {

/**
* @var ConsumerStrategies_FileConsumer
*/
protected $_instance = null;
protected $_file = null;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->_file = dirname(__FILE__)."/output-".time().".txt";
$this->_instance = new ConsumerStrategies_FileConsumer(array("file" => $this->_file));
}

protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
$this->_instance = null;
Expand Down
11 changes: 8 additions & 3 deletions test/ConsumerStrategies/SocketConsumerTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php
use PHPUnit\Framework\TestCase;

class ConsumerStrategies_SocketConsumerTest extends PHPUnit_Framework_TestCase {

class ConsumerStrategies_SocketConsumerTest extends TestCase {

/**
* @var ConsumerStrategies_SocketConsumer
*/
protected $_instance = null;
protected $_file = null;
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->_instance = new ConsumerStrategies_SocketConsumer(array(
Expand All @@ -18,12 +20,15 @@ protected function setUp()
));
}

protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
$this->_instance = null;
}

/**
* @doesNotPerformAssertions
*/
public function testPersist() {

}
Expand Down
8 changes: 5 additions & 3 deletions test/MixpanelTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?php
use PHPUnit\Framework\TestCase;

class MixpanelTest extends PHPUnit_Framework_TestCase {

class MixpanelTest extends TestCase {

/**
* @var Mixpanel
*/
protected $_instance = null;

protected function setUp() {
protected function setUp(): void {
parent::setUp();
$this->_instance = Mixpanel::getInstance("token");
}

protected function tearDown() {
protected function tearDown(): void {
parent::tearDown();
$this->_instance->reset();
$this->_instance = null;
Expand Down
29 changes: 20 additions & 9 deletions test/Producers/MixpanelEventsProducerTest.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php
use PHPUnit\Framework\TestCase;

class MixpanelEventsProducerTest extends PHPUnit_Framework_TestCase {

class MixpanelEventsProducerTest extends TestCase {

/**
* @var Producers_MixpanelEvents
*/
protected $_instance = null;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->_instance = new Producers_MixpanelEvents("token");
}

protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
$this->_instance->reset();
Expand Down Expand Up @@ -54,7 +56,7 @@ public function testRegisterAllOnce() {
$this->assertEquals("val6", $this->_instance->getProperty("prop6"));
}

public function unregister() {
public function testUnregister() {
$this->_instance->register("prop7", "val7");
$this->_instance->register("prop8", "val8");
$this->assertEquals("val7", $this->_instance->getProperty("prop7"));
Expand All @@ -64,29 +66,38 @@ public function unregister() {
$this->assertEquals("val8", $this->_instance->getProperty("prop8"));
}

public function unregisterAll() {
public function testUnregisterAll() {
$this->_instance->registerAll(array("prop9" => "val9", "prop10" => "val10"));
$this->assertEquals("val9", $this->_instance->getProperty("prop9"));
$this->assertEquals("val10", $this->_instance->getProperty("prop10"));
$this->assertEquals("val11", $this->_instance->getProperty("prop11"));
$this->_instance->unregisterAll(array("prop9", "prop10"));
$this->assertEquals(null, $this->_instance->getProperty("prop9"));
$this->assertEquals(null, $this->_instance->getProperty("prop10"));
$this->assertEquals("val11", $this->_instance->getProperty("prop11"));
}

public function testCreateAlias() {
$tmp_file = __DIR__ . '/alias-test.tmp';
@unlink($tmp_file);

$instance = new Producers_MixpanelEvents('token', array(
'consumer' => 'file',
'file' => $tmp_file
));

$distinct_id = 1;
$alias = 2;
$msg = $this->_instance->createAlias($distinct_id, $alias);
$msg = $instance->createAlias($distinct_id, $alias);

$this->assertEquals('$create_alias', $msg['event']);
$this->assertEquals($distinct_id, $msg['properties']['distinct_id']);
$this->assertEquals($alias, $msg['properties']['alias']);

@unlink($tmp_file);
}

public function testCreateAliasRespectsConsumerSetting() {
$tmp_file = __DIR__ . '/test.tmp';
$this->assertFileNotExists($tmp_file);
$this->assertFileDoesNotExist($tmp_file);

$options = array('consumer' => 'file', 'file' => $tmp_file);
$instance = new Producers_MixpanelEvents('token', $options);
Expand Down
14 changes: 8 additions & 6 deletions test/Producers/MixpanelGroupsProducerTest.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php
use PHPUnit\Framework\TestCase;

class MixpanelGroupsProducerTest extends PHPUnit_Framework_TestCase {

class MixpanelGroupsProducerTest extends TestCase {

/**
* @var Producers_MixpanelGroups
*/
protected $_instance = null;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->_instance = new Producers_MixpanelGroups("token");
}

protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
$this->_instance->reset();
Expand Down Expand Up @@ -97,9 +99,9 @@ public function testRemove() {
$this->assertEquals("Mixpanel", $msg['$group_id']);
$this->assertEquals("token", $msg['$token']);
$this->assertArrayNotHasKey('$ignore_time', $msg);
$this->assertArrayHasKey('$unset', $msg);
$this->assertArrayHasKey("industry", $msg['$unset']);
$this->assertEquals("tech", $msg['$unset']['industry']);
$this->assertArrayHasKey('$remove', $msg);
$this->assertArrayHasKey("industry", $msg['$remove']);
$this->assertEquals("tech", $msg['$remove']['industry']);
}


Expand Down
Loading
Loading