-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Test class Generator #8333
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
Test class Generator #8333
Conversation
eef7990
to
b2d0ce7
Compare
Man, writing code for CI has become tedious. I'm having to fix a dozen PHPStan issues that have been around for ages in the GeneratorTrait, in code that I didn't touch for this PR. Really annoying. Can't imagine how annoyed I'd be if I was just trying to submit a small fix for the framework and wasn't on the core team. And why is |
Yes, this is an issue for me too. But I'm not sure how we can handle it... Can lowering the If I remember correctly @paulbalandan advised me in the past to just generate the baseline vendor/bin/phpstan analyse --generate-baseline phpstan-baseline.php
I think we've established that in 99% of cases, it is too loose. And it brings a lot of trouble. I believe you can still add an exception for it. |
I didn't realize there could be so many errors, but these are technical debt in the trait. I will fix them. |
@lonnieezell I don't know how you made commits in this PR. I was not able to extract your commit in this PR. I ran |
The reason why Also, developers who read the code later must consider what
See https://3v4l.org/BsbRk |
It seems we don't need $ ./spark make:test App\\Controllers\\HelloTest
...
File created: ROOTPATH/tests/App/Controllers/HelloTest.php <?php
namespace Tests\App\Controllers;
use CodeIgniter\Test\CIUnitTestCase;
class HelloTest extends CIUnitTestCase
{
protected function setUp(): void
{
parent::setUp();
}
public function testExample(): void
{
//
}
} |
Sorry about the empty comment last night. It was mostly rhetorical and born out of my frustration. I understand what this team would not want it used. I don't find it nearly as dangerous but that's fine. And yes, after 17 years with PHP I am aware of the values it checks for. @kenjis Thanks for fixing those. Wasn't looking for the help just expressing frustration. As someone who spent years of my spare time writing this imperfect code I don't find the process enjoyable anymore because something like this happens every time. We have to find a better balance between code quality checks and developer experience. I'll look at the rest of the PR and comments tonight. Just getting my day started here. |
@lonnieezell No problem. It is good thing you can express your frustration. The most easiest workaround is to update the baseline. This works every time.
But I really don't want I thought all objects were not empty, but today I know an empty object.
|
Right, but it works by hiding errors, partially defeating why we're using it and if we use it frequently don't we continually hide a bunch of errors?
I have no problem with this, really, just find it a bit over-restrictive. |
Yes, it is correct. So we should not use it frequently. But we are hiding more than 1000 errors now. Also, our PHPStan level is still 6. Of course, I do not recommend hiding errors. |
e077110
to
8ffb170
Compare
All green. |
@lonnieezell I know it's a little late, but who is this command for, the developers who use appstarter? If so, I think the current best practice is to match the namespace of the class file with the test file. However, this command cannot generate such a test file. Also, this command cannot be used for CI4 development, because it cannot generate files under |
According to the docs, test classes are expected in
|
For app starter users. While I know that we do namespace based on class namespace I don't know that's a best practice. I haven't encountered that anywhere else and find it a little confusing since that's the only place that does not map the namespace to a directory within our codebase. |
Then I think we should change the docs. We have no practical reason to enforce this and it just makes a slightly worse developer experience. Any time the user wants to run a single test class they have to type in extra characters for no beneficial reason. My opinion is that the tests folder should be left to organize however they see fit. |
I know this is a bit different from your opinion, but what about #8374? |
Description
Adds a new
make:test
command to generate a skeleton test file. Required refactoring the GeneratorTrait to allow setting a namespace outside of the App directory to work. Also needed to add aTests
namespace by default to allow it be generated, but that's something we should have anyway for anyone writing their own tests. Surprised this hasn't been a pain point for others in the past, honestly.Checklist: