rectorphp / rector-book-feedback

[BOOK] Repository for feedback from readers of Rector book, to improve it continuously
https://leanpub.com/rector-the-power-of-automated-refactoring
15 stars 2 forks source link

Possible missing directory in filepath #20

Closed oceanicpanda closed 3 years ago

oceanicpanda commented 3 years ago

Code Improvement

I think code on page 79 could be improved. Using the exact file/folder structure provided in the text I receive the following if I do not also include the name of my Rector in the file path:

utils/Rector/Test/Fixture" directory does not exist.

image

I propose this change

-before
public function provideData(): Iterator
    {
        return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
    }
    public function provideConfigFilePath(): string
    {
        return __DIR__ . '/config.php';
    }
+after
public function provideData(): Iterator
    {
        return $this->yieldFilesFromDirectory(__DIR__ . '/<MyExampleRector>/Fixture');
    }
    public function provideConfigFilePath(): string
    {
        return __DIR__ . '/<MyExampleRector>/config.php';
    }

Thanks!

TomasVotruba commented 3 years ago

The structure we use in Rector is the "before". The files and directories should be updated to match it.

Typical structure looks like this:

/tests
    /Rector
        /SomeSpecificRector
            /config # all the configs go here
            /Fixture # all the tested files go here
            SomeSpecificRectorTest.php # the test itself
TomasVotruba commented 3 years ago

Ah, I see it now. This is how you need to update your structure:

/tests
    /Rector
        /SomeSpecificRector
            /config # all the configs go here
            /Fixture # all the tested files go here
-       SomeSpecificRectorTest.php # the test itself
+           SomeSpecificRectorTest.php # the test itself

We'll show this example in the book, so it's more clear. Thank you for feedback :+1: