Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 07d53d3

Browse files
committed
removed old PHPUnit4 Parts
changed `setExpectedException` to `expectException` and `expectExceptionMessage` added in `testCanCreateServiceWithAbstractFactory` a assert
1 parent 9247ee5 commit 07d53d3

7 files changed

+33
-28
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"require-dev": {
2222
"ocramius/proxy-manager": "^1.0 || ^2.0",
2323
"phpbench/phpbench": "^0.10.0",
24-
"phpunit/phpunit": "^4.6 || ^5.2.10",
24+
"phpunit/phpunit": "^5.2.10",
2525
"mikey179/vfsStream": "^1.6",
2626
"zendframework/zend-coding-standard": "~1.0.0"
2727
},

src/Test/CommonPluginManagerTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ public function testShareByDefaultAndSharedByDefault()
5353

5454
public function testRegisteringInvalidElementRaisesException()
5555
{
56-
$this->setExpectedException($this->getServiceNotFoundException());
56+
$this->expectException($this->getServiceNotFoundException());
5757
$this->getPluginManager()->setService('test', $this);
5858
}
5959

6060
public function testLoadingInvalidElementRaisesException()
6161
{
6262
$manager = $this->getPluginManager();
6363
$manager->setInvokableClass('test', get_class($this));
64-
$this->setExpectedException($this->getServiceNotFoundException());
64+
$this->expectException($this->getServiceNotFoundException());
6565
$manager->get('test');
6666
}
6767

test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function testFactoryRaisesExceptionWhenUnableToResolveATypeHintedService(
5454
$this->container->has(TestAsset\SampleInterface::class)->willReturn(false);
5555
$this->container->has('config')->willReturn(false);
5656
$factory = new ReflectionBasedAbstractFactory();
57-
$this->setExpectedException(
58-
ServiceNotFoundException::class,
57+
$this->expectException(ServiceNotFoundException::class);
58+
$this->expectExceptionMessage(
5959
sprintf(
6060
'Unable to create service "%s"; unable to resolve parameter "sample" using type hint "%s"',
6161
TestAsset\ClassWithTypeHintedConstructorParameter::class,
@@ -68,8 +68,8 @@ public function testFactoryRaisesExceptionWhenUnableToResolveATypeHintedService(
6868
public function testFactoryRaisesExceptionForScalarParameters()
6969
{
7070
$factory = new ReflectionBasedAbstractFactory();
71-
$this->setExpectedException(
72-
ServiceNotFoundException::class,
71+
$this->expectException(ServiceNotFoundException::class);
72+
$this->expectExceptionMessage(
7373
sprintf(
7474
'Unable to create service "%s"; unable to resolve parameter "foo" to a class, interface, or array type',
7575
TestAsset\ClassWithScalarParameters::class

test/AbstractPluginManagerTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function testValidateInstance()
7777
$pluginManager->get(InvokableObject::class);
7878

7979
// Assert it throws an exception for anything else
80-
$this->setExpectedException(InvalidServiceException::class);
80+
$this->expectException(InvalidServiceException::class);
8181
$pluginManager->get(stdClass::class);
8282
}
8383

@@ -181,7 +181,7 @@ function ($container, $name, $callback) {
181181
public function testGetRaisesExceptionWhenNoFactoryIsResolved()
182182
{
183183
$pluginManager = $this->createContainer();
184-
$this->setExpectedException(ServiceNotFoundException::class, get_class($pluginManager));
184+
$this->expectException(ServiceNotFoundException::class, get_class($pluginManager));
185185
$pluginManager->get('Some\Unknown\Service');
186186
}
187187

@@ -259,7 +259,7 @@ public function invalidConstructorArguments()
259259
*/
260260
public function testPassingNonContainerNonConfigNonNullFirstConstructorArgumentRaisesException($arg)
261261
{
262-
$this->setExpectedException(InvalidArgumentException::class);
262+
$this->expectException(InvalidArgumentException::class);
263263
new TestAsset\LenientPluginManager($arg);
264264
}
265265

@@ -308,7 +308,8 @@ public function testSupportsRetrievingAutoInvokableServicesByDefault()
308308
public function testPluginManagersMayOptOutOfSupportingAutoInvokableServices()
309309
{
310310
$pluginManager = new TestAsset\NonAutoInvokablePluginManager(new ServiceManager());
311-
$this->setExpectedException(ServiceNotFoundException::class, TestAsset\NonAutoInvokablePluginManager::class);
311+
$this->expectException(ServiceNotFoundException::class);
312+
$this->expectExceptionMessage(TestAsset\NonAutoInvokablePluginManager::class);
312313
$pluginManager->get(TestAsset\InvokableObject::class);
313314
}
314315

@@ -342,14 +343,14 @@ public function testValidateWillFallBackToValidatePluginWhenDefinedAndEmitDeprec
342343
public function testSetServiceShouldRaiseExceptionForInvalidPlugin()
343344
{
344345
$pluginManager = new TestAsset\SimplePluginManager(new ServiceManager());
345-
$this->setExpectedException(InvalidServiceException::class);
346+
$this->expectException(InvalidServiceException::class);
346347
$pluginManager->setService(stdClass::class, new stdClass());
347348
}
348349

349350
public function testPassingServiceInstanceViaConfigureShouldRaiseExceptionForInvalidPlugin()
350351
{
351352
$pluginManager = new TestAsset\SimplePluginManager(new ServiceManager());
352-
$this->setExpectedException(InvalidServiceException::class);
353+
$this->expectException(InvalidServiceException::class);
353354
$pluginManager->configure(['services' => [
354355
stdClass::class => new stdClass(),
355356
]]);

test/CommonServiceLocatorBehaviorsTrait.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function testCanCreateServiceWithAbstractFactory()
136136
]
137137
]);
138138

139-
$serviceManager->get(DateTime::class);
139+
$this->assertInstanceOf(DateTime::class, $serviceManager->get(DateTime::class));
140140
}
141141

142142
public function testAllowsMultipleInstancesOfTheSameAbstractFactory()
@@ -258,7 +258,7 @@ public function testThrowExceptionIfServiceCannotBeCreated()
258258
]
259259
]);
260260

261-
$this->setExpectedException(ServiceNotCreatedException::class);
261+
$this->expectException(ServiceNotCreatedException::class);
262262

263263
$serviceManager->get(stdClass::class);
264264
}
@@ -271,7 +271,7 @@ public function testThrowExceptionWithStringAsCodeIfServiceCannotBeCreated()
271271
]
272272
]);
273273

