Skip to content

refactors Mvc directory and Middleware#257

Merged
armanist merged 7 commits into
quantum-php:masterfrom
ematrito:malnutreeto-mvcmanager-refactor
Apr 30, 2025
Merged

refactors Mvc directory and Middleware#257
armanist merged 7 commits into
quantum-php:masterfrom
ematrito:malnutreeto-mvcmanager-refactor

Conversation

@ematrito

Copy link
Copy Markdown
Collaborator

Hi, i'm glad to contribute to your project! i tried to refactor as issue #253 requires. I refactored the MvcManager class (renamed to RouteDispatcher) by extracting middleware and view cache logic into separate classes — MiddlewareExecutor and ViewCacheHandler. Additionally, i merged the QtController functionality into RouteController, eliminating unnecessary inheritance and simplifying the controller structure.

Comment thread src/Mvc/RouteDispatcher.php Outdated
Comment thread src/Router/RouteController.php Outdated
Comment thread src/Middleware/MiddlewareExecutor.php
Comment thread src/Mvc/RouteDispatcher.php Outdated
Comment thread src/Mvc/QtController.php Outdated
Comment thread src/Mvc/RouteDispatcher.php

@andrey-smaelov andrey-smaelov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor issues

Comment thread src/Handlers/VIewCacheHandler.php
Comment thread src/Mvc/RouteDispatcher.php
Comment thread src/Handlers/VIewCacheHandler.php

@armanist armanist left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Malnutreeto thanks for your contribution, it's a great support for us.

We have github actions on pull requests which runs unit tests. Your pull request isn't passed all the unit tests and the error I'm adding bellow.

You can run the unit tests on your local machine as well to make sure all tests are passed before creating pull request.

The command to run unit tests:

vendor/bin/phpunit --stderr 

The error currently captured on this pull request by github actions

> vendor/bin/phpunit --stderr --testdox --coverage-clover coverage.xml
PHP Fatal error:  Uncaught Error: Class 'Quantum\Mvc\QtController' not found in /home/runner/work/quantum-php-core/quantum-php-core/tests/Unit/Di/DiTest.php:10
Stack trace:
#0 /home/runner/work/quantum-php-core/quantum-php-core/vendor/phpunit/phpunit/src/Util/FileLoader.php(66): include_once()
#1 /home/runner/work/quantum-php-core/quantum-php-core/vendor/phpunit/phpunit/src/Util/FileLoader.php(4[9](https://github.com/softberg/quantum-php-core/actions/runs/14579401359/job/40920939807?pr=257#step:11:10)): PHPUnit\Util\FileLoader::load()
#2 /home/runner/work/quantum-php-core/quantum-php-core/vendor/phpunit/phpunit/src/Framework/TestSuite.php(398): PHPUnit\Util\FileLoader::checkAndLoad()
#3 /home/runner/work/quantum-php-core/quantum-php-core/vendor/phpunit/phpunit/src/Framework/TestSuite.php(537): PHPUnit\Framework\TestSuite->addTestFile()
#4 /home/runner/work/quantum-php-core/quantum-php-core/vendor/phpunit/phpunit/src/TextUI/TestSuiteMapper.php(67): PHPUnit\Framework\TestSuite->addTestFiles()
#5 /home/runner/work/quantum-php-core/quantum-php-core/vendor/phpunit/phpunit/src/TextUI/Command.php(393): PHPUnit\TextUI\TestSuiteMapper->map( in /home/runner/work/quantum-php-core/quantum-php-core/vendor/phpunit/phpunit/src/TextUI/Command.php on line [10](https://github.com/softberg/quantum-php-core/actions/runs/14579401359/job/40920939807?pr=257#step:11:11)1
Script vendor/bin/phpunit --stderr --testdox --coverage-clover coverage.xml handling the test event returned with error code 255
Error: Process completed with exit code 255.

@armanist armanist left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please correct the above issues so we can merge your pull request

@ematrito

Copy link
Copy Markdown
Collaborator Author

I tried to resolve test errors but I'm afraid that anything went wrong on my machine, please let me know

@armanist armanist requested review from Arno2005 and armanist April 23, 2025 13:36

@armanist armanist left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The unit tests are still failing, I've invited you to repo so you can see the github actions log

Comment thread tests/Unit/Di/DiTest.php Outdated
Comment thread tests/Unit/Libraries/Module/ModuleManagerTest.php Outdated
Comment thread tests/Unit/Mvc/QtControllerTest.php Outdated
use Quantum\App\App;
use Exception;
use Mockery;
use Quantum\Mvc\RouteDispatcher;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Move RouteDispatcher to its right place so all the namespaces are correctly ordered.
Update: see the other change requests, as RouteDispatcher probably shouldn't be used here.

@ematrito

ematrito commented Apr 24, 2025

Copy link
Copy Markdown
Collaborator Author

Hi Arno, I don't know why those 3 tests fail even with composer dump-autoload command executed. The issue called for streamlining the QtController by implementing a route dispatcher, but I'm currently struggling to find a viable solution. Could you offer some assistance?

@Arno2005

Arno2005 commented Apr 24, 2025

Copy link
Copy Markdown
Collaborator

Hi Arno, I don't know why those 3 tests fail even with composer dump-autoload command executed. The issue called for streamlining the QtController by implementing a route dispatcher, but I'm currently struggling to find a viable solution. Could you offer some assistance?

Hello, sure, I'm happy to help you. I checked your code and identified the problems. You have 3 errors in the unit test: 2 ViewCacheHandler not found errors, and one QtController not found error.

ViewCacheHandler error:
It seems that the file containing this class has the name VIewCacheHandler.php (with uppercase I). Try to correct that and see if the error persists.

QtController error:
This is a bit tricky, as the ModuleManager itself doesn't use it, but the errors show that it has occurred there. The ModuleManager class serves as a tool that lets you generate modules from templates. You can see them in the Libraries/Modules/Templates folder. In the folder (which basically contains PHP files but with .tpl extension) change the use of QtController and replace it with the proper class.

I hope I explained it clearly. If you have any questions or need some help, feel free to ask.

@ematrito

Copy link
Copy Markdown
Collaborator Author

Thank you! I'll fix asap!

@ematrito

Copy link
Copy Markdown
Collaborator Author

Hello, I just pushed fix commit but I haven't found VIewCacheHandler.php file (with uppercase I). I also replace QtController where not properly required

@armanist

Copy link
Copy Markdown
Collaborator

Hello, I just pushed fix commit but I haven't found VIewCacheHandler.php file (with uppercase I). I also replace QtController where not properly required

Looks like most of the issues are resolved now, only one error is left: Error: Class 'Quantum\Handlers\ViewCacheHandler' not found this is because the class name is ViewCacheHandler whereas the class file name is VIewCacheHandler.php, see the screenshot attached.

Screenshot 2025-04-29 112006

@ematrito

Copy link
Copy Markdown
Collaborator Author

Got it! Thank you!

Comment thread src/Handlers/ViewCacheHandler.php
Comment thread src/Handlers/ViewCacheHandler.php
@armanist armanist added the enhancement New feature or request label Apr 30, 2025
@armanist armanist added this to the 2.9.7 milestone Apr 30, 2025
@armanist armanist merged commit 5f40977 into quantum-php:master Apr 30, 2025
@armanist

Copy link
Copy Markdown
Collaborator

Closes #256

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants