Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Exceptions System #60

Merged
merged 65 commits into from
Sep 15, 2021
Merged

New Exceptions System #60

merged 65 commits into from
Sep 15, 2021

Conversation

julien-boudry
Copy link
Owner

No description provided.

@toddy15
Copy link
Contributor

toddy15 commented Sep 10, 2021

Hi @julien-boudry,

I've now pushed a few new exceptions to this branch. It would be great if you could take a look and tell me if the code is fine with you. It would be a pity if I'm running in the wrong direction. 😄

Regards,
Tobias

@julien-boudry
Copy link
Owner Author

julien-boudry commented Sep 10, 2021

Hi @julien-boudry,

I've now pushed a few new exceptions to this branch. It would be great if you could take a look and tell me if the code is fine with you. It would be a pity if I'm running in the wrong direction. 😄

Regards,
Tobias

Hi @toddy15

  • I just push new commits (b0d2b4c + c75819d): Just add a new class CondorcetPublicApiException as a base abstract class. Actually, it's just providing the trait CondorcetVersion && Stringable interface. But can be useful for the future.

  • Maybe we can classify Exception in a subpath (folder & namespace), but it can be done easily later (thx IDE).

  • Most of the new test class are not useful, and looks likes duplicate code because they are all the same and without any surprise or risks. Because they don't test the new Exception in action (functional test do it). Maybe we can just add a new expectExeptionMessage() directly into the functional test instead.

Thx for all.

@julien-boudry
Copy link
Owner Author

Another problem with the tests: We cannot know if the coverage is correct on the real tests, because we test each class even if not used in the real world (or lack of real tests).

Instead, I propose to eliminate these unnecessary tests. And to write them only if there were special cases to test that are not satisfied in the functional tests, or if there are features specific to certain Exception classes, which is not the case here, they do not have their own code.

@julien-boudry
Copy link
Owner Author

julien-boudry commented Sep 10, 2021

Have a look on f357935
I think this may be the right model. And easy to apply to others. Don't define the message systematically in the code when it can be defined in the class (but be able to do it for the ones that fit), while being able to pass simple parameters easily.

This should be applied to the others and the following ones.
Do not hesitate to comment.

Both classes are in the same namespace, so the use statement is superfluous.
@toddy15
Copy link
Contributor

toddy15 commented Sep 11, 2021

Hi @julien-boudry,

thanks for your input. Yes, you're right, the new tests I've added provide very little confidence. Basically, they just assure that the exception classes are instantiable and of the correct type. However, the functional tests give more confidence. I'm fine with deleting all those new tests and add some more 'asserts' to the functional tests. So your commit f357935 is alright with me.

About adding the abstract class CondorcetPublicApiException: I like that a lot, and in fact, I did think about this already before you've mentioned it. I thought that it might make sense to convert the previous "CondorcetException" to the new exception system and then, when there are no "exception codes" left in CondorcetException, use that as the base class. This way, code using the library would not have to be rewritten for v3.2.0, because they still can catch the generic "CondorcetException". On the other hand, it might be better with the new class you've introduced, because it's a clear break for downstream projects, so hopefully there won't be silent bugs because the downstream author still relies on the old exception system.

Hm, not quite sure about the best approach here.

@julien-boudry
Copy link
Owner Author

Hi @toddy15,

Yes, it's easy with Docker, I do it myself with shared volume, directly from official PHP images.

I will do the merge from dev-3.2 branch (wich have merged few hours ago with php 8.1) into newExceptions branch.

toddy15 and others added 4 commits September 14, 2021 23:08
# Conflicts:
#	Tests/lib/Algo/Methods/STV/SingleTransferableVoteTest.php
#	Tests/lib/CandidateTest.php
#	Tests/lib/ElectionTest.php
#	Tests/lib/VoteTest.php
#	lib/Algo/Methods/CondorcetBasic.php
#	lib/Throwable/CondorcetException.php
@julien-boudry
Copy link
Owner Author

Merged!

@toddy15
Copy link
Contributor

toddy15 commented Sep 14, 2021

Great, thanks! The branch is now almost ready to be merged into dev-3.2, there are only a couple of minor thing to fix. In some places of the code, the CondorcetException is still used.

@julien-boudry
Copy link
Owner Author

julien-boudry commented Sep 14, 2021

Great, thanks! The branch is now almost ready to be merged into dev-3.2, there are only a couple of minor thing to fix. In some places of the code, the CondorcetException is still used.

Yes, the last ones are harder to fix, because maybe some of them need some new tests (actually, only coverage is lower). For example with Vote.php.

@julien-boudry
Copy link
Owner Author

Thanks for all! I will see the problem with the Vote class tomorrow.

@toddy15
Copy link
Contributor

toddy15 commented Sep 14, 2021

Soo ... I think that I've spotted every left over occurence of CondorcetException now, apart from some places in Documentation -- but as I understand it, you generate those files, right?

So from my perspective, this branch could be merged into dev-3.2.

@toddy15 toddy15 marked this pull request as ready for review September 14, 2021 22:35
@julien-boudry
Copy link
Owner Author

Very nice job @toddy15!

If you wants to continue to contribute, you can have a look at issues (or submit any ideas):
https://github.com/julien-boudry/Condorcet/issues
https://github.com/julien-boudry/Condorcet/projects/1

@toddy15
Copy link
Contributor

toddy15 commented Sep 19, 2021

Hi @julien-boudry,

thanks! Indeed, I'd be interested in looking into the infection/infection implementation (#53).

Apart from that, have you heard of https://pestphp.com/? It seems to be a really nice testing framework, capable of running the standard PHPUnit tests. However, the tests are much nicer to read and write -- at least in my opinion.

@julien-boudry
Copy link
Owner Author

Let's continue in the discussion section. And a new pull request for Infection.

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

Successfully merging this pull request may close these issues.

None yet

2 participants