Skip to content
Closed
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
14 changes: 4 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ php-docker-template: &php-docker-template
steps:
- checkout
- run:
name: validate composer.json
command: composer validate
- run:
name: install current dependencies
command: composer install --no-progress
name: update and validate composer.json
command: composer update && composer validate
- run:
name: run tests with current dependency versions
command: vendor/bin/phpunit --log-junit ~/phpunit/junit.xml --coverage-text tests
Expand Down Expand Up @@ -70,11 +67,8 @@ jobs:
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
- checkout
- run:
name: validate composer.json
command: composer validate
- run:
name: install current dependencies
command: composer install --no-progress
name: update and validate composer.json
command: composer update && composer validate
- run:
name: run php-cs-fixer
command: vendor/bin/php-cs-fixer fix --diff --dry-run --verbose
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"guzzlehttp/guzzle": "^6.2.1",
"kevinrob/guzzle-cache-middleware": "^1.4.1",
"phpdocumentor/phpdocumentor": "^2.0",
"phpunit/phpunit": ">=4.8.26 <5.4",
"phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5",
"predis/predis": "^1.0",
"zendframework/zend-serializer": "^2.7"
},
Expand Down
3 changes: 2 additions & 1 deletion tests/EvaluationReasonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
namespace LaunchDarkly\Tests;

use LaunchDarkly\EvaluationReason;
use PHPUnit\Framework\TestCase;

class EvaluationReasonTest extends \PHPUnit_Framework_TestCase
class EvaluationReasonTest extends TestCase
{
public function testOffReasonSerialization()
{
Expand Down
43 changes: 22 additions & 21 deletions tests/EventSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

use LaunchDarkly\EventSerializer;
use LaunchDarkly\LDUserBuilder;
use PHPUnit\Framework\TestCase;

class EventSerializerTest extends \PHPUnit_Framework_TestCase
class EventSerializerTest extends TestCase
{
private function getUser()
{
Expand All @@ -13,7 +14,7 @@ private function getUser()
->custom(array('bizzle' => 'def', 'dizzle' => 'ghi'))
->build();
}

private function getUserSpecifyingOwnPrivateAttr()
{
return (new LDUserBuilder('abc'))
Expand All @@ -22,7 +23,7 @@ private function getUserSpecifyingOwnPrivateAttr()
->privateCustomAttribute('dizzle', 'ghi')
->build();
}

private function getFullUserResult()
{
return array(
Expand All @@ -31,15 +32,15 @@ private function getFullUserResult()
'custom' => array('bizzle' => 'def', 'dizzle' => 'ghi')
);
}

private function getUserResultWithAllAttrsHidden()
{
return array(
'key' => 'abc',
'privateAttrs' => array('bizzle', 'dizzle', 'firstName')
);
}

private function getUserResultWithSomeAttrsHidden()
{
return array(
Expand All @@ -48,7 +49,7 @@ private function getUserResultWithSomeAttrsHidden()
'privateAttrs' => array('bizzle', 'firstName')
);
}

private function getUserResultWithOwnSpecifiedAttrHidden()
{
return array(
Expand All @@ -58,7 +59,7 @@ private function getUserResultWithOwnSpecifiedAttrHidden()
'privateAttrs' => array('dizzle')
);
}

private function makeEvent($user)
{
return array(
Expand All @@ -68,14 +69,14 @@ private function makeEvent($user)
'user' => $user
);
}

private function getJsonForUserBySerializingEvent($user)
{
$es = new EventSerializer(array());
$event = $this->makeEvent($user);
return json_decode($es->serializeEvents(array($event)), true)[0]['user'];
}

public function testAllUserAttrsSerialized()
{
$es = new EventSerializer(array());
Expand All @@ -93,7 +94,7 @@ public function testAllUserAttrsPrivate()
$expected = $this->makeEvent($this->getUserResultWithAllAttrsHidden());
$this->assertEquals(array($expected), json_decode($json, true));
}

public function testSomeUserAttrsPrivate()
{
$es = new EventSerializer(array('private_attribute_names' => array('firstName', 'bizzle')));
Expand All @@ -102,7 +103,7 @@ public function testSomeUserAttrsPrivate()
$expected = $this->makeEvent($this->getUserResultWithSomeAttrsHidden());
$this->assertEquals(array($expected), json_decode($json, true));
}

public function testPerUserPrivateAttr()
{
$es = new EventSerializer(array());
Expand All @@ -120,15 +121,15 @@ public function testPerUserPrivateAttrPlusGlobalPrivateAttrs()
$expected = $this->makeEvent($this->getUserResultWithAllAttrsHidden());
$this->assertEquals(array($expected), json_decode($json, true));
}

public function testUserKey()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("[email protected]", $json['key']);
}

public function testEmptyCustom()
{
$builder = new LDUserBuilder("[email protected]");
Expand All @@ -152,63 +153,63 @@ public function testUserSecondary()
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("secondary", $json['secondary']);
}

public function testUserIP()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->ip("127.0.0.1")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("127.0.0.1", $json['ip']);
}

public function testUserCountry()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->country("US")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("US", $json['country']);
}

public function testUserEmail()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->email("[email protected]")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("[email protected]", $json['email']);
}

public function testUserName()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->name("Foo Bar")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("Foo Bar", $json['name']);
}

public function testUserAvatar()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->avatar("http://www.gravatar.com/avatar/1")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("http://www.gravatar.com/avatar/1", $json['avatar']);
}

