这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@dimaodnokoz
Copy link
Collaborator

@dimaodnokoz dimaodnokoz commented May 15, 2024

  1. Refactoring of dialog key generation and use of it in DialogManager.php to avoid misunderstanding in private functions naming and to have generation formula in 1 place for all needs. Description of $user_id in Dialog.php also changed to be more informative. All tests passed.

  2. Added test to DialogManager.php to check afterLastStep function call in Dialog.php proceed function. Also updated HelloExampleDialog.php to use it in tests without TG API calls in steps if bot instance NULL (like in tests). Test fails, which prove the wrong place of afterLastStep function call. Ready to do PR of fix in Dialog.php file, plz suggest next steps here.

…p to avoid misunderstanding in private functions naming and to have gen firmula in 1 place for all needs.
… function. Test fails, which prove the wrong place of afterLastStep function call. Ready to do PR of fix (Dialog.php file).
@dimaodnokoz dimaodnokoz changed the title Dialog key generation functions refactoring 1) Dialog key generation functions refactoring 2) Test to check afterLastStep function May 15, 2024
Copy link
Collaborator

@alies-dev alies-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dimaodnokoz

Thanks for your work! Generally it looks great, I love the direction. But there are a few things we can improve to make code cleaner. Please take a look to my comments. Thanks again!

PS: BTW, I found a bug when we call getMessage()->id in DialogManager. Due to bad design in the TG SDK v3, getMessage() may return an empty Collection in some cases. We need to fix it also (of course not in this PR)

* @return non-empty-string
*/
private function generateDialogKeySharedBetweenUsers(Update $update): string
private function generateDialogKey($chatId, $userId = null): string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing type info (both params are int)

public function sayHello(Update $update): void
{
//Used for test purposes
if(!isset($this->bot)){return;}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this HelloExampleDialog should be sort of showcase for developers, and we should avoid adding such code needed for testing purposes.

if you want to test Dialog-related functionality, please consider either:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, @alies-dev. Thank you for your feedback. So should i cancel this PR and submit another one with fixes?
According your last proposal "use the same approach" - i tried, but failed. Maybe it was because i planned test with sendMessage and did not understand how to emulate its call in fake bot. But as for my last test i do not need this call, so i will try again.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimaodnokoz
pls update code for the existing PR, I think it will be simpler to you.

Also, if you have issues with Faking HTTP requests and responses, I think it will be simpler for your to create a new Dialog implementation like PassiveTestDialog extends Dialog that only listens and doesn't send anything and use it for your tests.

You can also implement afterLastStep in that Dialog and e.g. throw an exception. If exception is not thrown - the test should fail. This way you will avoid adding code like:

public bool $afterLastStepCalled = false;

    protected function afterLastStep(Update $update): void
    {
        $this->afterLastStepCalled = true;
    }

(it's just an idea, you can find another implementation, incl. public properties that are ok for a TestDialog)

@dimaodnokoz
Copy link
Collaborator Author

@alies-dev done! plz check. Except a bug about getMessage.

Copy link

@lptn lptn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

I'll remove ItWorks exception if you don't mind and will use \LogicException instead to reduce amount of code. Plus I'll move PassiveTestDialog to simplify onboarding for new comers. I think this class should live in /tests dir

Thank you for your great help!

@lptn lptn merged commit 19a9d07 into koot-labs:master May 16, 2024
@dimaodnokoz
Copy link
Collaborator Author

We proved that afterLastStep is not in correct place. So now we need to fix this) Should i wait for your new commit, where you do several things mentioned, above and then commit this fix? Or, maybe, you will fix it yourself? As i understand the call of afterLastStep in Dialog.php/proseed function should be moved to the very end of function right after "++$this->next;" and that's all.

@lptn
Copy link

lptn commented May 16, 2024

@dimaodnokoz

Should i wait for your new commit, where you do several things mentioned, above and then commit this fix?

I did it, it's already on the master branch. Now we can fix the issue. Are you going to create a PR with the fix?

As i understand the call of afterLastStep in Dialog.php/proseed function should be moved to the very end of function right after "++$this->next;" and that's all.

Right, somewhere I this place. Ideally we should have more tests to catch all possible cases (e.g. with afterProceedJumpToIndex)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants