|
21 | 21 | use Optimizely\Bucketer;
|
22 | 22 | use Optimizely\ErrorHandler\NoOpErrorHandler;
|
23 | 23 | use Optimizely\Event\LogEvent;
|
| 24 | +use Optimizely\Exceptions\InvalidAttributeException; |
24 | 25 | use Optimizely\Logger\NoOpLogger;
|
25 | 26 | use Optimizely\ProjectConfig;
|
26 | 27 | use TypeError;
|
@@ -250,6 +251,32 @@ public function testActivateInvalidOptimizelyObject()
|
250 | 251 | $this->expectOutputRegex('/Datafile has invalid format. Failing "activate"./');
|
251 | 252 | }
|
252 | 253 |
|
| 254 | + public function testActivateInvalidAttributes() |
| 255 | + { |
| 256 | + $this->loggerMock->expects($this->exactly(2)) |
| 257 | + ->method('log'); |
| 258 | + $this->loggerMock->expects($this->at(0)) |
| 259 | + ->method('log') |
| 260 | + ->with(Logger::ERROR, 'Provided attributes are in an invalid format.'); |
| 261 | + $this->loggerMock->expects($this->at(1)) |
| 262 | + ->method('log') |
| 263 | + ->with(Logger::INFO, 'Not activating user "test_user".'); |
| 264 | + |
| 265 | + $errorHandlerMock = $this->getMockBuilder(NoOpErrorHandler::class) |
| 266 | + ->setMethods(array('handleError')) |
| 267 | + ->getMock(); |
| 268 | + $errorHandlerMock->expects($this->once()) |
| 269 | + ->method('handleError') |
| 270 | + ->with(new InvalidAttributeException('Provided attributes are in an invalid format.')); |
| 271 | + |
| 272 | + $optlyObject = new Optimizely( |
| 273 | + $this->datafile, new ValidEventDispatcher(), $this->loggerMock, $errorHandlerMock |
| 274 | + ); |
| 275 | + |
| 276 | + // Call activate |
| 277 | + $this->assertNull($optlyObject->activate('test_experiment', 'test_user', 42)); |
| 278 | + } |
| 279 | + |
253 | 280 | public function testActivateNoAudienceNoAttributes()
|
254 | 281 | {
|
255 | 282 | $this->eventBuilderMock->expects($this->once())
|
@@ -400,6 +427,27 @@ public function testGetVariationInvalidOptimizelyObject()
|
400 | 427 | $this->expectOutputRegex('/Datafile has invalid format. Failing "getVariation"./');
|
401 | 428 | }
|
402 | 429 |
|
| 430 | + public function testGetVariationInvalidAttributes() |
| 431 | + { |
| 432 | + $this->loggerMock->expects($this->once()) |
| 433 | + ->method('log') |
| 434 | + ->with(Logger::ERROR, 'Provided attributes are in an invalid format.'); |
| 435 | + |
| 436 | + $errorHandlerMock = $this->getMockBuilder(NoOpErrorHandler::class) |
| 437 | + ->setMethods(array('handleError')) |
| 438 | + ->getMock(); |
| 439 | + $errorHandlerMock->expects($this->once()) |
| 440 | + ->method('handleError') |
| 441 | + ->with(new InvalidAttributeException('Provided attributes are in an invalid format.')); |
| 442 | + |
| 443 | + $optlyObject = new Optimizely( |
| 444 | + $this->datafile, new ValidEventDispatcher(), $this->loggerMock, $errorHandlerMock |
| 445 | + ); |
| 446 | + |
| 447 | + // Call activate |
| 448 | + $this->assertNull($optlyObject->getVariation('test_experiment', 'test_user', 42)); |
| 449 | + } |
| 450 | + |
403 | 451 | public function testGetVariationAudienceMatch()
|
404 | 452 | {
|
405 | 453 | $this->loggerMock->expects($this->exactly(2))
|
@@ -447,6 +495,27 @@ public function testTrackInvalidOptimizelyObject()
|
447 | 495 | $this->expectOutputRegex('/Datafile has invalid format. Failing "track"./');
|
448 | 496 | }
|
449 | 497 |
|
| 498 | + public function testTrackInvalidAttributes() |
| 499 | + { |
| 500 | + $this->loggerMock->expects($this->once()) |
| 501 | + ->method('log') |
| 502 | + ->with(Logger::ERROR, 'Provided attributes are in an invalid format.'); |
| 503 | + |
| 504 | + $errorHandlerMock = $this->getMockBuilder(NoOpErrorHandler::class) |
| 505 | + ->setMethods(array('handleError')) |
| 506 | + ->getMock(); |
| 507 | + $errorHandlerMock->expects($this->once()) |
| 508 | + ->method('handleError') |
| 509 | + ->with(new InvalidAttributeException('Provided attributes are in an invalid format.')); |
| 510 | + |
| 511 | + $optlyObject = new Optimizely( |
| 512 | + $this->datafile, new ValidEventDispatcher(), $this->loggerMock, $errorHandlerMock |
| 513 | + ); |
| 514 | + |
| 515 | + // Call activate |
| 516 | + $this->assertNull($optlyObject->track('purchase', 'test_user', 42)); |
| 517 | + } |
| 518 | + |
450 | 519 | public function testTrackNoAttributesNoEventValue()
|
451 | 520 | {
|
452 | 521 | $this->eventBuilderMock->expects($this->once())
|
|
0 commit comments