public function testUserFirstName()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->firstName("Foo")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("Foo", $json['firstName']);
}

public function testUserLastName()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->lastName("Bar")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("Bar", $json['lastName']);
}

public function testUserAnonymous()
{
$builder = new LDUserBuilder("[email protected]");
Expand Down
11 changes: 6 additions & 5 deletions tests/FeatureFlagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use LaunchDarkly\LDUser;
use LaunchDarkly\LDUserBuilder;
use LaunchDarkly\Segment;
use PHPUnit\Framework\TestCase;

class FeatureFlagTest extends \PHPUnit_Framework_TestCase
class FeatureFlagTest extends TestCase
{
private static $json1 = "{
\"key\": \"integration.feature.0\",
Expand Down Expand Up @@ -146,7 +147,7 @@ public function testDecode()
$this->assertInstanceOf(FeatureFlag::class, FeatureFlag::decode(\GuzzleHttp\json_decode(FeatureFlagTest::$json1, true)));
$this->assertInstanceOf(FeatureFlag::class, FeatureFlag::decode(\GuzzleHttp\json_decode(FeatureFlagTest::$json2, true)));
}

public function dataDecodeMulti()
{
return [
Expand Down Expand Up @@ -182,15 +183,15 @@ public function dataDecodeMulti()
],
];
}

/**
* @dataProvider dataDecodeMulti
* @param array $feature
*/
public function testDecodeMulti(array $feature)
{
$featureFlag = FeatureFlag::decode($feature);

self::assertInstanceOf(FeatureFlag::class, $featureFlag);
}

Expand Down Expand Up @@ -701,7 +702,7 @@ public function testSegmentMatchClauseRetrievesSegmentFromStore()
public function testSegmentMatchClauseFallsThroughWithNoErrorsIfSegmentNotFound()
{
$requester = new MockFeatureRequesterForSegment();

$feature = $this->makeBooleanFeatureWithSegmentMatch('segkey');

$ub = new LDUserBuilder('foo');
Expand Down
5 changes: 3 additions & 2 deletions tests/FeatureFlagsStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use LaunchDarkly\EvaluationReason;
use LaunchDarkly\FeatureFlag;
use LaunchDarkly\FeatureFlagsState;
use PHPUnit\Framework\TestCase;

class FeatureFlagsStateTest extends \PHPUnit_Framework_TestCase
class FeatureFlagsStateTest extends TestCase
{
private static $flag1Json = array(
'key' => 'key1',
Expand Down Expand Up @@ -51,7 +52,7 @@ public function testCanGetFlagValue()
public function testUnknownFlagReturnsNullValue()
{
$state = new FeatureFlagsState(true);

$this->assertNull($state->getFlagValue('key1'));
}

Expand Down
27 changes: 15 additions & 12 deletions tests/LDClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
use LaunchDarkly\LDUser;
use LaunchDarkly\LDUserBuilder;
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\TestCase;

class LDClientTest extends \PHPUnit_Framework_TestCase
class LDClientTest extends TestCase
{
public function testDefaultCtor()
{
Expand Down Expand Up @@ -305,7 +306,7 @@ public function testAllFlagsStateReturnsState()
$builder = new LDUserBuilder(3);
$user = $builder->build();
$state = $client->allFlagsState($user);

$this->assertTrue($state->isValid());
$this->assertEquals(array('feature' => 'off'), $state->toValuesMap());
$expectedState = array(
Expand Down Expand Up @@ -351,7 +352,7 @@ public function testAllFlagsStateReturnsStateWithReasons()
$builder = new LDUserBuilder(3);
$user = $builder->build();
$state = $client->allFlagsState($user, array('withReasons' => true));

$this->assertTrue($state->isValid());
$this->assertEquals(array('feature' => 'off'), $state->toValuesMap());
$expectedState = array(
Expand Down Expand Up @@ -396,14 +397,16 @@ public function testAllFlagsStateCanFilterForClientSideFlags()
$builder = new LDUserBuilder(3);
$user = $builder->build();
$state = $client->allFlagsState($user, array('clientSideOnly' => true));

$this->assertTrue($state->isValid());
$this->assertEquals(array('client-side-1' => 'value1', 'client-side-2' => 'value2'), $state->toValuesMap());
}

/**
* @expectedException InvalidArgumentException
*/
public function testOnlyValidFeatureRequester()
{
$this->setExpectedException(InvalidArgumentException::class);
new LDClient("BOGUS_SDK_KEY", ['feature_requester_class' => \stdClass::class]);
}

Expand All @@ -413,29 +416,29 @@ public function testSecureModeHash()
$user = new LDUser("Message");
$this->assertEquals("aa747c502a898200f9e4fa21bac68136f886a0e27aec70ba06daf2e2a5cb5597", $client->secureModeHash($user));
}

public function testLoggerInterfaceWarn()
{
// Use LoggerInterface impl, instead of concreate Logger from Monolog, to demonstrate the problem with `warn`.
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();

$logger->expects(self::atLeastOnce())->method('warning');

$client = new LDClient('secret', [
'logger' => $logger,
]);

$user = new LDUser('');

$client->variation('MyFeature', $user);
}

private function getPrivateField(&$object, $fieldName)
{
$reflection = new \ReflectionClass(get_class($object));
$field = $reflection->getProperty($fieldName);
$field->setAccessible(true);

return $field->getValue($object);
}
}
Loading