274-
$this->setExpectedException(ServiceNotCreatedException::class);
274+
$this->expectException(ServiceNotCreatedException::class);
275275

276276
$serviceManager->get(stdClass::class);
277277
}
@@ -512,7 +512,8 @@ public function testPassingInvalidAbstractFactoryTypeViaConfigurationRaisesExcep
512512
$factory,
513513
$contains = 'invalid abstract factory'
514514
) {
515-
$this->setExpectedException(InvalidArgumentException::class, $contains);
515+
$this->expectException(InvalidArgumentException::class);
516+
$this->expectExceptionMessage($contains);
516517
$serviceManager = $this->createContainer([
517518
'abstract_factories' => [
518519
$factory,
@@ -552,7 +553,8 @@ public function testPassingInvalidInitializerTypeViaConfigurationRaisesException
552553
$initializer,
553554
$contains = 'invalid initializer'
554555
) {
555-
$this->setExpectedException(InvalidArgumentException::class, $contains);
556+
$this->expectException(InvalidArgumentException::class);
557+
$this->expectExceptionMessage($contains);
556558
$serviceManager = $this->createContainer([
557559
'initializers' => [
558560
$initializer,
@@ -566,7 +568,8 @@ public function testPassingInvalidInitializerTypeViaConfigurationRaisesException
566568
public function testGetRaisesExceptionWhenNoFactoryIsResolved()
567569
{
568570
$serviceManager = $this->createContainer();
569-
$this->setExpectedException(ContainerException::class, 'Unable to resolve');
571+
$this->expectException(ContainerException::class);
572+
$this->expectExceptionMessage('Unable to resolve');
570573
$serviceManager->get('Some\Unknown\Service');
571574
}
572575

@@ -600,7 +603,8 @@ public function testInvalidDelegatorShouldRaiseExceptionDuringCreation(
600603
],
601604
]);
602605

603-
$this->setExpectedException(ServiceNotCreatedException::class, $contains);
606+
$this->expectException(ServiceNotCreatedException::class);
607+
$this->expectExceptionMessage($contains);
604608
$serviceManager->get(stdClass::class);
605609
}
606610

@@ -799,7 +803,7 @@ public function testConfiguringInstanceRaisesExceptionIfAllowOverrideIsFalse($me
799803
{
800804
$container = $this->createContainer(['services' => ['foo' => $this]]);
801805
$container->setAllowOverride(false);
802-
$this->setExpectedException(ContainerModificationsNotAllowedException::class);
806+
$this->expectException(ContainerModificationsNotAllowedException::class);
803807
call_user_func_array([$container, $method], $args);
804808
}
805809

@@ -841,7 +845,7 @@ public function testCanRetrieveParentContainerViaGetServiceLocatorWithDeprecatio
841845
*/
842846
public function testCrashesOnCyclicAliases()
843847
{
844-
$this->setExpectedException(CyclicAliasException::class);
848+
$this->expectException(CyclicAliasException::class);
845849

846850
$this->createContainer([
847851
'aliases' => [

test/LazyServiceIntegrationTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ public function testMissingClassMapRaisesExceptionOnAttemptToRetrieveLazyService
162162
];
163163

164164
$container = new ServiceManager($config);
165-
$this->setExpectedException(ServiceNotCreatedException::class, 'class_map');
165+
$this->expectException(ServiceNotCreatedException::class);
166+
$this->expectExceptionMessage('class_map');
166167
$container->get(InvokableObject::class);
167168
}
168169

@@ -277,7 +278,8 @@ public function testRaisesServiceNotFoundExceptionIfRequestedLazyServiceIsNotInC
277278

278279
$container = new ServiceManager($config);
279280

280-
$this->setExpectedException(ServiceNotFoundException::class, 'not found in the provided services map');
281+
$this->expectException(ServiceNotFoundException::class);
282+
$this->expectExceptionMessage('not found in the provided services map');
281283
$container->build(InvokableObject::class, ['foo' => 'bar']);
282284
}
283285

test/Proxy/LazyServiceFactoryTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ public function testThrowExceptionWhenServiceNotExists()
6464
$this->proxyFactory->expects($this->never())
6565
->method('createProxy')
6666
;
67-
$this->setExpectedException(
68-
ServiceNotFoundException::class,
69-
'The requested service "not_exists" was not found in the provided services map'
70-
);
67+
$this->expectException(ServiceNotFoundException::class);
68+
$this->expectExceptionMessage('The requested service "not_exists" was not found in the provided services map');
7169

7270
$this->factory->__invoke($container, 'not_exists', [$callback, 'callback']);
7371
}

0 commit comments

Comments
 (0)