Skip to content

Commit f0fbe38

Browse files
[PhpUnitBridge] Drop ErrorAssert in favor of @expectedDeprecation
1 parent 4733a9c commit f0fbe38

File tree

1 file changed

+43
-86
lines changed

1 file changed

+43
-86
lines changed

Tests/ContainerTest.php

Lines changed: 43 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Tests;
1313

14-
use Symfony\Bridge\PhpUnit\ErrorAssert;
1514
use Symfony\Component\DependencyInjection\Container;
1615
use Symfony\Component\DependencyInjection\ContainerInterface;
1716
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -131,20 +130,14 @@ public function testGetServiceIds()
131130

132131
/**
133132
* @group legacy
134-
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
133+
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
135134
*/
136135
public function testGetLegacyServiceIds()
137136
{
138137
$sc = new LegacyProjectServiceContainer();
139138
$sc->set('foo', $obj = new \stdClass());
140139

141-
$deprecations = array(
142-
'Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.',
143-
);
144-
145-
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () use ($sc) {
146-
$this->assertEquals(array('internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
147-
});
140+
$this->assertEquals(array('internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
148141
}
149142

150143
public function testSet()
@@ -193,39 +186,33 @@ public function testGet()
193186

194187
/**
195188
* @group legacy
196-
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
189+
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
190+
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
191+
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
192+
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
197193
*/
198194
public function testLegacyGet()
199195
{
200196
$sc = new LegacyProjectServiceContainer();
201197
$sc->set('foo', $foo = new \stdClass());
202198

203-
$deprecations = array(
204-
'Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.',
205-
'Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.',
206-
'Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.',
207-
'Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.',
208-
);
209-
210-
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () use ($sc, $foo) {
211-
$this->assertEquals($foo, $sc->get('foo'), '->get() returns the service for the given id');
212-
$this->assertEquals($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
213-
$this->assertEquals($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
214-
$this->assertEquals($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
215-
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
216-
$this->assertEquals($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
199+
$this->assertEquals($foo, $sc->get('foo'), '->get() returns the service for the given id');
200+
$this->assertEquals($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
201+
$this->assertEquals($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
202+
$this->assertEquals($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
203+
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
204+
$this->assertEquals($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
217205

218-
$sc->set('bar', $bar = new \stdClass());
219-
$this->assertEquals($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
206+
$sc->set('bar', $bar = new \stdClass());
207+
$this->assertEquals($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
220208

221-
try {
222-
$sc->get('');
223-
$this->fail('->get() throws a \InvalidArgumentException exception if the service is empty');
224-
} catch (\Exception $e) {
225-
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws a ServiceNotFoundException exception if the service is empty');
226-
}
227-
$this->assertNull($sc->get('', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service is empty');
228-
});
209+
try {
210+
$sc->get('');
211+
$this->fail('->get() throws a \InvalidArgumentException exception if the service is empty');
212+
} catch (\Exception $e) {
213+
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws a ServiceNotFoundException exception if the service is empty');
214+
}
215+
$this->assertNull($sc->get('', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service is empty');
229216
}
230217

231218
public function testGetThrowServiceNotFoundException()
@@ -288,28 +275,22 @@ public function testHas()
288275

289276
/**
290277
* @group legacy
291-
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
278+
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
279+
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
280+
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
281+
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
292282
*/
293283
public function testLegacyHas()
294284
{
295285
$sc = new LegacyProjectServiceContainer();
296286
$sc->set('foo', new \stdClass());
297287

298-
$deprecations = array(
299-
'Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.',
300-
'Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.',
301-
'Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.',
302-
'Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.',
303-
);
304-
305-
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () use ($sc) {
306-
$this->assertFalse($sc->has('foo1'), '->has() returns false if the service does not exist');
307-
$this->assertTrue($sc->has('foo'), '->has() returns true if the service exists');
308-
$this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
309-
$this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
310-
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
311-
$this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined');
312-
});
288+
$this->assertFalse($sc->has('foo1'), '->has() returns false if the service does not exist');
289+
$this->assertTrue($sc->has('foo'), '->has() returns true if the service exists');
290+
$this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
291+
$this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
292+
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
293+
$this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined');
313294
}
314295

315296
public function testInitialized()
@@ -400,66 +381,42 @@ public function testThatCloningIsNotSupported()
400381

401382
/**
402383
* @group legacy
403-
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
384+
* @expectedDeprecation Unsetting the "internal" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0.
404385
*/
405386
public function testUnsetInternalPrivateServiceIsDeprecated()
406387
{
407-
$deprecations = array(
408-
'Unsetting the "internal" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.',
409-
);
410-
411-
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () {
412-
$c = new ProjectServiceContainer();
413-
$c->set('internal', null);
414-
});
388+
$c = new ProjectServiceContainer();
389+
$c->set('internal', null);
415390
}
416391

417392
/**
418393
* @group legacy
419-
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
394+
* @expectedDeprecation Setting the "internal" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0. A new public service will be created instead.
420395
*/
421396
public function testChangeInternalPrivateServiceIsDeprecated()
422397
{
423-
$deprecations = array(
424-
'Setting the "internal" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0. A new public service will be created instead.',
425-
);
426-
427-
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () {
428-
$c = new ProjectServiceContainer();
429-
$c->set('internal', new \stdClass());
430-
});
398+
$c = new ProjectServiceContainer();
399+
$c->set('internal', new \stdClass());
431400
}
432401

433402
/**
434403
* @group legacy
435-
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
404+
* @expectedDeprecation Checking for the existence of the "internal" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0.
436405
*/
437406
public function testCheckExistenceOfAnInternalPrivateServiceIsDeprecated()
438407
{
439-
$deprecations = array(
440-
'Checking for the existence of the "internal" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.',
441-
);
442-
443-
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () {
444-
$c = new ProjectServiceContainer();
445-
$c->has('internal');
446-
});
408+
$c = new ProjectServiceContainer();
409+
$c->has('internal');
447410
}
448411

449412
/**
450413
* @group legacy
451-
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
414+
* @expectedDeprecation Requesting the "internal" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0.
452415
*/
453416
public function testRequestAnInternalSharedPrivateServiceIsDeprecated()
454417
{
455-
$deprecations = array(
456-
'Requesting the "internal" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.',
457-
);
458-
459-
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () {
460-
$c = new ProjectServiceContainer();
461-
$c->get('internal');
462-
});
418+
$c = new ProjectServiceContainer();
419+
$c->get('internal');
463420
}
464421
}
465422

0 commit comments

Comments
 (0)