magento2 – Unit test ‘non-existent’ factory methods

Potentially same question has been asked but differently.

You are testing something in isolation and assume no access to generated folder.

Helper method

class HelperClass extends AbstractHelper

    public function __construct(
        Context $context,
        CurrencyFactory $currencyFactory
    ) {
        $this->currencyFactory = $currencyFactory;


     * Format price with symbol
     * @param float $price
     * @param string $symbol
     * @return string
    public function formatPrice(float $price, string $symbol): string
        return $this->currencyFactory
                ('symbol' => $symbol),

Unit test

    public function setUp(): void
        $this->currencyMock = $this->createMock(Currency::class);

        $this->currencyFactoryMock = $this->getMockBuilder(CurrencyFactory::class)


        $this->helper = new HelperClass(

    public function testFormatPrice()
        $this->assertEquals('£2.23', $this->helper->formatPrice((float) 2.2294, '£'));

Error: HelperClass::formatPrice() must be of the type string, null returned

Is there just no way of testing generated classes without them existing?