/** * Gets the event that will be used for the next event logged by call to logEvent() or queueEvent() * * You can also pass in an event or array of event properties. If you pass in an event, it will be set as the * event to be used for the next call to queueEvent() or logEvent() * * @param null|array|\Zumba\Amplitude\Event Can pass in an event to set as the next event to run, or array to set * properties on that event * @return \Zumba\Amplitude\Event */ public function event($event = null) { if (!empty($event) && $event instanceof \Zumba\Amplitude\Event) { $this->event = $event; } elseif (empty($this->event)) { // Set the values that persist between tracking events $this->event = new Event(); } if (!empty($event) && is_array($event)) { // Set properties on the event $this->event->set($event); } return $this->event; }
public function testUnsetProperty() { $event = new Event(); $event->set('custom prop', 'value'); $event->userId = 'user'; $event->quantity = 50; $event->userProperties = ['prop' => 'value']; $this->assertEquals(['event_properties' => ['custom prop' => 'value'], 'user_id' => 'user', 'quantity' => 50, 'user_properties' => ['prop' => 'value']], $event->toArray(), 'Initialization Check'); // Should just not care if not set... $event->unsetProperty('invalid'); unset($event->invalid); // Should be able to successfully unset custom property $this->assertNotEmpty($event->get('custom prop'), 'Initialization check'); $event->unsetProperty('custom prop'); $this->assertEmpty($event->get('custom prop'), 'Should be able to unset custom properties'); // also should work with magic methods $this->assertNotEmpty($event->userId, 'Initialization check'); unset($event->userId); $this->assertEmpty($event->userId, 'Should unset built-in properties with magic unset'); }