public function testUpdatesCustomAttributes() { $userId = 11; $unchanged = new AttributeValue(1, 'value'); $toChange = new AttributeValue(2, 'value'); $toAdd = new AttributeValue(3, 'value'); $user = new User(); $user->WithId($userId); $user->WithAttribute($unchanged); $user->WithAttribute(new AttributeValue(100, 'should be removed')); $user->WithAttribute(new AttributeValue(2, 'new value')); $attributes = array($unchanged, $toChange, $toAdd); $user->ChangeCustomAttributes($attributes); $repo = new UserRepository(); $repo->Update($user); $addNewCommand = new AddAttributeValueCommand($toAdd->AttributeId, $toAdd->Value, $userId, CustomAttributeCategory::USER); $removeOldCommand = new RemoveAttributeValueCommand(100, $userId); $removeUpdated = new RemoveAttributeValueCommand($toChange->AttributeId, $userId); $addUpdated = new AddAttributeValueCommand($toChange->AttributeId, $toChange->Value, $userId, CustomAttributeCategory::USER); $this->assertEquals($removeOldCommand, $this->db->_Commands[1]); $this->assertEquals($removeUpdated, $this->db->_Commands[2], "need to remove before adding to make sure changed values are not immediately deleted"); $this->assertEquals($addUpdated, $this->db->_Commands[3]); $this->assertEquals($addNewCommand, $this->db->_Commands[4]); }