Skip to content

Commit

Permalink
test: Write test for namespace generation
Browse files Browse the repository at this point in the history
Signed-off-by: Ádám Bálint <[email protected]>
  • Loading branch information
adambalint-srg committed Jun 3, 2022
1 parent 5c9931c commit c17d801
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/Tool/FactoryCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

use Laminas\ServiceManager\Tool\FactoryCreator;
use LaminasTest\ServiceManager\TestAsset\ComplexDependencyObject;
use LaminasTest\ServiceManager\TestAsset\Foo;
use LaminasTest\ServiceManager\TestAsset\InvokableObject;
use LaminasTest\ServiceManager\TestAsset\SimpleDependencyObject;
use PHPUnit\Framework\TestCase;

use function class_alias;
use function file_get_contents;
use function preg_match;

class FactoryCreatorTest extends TestCase
{
Expand Down Expand Up @@ -47,4 +50,20 @@ public function testCreateFactoryCreatesForComplexDependencies(): void

$this->assertEquals($factory, $this->factoryCreator->createFactory($className));
}

public function testNamespaceGeneration(): void
{
$testClassNames = [
'Foo\\Bar\\Service' => 'Foo\\Bar',
'Foo\\Service\\Bar\\Service' => 'Foo\\Service\\Bar',
];
foreach ($testClassNames as $testFqcn => $expectedNamespace) {
class_alias(Foo::class, $testFqcn);
$generatedFactory = $this->factoryCreator->createFactory($testFqcn);
preg_match('/^namespace\s([^;]+)/m', $generatedFactory, $namespaceMatch);

$this->assertNotEmpty($namespaceMatch);
$this->assertEquals($expectedNamespace, $namespaceMatch[1]);
}
}
}

0 comments on commit c17d801

Please sign in to comment.