Skip to content

Commit 46b6dc2

Browse files
committed
updated unit tests to not rely on old factory signatures
1 parent 3d812c0 commit 46b6dc2

7 files changed

+41
-54
lines changed

tests/ConfigProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ConfigProviderTest extends TestCase
1616
{
1717
public function testInvokeHasDependencyKeyAndNotServiceManager(): void
1818
{
19-
$config = (new ConfigProvider())->__invoke();
19+
$config = (new ConfigProvider())();
2020

2121
self::assertArrayHasKey('dependencies', $config, 'Expected config to have "dependencies" array key');
2222
self::assertArrayNotHasKey('service_manager', $config, 'Config should not have "service_manager" array key');

tests/Service/ConfigurationFactoryTest.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\ORM\Mapping\NamingStrategy;
1313
use Doctrine\ORM\Mapping\QuoteStrategy;
1414
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
15+
use DoctrineORMModule\Options\Configuration;
1516
use DoctrineORMModule\Service\ConfigurationFactory;
1617
use DoctrineORMModuleTest\Assets\RepositoryClass;
1718
use Laminas\ServiceManager\Exception\InvalidArgumentException;
@@ -47,7 +48,7 @@ public function testWillInstantiateConfigWithoutNamingStrategySetting(): void
4748
],
4849
];
4950
$this->serviceManager->setService('config', $config);
50-
$ormConfig = $this->factory->createService($this->serviceManager);
51+
$ormConfig = ($this->factory)($this->serviceManager, Configuration::class);
5152
$this->assertInstanceOf(NamingStrategy::class, $ormConfig->getNamingStrategy());
5253
}
5354

@@ -64,7 +65,7 @@ public function testWillInstantiateConfigWithNamingStrategyObject(): void
6465
];
6566
$this->serviceManager->setService('config', $config);
6667
$factory = new ConfigurationFactory('test_default');
67-
$ormConfig = $factory->createService($this->serviceManager);
68+
$ormConfig = $factory($this->serviceManager, Configuration::class);
6869
$this->assertSame($namingStrategy, $ormConfig->getNamingStrategy());
6970
}
7071

@@ -80,7 +81,7 @@ public function testWillInstantiateConfigWithNamingStrategyReference(): void
8081
];
8182
$this->serviceManager->setService('config', $config);
8283
$this->serviceManager->setService('test_naming_strategy', $namingStrategy);
83-
$ormConfig = $this->factory->createService($this->serviceManager);
84+
$ormConfig = ($this->factory)($this->serviceManager, Configuration::class);
8485
$this->assertSame($namingStrategy, $ormConfig->getNamingStrategy());
8586
}
8687

@@ -95,7 +96,7 @@ public function testWillNotInstantiateConfigWithInvalidNamingStrategyReference()
9596
];
9697
$this->serviceManager->setService('config', $config);
9798
$this->expectException(InvalidArgumentException::class);
98-
$this->factory->createService($this->serviceManager);
99+
($this->factory)($this->serviceManager, Configuration::class);
99100
}
100101

101102
public function testWillInstantiateConfigWithQuoteStrategyObject(): void
@@ -111,7 +112,7 @@ public function testWillInstantiateConfigWithQuoteStrategyObject(): void
111112
];
112113
$this->serviceManager->setService('config', $config);
113114
$factory = new ConfigurationFactory('test_default');
114-
$ormConfig = $factory->createService($this->serviceManager);
115+
$ormConfig = $factory($this->serviceManager, Configuration::class);
115116
$this->assertSame($quoteStrategy, $ormConfig->getQuoteStrategy());
116117
}
117118

@@ -127,7 +128,7 @@ public function testWillInstantiateConfigWithQuoteStrategyReference(): void
127128
];
128129
$this->serviceManager->setService('config', $config);
129130
$this->serviceManager->setService('test_quote_strategy', $quoteStrategy);
130-
$ormConfig = $this->factory->createService($this->serviceManager);
131+
$ormConfig = ($this->factory)($this->serviceManager, Configuration::class);
131132
$this->assertSame($quoteStrategy, $ormConfig->getQuoteStrategy());
132133
}
133134

@@ -142,7 +143,7 @@ public function testWillNotInstantiateConfigWithInvalidQuoteStrategyReference():
142143
];
143144
$this->serviceManager->setService('config', $config);
144145
$this->expectException(InvalidArgumentException::class);
145-
$this->factory->createService($this->serviceManager);
146+
($this->factory)($this->serviceManager, Configuration::class);
146147
}
147148

148149
public function testWillInstantiateConfigWithHydrationCacheSetting(): void
@@ -156,7 +157,7 @@ public function testWillInstantiateConfigWithHydrationCacheSetting(): void
156157
];
157158
$this->serviceManager->setService('config', $config);
158159
$factory = new ConfigurationFactory('test_default');
159-
$ormConfig = $factory->createService($this->serviceManager);
160+
$ormConfig = $factory($this->serviceManager, Configuration::class);
160161
$this->assertInstanceOf(ArrayCache::class, $ormConfig->getHydrationCacheImpl());
161162
}
162163

@@ -176,7 +177,7 @@ public function testCanSetDefaultRepositoryClass(): void
176177
$this->serviceManager->setService('config', $config);
177178

178179
$factory = new ConfigurationFactory('test_default');
179-
$ormConfig = $factory->createService($this->serviceManager);
180+
$ormConfig = $factory($this->serviceManager, Configuration::class);
180181
$this->assertInstanceOf(ArrayCache::class, $ormConfig->getHydrationCacheImpl());
181182
}
182183

@@ -191,7 +192,7 @@ public function testAcceptsMetadataFactory(): void
191192
];
192193
$this->serviceManager->setService('config', $config);
193194
$factory = new ConfigurationFactory('test_default');
194-
$ormConfig = $factory->createService($this->serviceManager);
195+
$ormConfig = $factory($this->serviceManager, Configuration::class);
195196
$this->assertEquals('Factory', $ormConfig->getClassMetadataFactoryName());
196197
}
197198

@@ -206,7 +207,7 @@ public function testDefaultMetadatFactory(): void
206207
];
207208
$this->serviceManager->setService('config', $config);
208209
$factory = new ConfigurationFactory('test_default');
209-
$ormConfig = $factory->createService($this->serviceManager);
210+
$ormConfig = $factory($this->serviceManager, Configuration::class);
210211
$this->assertEquals(
211212
ClassMetadataFactory::class,
212213
$ormConfig->getClassMetadataFactoryName()
@@ -225,7 +226,7 @@ public function testWillInstantiateConfigWithoutEntityListenerResolverSetting():
225226

226227
$this->serviceManager->setService('config', $config);
227228

228-
$ormConfig = $this->factory->createService($this->serviceManager);
229+
$ormConfig = ($this->factory)($this->serviceManager, Configuration::class);
229230

230231
$this->assertInstanceOf(
231232
EntityListenerResolver::class,
@@ -247,7 +248,7 @@ public function testWillInstantiateConfigWithEntityListenerResolverObject(): voi
247248

248249
$this->serviceManager->setService('config', $config);
249250

250-
$ormConfig = $this->factory->createService($this->serviceManager);
251+
$ormConfig = ($this->factory)($this->serviceManager, Configuration::class);
251252

252253
$this->assertSame($entityListenerResolver, $ormConfig->getEntityListenerResolver());
253254
}
@@ -267,7 +268,7 @@ public function testWillInstantiateConfigWithEntityListenerResolverReference():
267268
$this->serviceManager->setService('config', $config);
268269
$this->serviceManager->setService('test_entity_listener_resolver', $entityListenerResolver);
269270

270-
$ormConfig = $this->factory->createService($this->serviceManager);
271+
$ormConfig = ($this->factory)($this->serviceManager, Configuration::class);
271272

272273
$this->assertSame($entityListenerResolver, $ormConfig->getEntityListenerResolver());
273274
}
@@ -284,7 +285,7 @@ public function testDoNotCreateSecondLevelCacheByDefault(): void
284285

285286
$this->serviceManager->setService('config', $config);
286287

287-
$ormConfig = $this->factory->createService($this->serviceManager);
288+
$ormConfig = ($this->factory)($this->serviceManager, Configuration::class);
288289

289290
$this->assertNull($ormConfig->getSecondLevelCacheConfiguration());
290291
}
@@ -322,7 +323,7 @@ public function testCanInstantiateWithSecondLevelCacheConfig(): void
322323

323324
$this->serviceManager->setService('config', $config);
324325

325-
$ormConfig = $this->factory->createService($this->serviceManager);
326+
$ormConfig = ($this->factory)($this->serviceManager, Configuration::class);
326327
$secondLevelCache = $ormConfig->getSecondLevelCacheConfiguration();
327328

328329
$this->assertInstanceOf(CacheConfiguration::class, $secondLevelCache);

tests/Service/DBALConnectionFactoryTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\Common\Cache\ArrayCache;
88
use Doctrine\Common\EventManager;
9+
use Doctrine\DBAL\Connection as DBALConnection;
910
use Doctrine\DBAL\Driver\PDO\SQLite\Driver;
1011
use Doctrine\DBAL\Platforms\AbstractPlatform;
1112
use Doctrine\DBAL\Types\Type;
@@ -53,7 +54,7 @@ public function testNoConnectWithoutCustomMappingsAndCommentedTypes(): void
5354
$this->serviceManager->setService('config', $config);
5455
$this->serviceManager->setService('Configuration', $config);
5556

56-
$dbal = $this->factory->createService($this->serviceManager);
57+
$dbal = ($this->factory)($this->serviceManager, DBALConnection::class);
5758
$this->assertFalse($dbal->isConnected());
5859
}
5960

@@ -78,7 +79,7 @@ public function testDoctrineMappingTypeReturnCorrectParent(): void
7879
$this->serviceManager->setService('config', $config);
7980
$this->serviceManager->setService('Configuration', $config);
8081

81-
$dbal = $this->factory->createService($this->serviceManager);
82+
$dbal = ($this->factory)($this->serviceManager, DBALConnection::class);
8283
$platform = $dbal->getDatabasePlatform();
8384
$this->assertSame('string', $platform->getDoctrineTypeMapping('money'));
8485
}
@@ -113,9 +114,9 @@ public function testDoctrineAddCustomCommentedType(): void
113114
$configurationFactory = new ConfigurationFactory('orm_default');
114115
$this->serviceManager->setService(
115116
'doctrine.configuration.orm_default',
116-
$configurationFactory->createService($this->serviceManager)
117+
$configurationFactory($this->serviceManager, Configuration::class)
117118
);
118-
$dbal = $this->factory->createService($this->serviceManager);
119+
$dbal = ($this->factory)($this->serviceManager, DBALConnection::class);
119120
$platform = $dbal->getDatabasePlatform();
120121
$type = Type::getType($platform->getDoctrineTypeMapping('money'));
121122

@@ -148,7 +149,7 @@ public function testGettingPlatformFromContainer(): void
148149
$this->serviceManager->setService('Configuration', $config);
149150
$this->serviceManager->setService('platform_service', $platformMock);
150151

151-
$dbal = $this->factory->createService($this->serviceManager);
152+
$dbal = ($this->factory)($this->serviceManager, DBALConnection::class);
152153
$platform = $dbal->getDatabasePlatform();
153154
$this->assertSame($platformMock, $platform);
154155
}
@@ -173,7 +174,7 @@ public function testWithoutUseSavepoints(): void
173174
$this->serviceManager->setService('config', $config);
174175
$this->serviceManager->setService('Configuration', $config);
175176

