I want to override a controller inside a component
File path : components/com_test/controllers/test.php
how can I override test.php ?
Overwrite a controller is something that I don´t dare to do, even it is possible.
I recommend you try to use another approach
Option 1 – Modifying the controller to add an event trigger and ask the developer to include it in the next version.
As explained here:
Ok, you´ll need to hack a core file of the component and of course this change will be lost when upgrading, but if you need it, is likely that is it good for other too, so the developer can be willing to insert that event trigger.
Option 2 – Create a small component to handle your stuff.
As you can easily overwrite the templates of com_test, you can change the call to your own controller /com_mytest.php
Then in there, you can do whatever you need and return control to com_test when ready.
It is a complex solution. This plugin should help: Plugin to override 3rd Component controllers, models and views and Modules.
Also you can read about overrides in Joomla docs: How to override the component mvc from the Joomla! core