Skip to content

Commit

Permalink
Merge pull request #264 from lacrossefootwear/bugfix/bitExpert/phpsta…
Browse files Browse the repository at this point in the history
…n-magento/263

Fix factory generation for "FactoryThing" classes
  • Loading branch information
shochdoerfer committed Aug 6, 2022
2 parents 8e55592 + c975ea9 commit 67dd3a8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function getFileContents(string $class): string
$namespace = explode('\\', ltrim($class, '\\'));
/** @var string $factoryClassname */
$factoryClassname = array_pop($namespace);
$originalClassname = str_replace('Factory', '', $factoryClassname);
$originalClassname = preg_replace('#Factory$#', '', $factoryClassname);
$namespace = implode('\\', $namespace);

$template = "<?php\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,29 @@ public function autoloaderGeneratesCacheFileWhenNotFoundInCache(): void

self::assertTrue(class_exists(HelperFactory::class, false));
}

/**
* @test
*/
public function autoloaderGeneratesFactoryForCorrectClassname(): void
{
$this->storage->expects(self::atMost(2))
->method('load')
->willReturnOnConsecutiveCalls(null, __DIR__ . '/FactoryThingFactory.php');
$this->storage->expects(self::once())
->method('save')
->with(
'bitExpert\PHPStan\Magento\Autoload\FactoryThingFactory',
static::isType('string'),
static::stringContains(<<<DOC
/**
* Factory class for @see \bitExpert\PHPStan\Magento\Autoload\FactoryThing
*/
DOC
)
)
;

$this->autoloader->autoload(FactoryThingFactory::class);
}
}
20 changes: 20 additions & 0 deletions tests/bitExpert/PHPStan/Magento/Autoload/FactoryThingFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the phpstan-magento package.
*
* (c) bitExpert AG
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace bitExpert\PHPStan\Magento\Autoload;

/**
* Dummy class that can be loaded via the Autoloader in the test cases.
*/
class FactoryThingFactory
{
}

0 comments on commit 67dd3a8

Please sign in to comment.