176-
$dbal = $this->factory->createService($this->serviceManager);
177+
$dbal = ($this->factory)($this->serviceManager, DBALConnection::class);
177178
$this->assertFalse($dbal->getNestTransactionsWithSavepoints());
178179
}
179180

@@ -198,7 +199,7 @@ public function testWithUseSavepoints(): void
198199
$this->serviceManager->setService('config', $config);
199200
$this->serviceManager->setService('Configuration', $config);
200201

201-
$dbal = $this->factory->createService($this->serviceManager);
202+
$dbal = ($this->factory)($this->serviceManager, DBALConnection::class);
202203
$this->assertTrue($dbal->getNestTransactionsWithSavepoints());
203204
}
204205
}

tests/Service/MigrationsCommandFactoryTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use InvalidArgumentException;
3131
use Laminas\ServiceManager\ServiceManager;
3232
use PHPUnit\Framework\TestCase;
33+
use stdClass;
3334

3435
use function class_exists;
3536

@@ -59,7 +60,7 @@ public function testExecuteFactory(): void
5960

6061
$this->assertInstanceOf(
6162
ExecuteCommand::class,
62-
$factory->createService($this->serviceLocator)
63+
$factory($this->serviceLocator, ExecuteCommand::class)
6364
);
6465
}
6566

@@ -75,7 +76,7 @@ public function testDiffFactory(): void
7576

7677
$this->assertInstanceOf(
7778
DiffCommand::class,
78-
$factory->createService($this->serviceLocator)
79+
$factory($this->serviceLocator, DiffCommand::class)
7980
);
8081
}
8182

@@ -84,7 +85,7 @@ public function testThrowException(): void
8485
$factory = new MigrationsCommandFactory('unknowncommand');
8586

8687
$this->expectException(InvalidArgumentException::class);
87-
$factory->createService($this->serviceLocator);
88+
$factory($this->serviceLocator, stdClass::class);
8889
}
8990

9091
public function testDefineDependencyFactoryServicesFromConfig(): void
@@ -115,7 +116,7 @@ public function testDefineDependencyFactoryServicesFromConfig(): void
115116
['myService', 'test'],
116117
]);
117118

118-
$factory->createService($serviceLocator);
119+
$factory($serviceLocator, DiffCommand::class);
119120
}
120121

121122
public function testNoDefineDependencyFactoryServicesFromConfig(): void
@@ -143,6 +144,6 @@ public function testNoDefineDependencyFactoryServicesFromConfig(): void
143144
['doctrine.entitymanager.orm_default', $entityManager],
144145
]);
145146

146-
$factory->createService($serviceLocator);
147+
$factory($serviceLocator, DiffCommand::class);
147148
}
148149
}

tests/Service/RunSqlCommandFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCreateCommand(): void
2828

2929
$this->assertInstanceOf(
3030
RunSqlCommand::class,
31-
$factory->createService($this->serviceLocator)
31+
$factory($this->serviceLocator, RunSqlCommand::class)
3232
);
3333
}
3434
}

tests/Service/SQLLoggerCollectorFactoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testCreateSQLLoggerCollector(): void
4141
],
4242
]
4343
);
44-
$service = $this->factory->createService($this->services);
44+
$service = ($this->factory)($this->services, SQLLoggerCollector::class);
4545
$this->assertInstanceOf(SQLLoggerCollector::class, $service);
4646
$this->assertInstanceOf(SQLLogger::class, $configuration->getSQLLogger());
4747
}
@@ -60,7 +60,7 @@ public function testCreateSQLLoggerWithCustomConfiguration(): void
6060
],
6161
]
6262
);
63-
$this->factory->createService($this->services);
63+
($this->factory)($this->services, SQLLoggerCollector::class);
6464
$this->assertInstanceOf(SQLLogger::class, $configuration->getSQLLogger());
6565
}
6666

