Skip to content

Commit 24569b8

Browse files
committed
🖊️ Fixed Code Coverage
1 parent ad15a2c commit 24569b8

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

tests/ProjectConfigTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323
use Optimizely\Entity\Audience;
2424
use Optimizely\Entity\Event;
2525
use Optimizely\Entity\Experiment;
26+
use Optimizely\Entity\FeatureFlag;
27+
use Optimizely\Entity\Rollout;
2628
use Optimizely\Entity\Group;
2729
use Optimizely\Entity\Variation;
2830
use Optimizely\ErrorHandler\NoOpErrorHandler;
2931
use Optimizely\Exceptions\InvalidAttributeException;
3032
use Optimizely\Exceptions\InvalidAudienceException;
3133
use Optimizely\Exceptions\InvalidEventException;
3234
use Optimizely\Exceptions\InvalidExperimentException;
35+
use Optimizely\Exceptions\InvalidFeatureFlagException;
36+
use Optimizely\Exceptions\InvalidRolloutException;
3337
use Optimizely\Exceptions\InvalidGroupException;
3438
use Optimizely\Exceptions\InvalidVariationException;
3539
use Optimizely\Logger\DefaultLogger;
@@ -315,6 +319,30 @@ public function testGetExperimentInvalidId()
315319
$this->assertEquals(new Experiment(), $this->config->getExperimentFromId('42'));
316320
}
317321

322+
public function testGetFeatureFlagInvalidKey()
323+
{
324+
$this->loggerMock->expects($this->once())
325+
->method('log')
326+
->with(Logger::ERROR, 'FeatureFlag Key "42" is not in datafile.');
327+
$this->errorHandlerMock->expects($this->once())
328+
->method('handleError')
329+
->with(new InvalidFeatureFlagException('Provided feature flag is not in datafile.'));
330+
331+
$this->assertEquals(new FeatureFlag(), $this->config->getFeatureFlagFromKey('42'));
332+
}
333+
334+
public function testGetRolloutInvalidId()
335+
{
336+
$this->loggerMock->expects($this->once())
337+
->method('log')
338+
->with(Logger::ERROR, 'Rollout ID "42" is not in datafile.');
339+
$this->errorHandlerMock->expects($this->once())
340+
->method('handleError')
341+
->with(new InvalidRolloutException('Provided rollout is not in datafile.'));
342+
343+
$this->assertEquals(new Rollout(), $this->config->getRolloutFromId('42'));
344+
}
345+
318346
public function testGetEventValidKey()
319347
{
320348
$event = $this->config->getEvent('purchase');

tests/UtilsTests/ValidatorTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@
2121
use Optimizely\Logger\NoOpLogger;
2222
use Optimizely\ProjectConfig;
2323
use Optimizely\Utils\Validator;
24-
24+
use Monolog\Logger;
2525

2626
class ValidatorTest extends \PHPUnit_Framework_TestCase
2727
{
28+
protected $loggerMock;
29+
30+
protected function setUp()
31+
{
32+
// Mock Logger
33+
$this->loggerMock = $this->getMockBuilder(NoOpLogger::class)
34+
->setMethods(array('log'))
35+
->getMock();
36+
}
37+
2838
public function testValidateJsonSchemaValidFile()
2939
{
3040
$this->assertTrue(Validator::validateJsonSchema(DATAFILE));
@@ -42,6 +52,15 @@ public function testValidateJsonSchemaNoJsonContent()
4252
$this->assertFalse(Validator::validateJsonSchema($invalidDatafile));
4353
}
4454

55+
public function testValidateJsonSchemaInvalidJsonWithLogger(){
56+
$invalidDatafile = '{"key1": "val1"}';
57+
$this->loggerMock->expects($this->at(0))
58+
->method('log')
59+
->with(Logger::DEBUG,"JSON does not validate. Violations:\n");
60+
$this->assertFalse(Validator::validateJsonSchema($invalidDatafile, $this->loggerMock));
61+
62+
}
63+
4564
public function testAreAttributesValidValidAttributes()
4665
{
4766
// Empty attributes

0 commit comments

Comments
 (0)