Giter VIP home page Giter VIP logo

Comments (6)

shochdoerfer avatar shochdoerfer commented on August 26, 2024 1

Thanks for opening an issue first to discuss things.

First of all, yes what is called mocks are actually stubs. The reasoning behind this is that I did not want to confuse people (well, mainly me) with the stubs from PHPStan as they behave fundamentally differently and I could not come up with a better name.

It does not make sense to rely on PHPStan's stubs because doing that would mean we have to add half of Magento's codebase to this repo. The "problem" with PHPStan's stubs (at least the last time I looked at it) was, that you have to add any class you import/use as a stub as well. In our approach, the autoloader simply loads a different implementation if it exists. From that perspective, things work as they should for me.

Does it make sense to move the files out of the src folder? Maybe. Is it worth it? Probably not.

In an ideal world, the subs/mocks would be located in a separate Composer package that depends on a matching Magento version. Because currently, technically false positives could occur when Magento changes one of the classes that we stored as stub/mock. However, I decided against that approach for now, because it simply is way too much management overhead to create a separate package per Magento version and maintain that. Also, so far no one reported false positives from the stub/mock files we provide. As long as that does not happen, I'll leave things as they are.

from phpstan-magento.

szepeviktor avatar szepeviktor commented on August 26, 2024

I see you call stubs "mock".

from phpstan-magento.

szepeviktor avatar szepeviktor commented on August 26, 2024

I think

parameters:
	stubFiles:

could be used instead of a custom solution.

/**
* The MockAutoloader is responsible to load custom mocked classes or interfaces instead of the original Magento classes
* or interfaces. This is needed as not all interfaces expose all public methods that can be called on those objects.
*/
class MockAutoloader implements Autoloader
{
public function autoload(string $class): void
{
$filename = realpath(__DIR__ . '/../../../../' . str_replace('\\', '/', $class) . '.php');
if (!is_bool($filename) && file_exists($filename) && is_readable($filename)) {
include($filename);
}
}
public function register(): void
{
\spl_autoload_register([$this, 'autoload'], true, true);
}
public function unregister(): void
{
\spl_autoload_unregister([$this, 'autoload']);
}
}

from phpstan-magento.

szepeviktor avatar szepeviktor commented on August 26, 2024

you have to add any class you import/use as a stub as well

YES!!

from phpstan-magento.

szepeviktor avatar szepeviktor commented on August 26, 2024

to create a separate package per Magento version and maintain that

@shochdoerfer Would you like me to create and maintain a package - e.g php-stubs/magento-stub - and include your mocks?

from phpstan-magento.

shochdoerfer avatar shochdoerfer commented on August 26, 2024

@shochdoerfer Would you like me to create and maintain a package - e.g php-stubs/magento-stub - and include your mocks?

I don't see a benefit in that.

from phpstan-magento.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.