@@ -91,7 +91,7 @@ public function testCreateSQLLoggerWithPreviousExistingLoggerChainsLoggers(): vo
9191
],
9292
]
9393
);
94-
$this->factory->createService($this->services);
94+
($this->factory)($this->services, SQLLoggerCollector::class);
9595
$logger = $configuration->getSQLLogger();
9696
assert($logger instanceof SQLLogger);
9797
$logger->startQuery('test query');
@@ -113,7 +113,7 @@ public function testCreateSQLLoggerWithCustomLogger(): void
113113
],
114114
]
115115
);
116-
$this->factory->createService($this->services);
116+
($this->factory)($this->services, SQLLoggerCollector::class);
117117
$this->assertSame($logger, $configuration->getSQLLogger());
118118
}
119119

@@ -130,7 +130,7 @@ public function testCreateSQLLoggerWithCustomName(): void
130130
],
131131
]
132132
);
133-
$service = $this->factory->createService($this->services);
133+
$service = ($this->factory)($this->services, SQLLoggerCollector::class);
134134
assert($service instanceof SQLLoggerCollector);
135135
$this->assertSame('doctrine.sql_logger_collector.test_collector_name', $service->getName());
136136
}

tests/Yuml/YumlControllerFactoryTest.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use DoctrineORMModule\Yuml\YumlController;
88
use DoctrineORMModule\Yuml\YumlControllerFactory;
9-
use Laminas\ServiceManager\AbstractPluginManager;
109
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
1110
use Laminas\ServiceManager\ServiceLocatorInterface;
1211
use PHPUnit\Framework\TestCase;
@@ -22,15 +21,10 @@ public function testCreateService(): void
2221
];
2322

2423
$serviceLocator = $this->createMock(ServiceLocatorInterface::class);
25-
$pluginManager = $this->getMockBuilder(AbstractPluginManager::class)
26-
->disableOriginalConstructor()
27-
->getMock();
28-
2924
$serviceLocator->expects($this->once())->method('get')->with('config')->willReturn($config);
30-
$pluginManager->expects($this->once())->method('getServiceLocator')->willReturn($serviceLocator);
3125

3226
$factory = new YumlControllerFactory();
33-
$controller = $factory->createService($pluginManager);
27+
$controller = $factory($serviceLocator, YumlController::class);
3428

3529
$this->assertInstanceOf(YumlController::class, $controller);
3630
}
@@ -44,17 +38,12 @@ public function testCreateServiceWithNotEnabledToolbar(): void
4438
];
4539

4640
$serviceLocator = $this->createMock(ServiceLocatorInterface::class);
47-
$pluginManager = $this->getMockBuilder(AbstractPluginManager::class)
48-
->disableOriginalConstructor()
49-
->getMock();
50-
5141
$serviceLocator->expects($this->once())->method('get')->with('config')->willReturn($config);
52-
$pluginManager->expects($this->once())->method('getServiceLocator')->willReturn($serviceLocator);
5342

5443
$factory = new YumlControllerFactory();
5544

5645
$this->expectException(ServiceNotFoundException::class);
57-
$factory->createService($pluginManager);
46+
$factory($serviceLocator, YumlController::class);
5847
}
5948

6049
public function testCreateServiceWithNoConfigKey(): void
@@ -64,16 +53,11 @@ public function testCreateServiceWithNoConfigKey(): void
6453
];
6554

6655
$serviceLocator = $this->createMock(ServiceLocatorInterface::class);
67-
$pluginManager = $this->getMockBuilder(AbstractPluginManager::class)
68-
->disableOriginalConstructor()
69-
->getMock();
70-
7156
$serviceLocator->expects($this->once())->method('get')->with('config')->willReturn($config);
72-
$pluginManager->expects($this->once())->method('getServiceLocator')->willReturn($serviceLocator);
7357

7458
$factory = new YumlControllerFactory();
7559

7660
$this->expectException(ServiceNotFoundException::class);
77-
$factory->createService($pluginManager);
61+
$factory($serviceLocator, YumlController::class);
7862
}
7963
}

0 commit comments

Comments
 (0)