Skip to content

Commit 77eaf03

Browse files
authored
Merge pull request #3 from tweakers/arjenm-doc-updates
Update README.md to reflect changed method names and fix method name
2 parents 97a2061 + 7a6166a commit 77eaf03

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class TestServiceTest extends KernelTestCase
8282
parent::tearDown();
8383

8484
// Make sure the original version is restored inside the proxy
85-
self::$container->get(TestService::class)->reset();
85+
self::$container->get(TestService::class)->restoreOriginalService();
8686
}
8787

8888
public function testServiceBehaviorCanBeChanged(): void
@@ -97,19 +97,19 @@ class TestServiceTest extends KernelTestCase
9797
$mock = $this->createMock(TestService::class);
9898
$mock->method('getStuff')->willReturn(42);
9999

100-
$service->setAlternative($mock);
100+
$service->setAlternativeService($mock);
101101

102102
$this->assertSame(42, $service->getStuff());
103103

104104
// Revert to original service
105-
$service->reset();
105+
$service->restoreOriginalService();
106106
$this->assertSame(39, $service->getStuff());
107107
}
108108
}
109109
```
110110

111111
## Compatibility
112-
This code has only been tested with Symfony 3.4 and 4.1, although it should work with 4.0 and older versions.
113-
In Symfony 4.1 a [TestContainer](https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing) was introduced that gives access to private services.
112+
This code has only been tested with Symfony 3.4, 4.1 and 4.2, although it should work with 4.0 and older versions.
113+
In Symfony 4.1 a [TestContainer](https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing) was introduced that gives access to private services. So it may not be necessary to define a service as public with Symfony 4.1 and higher.
114114
Symfony however does 'inline' or completely remove unused private services (even in 4.1), so tests may fail due to missing services if you define everything private.
115-
To prevent inlining, the example above creates the proxies with public=true, but it may also be necessary to redefine specific services as well.
115+
To prevent inlining, the example above creates the proxies with public=true, but it may also be necessary to redefine specific services as well.

src/MockableService/MockableService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ public function setOriginalService(object $original): void;
2424
/**
2525
* Remove the 'alternative' service and revert to 'original' service.
2626
*/
27-
public function restoreOriginalServices(): void;
27+
public function restoreOriginalService(): void;
2828
}

src/MockableService/MockableServiceProxyGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* It also adds these methods to allow modifying the state:
2727
* 'setOriginalService' @see SetOriginalGenerator
2828
* 'setAlternativeService' @see SetAlternativeGenerator
29-
* 'restoreOriginalServices' @see RestoreOriginalsGenerator
29+
* 'restoreOriginalService' @see RestoreOriginalsGenerator
3030
*
3131
* @author Arjen
3232
*/

src/MockableService/RestoreOriginalsGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* It generates this method:
1212
*
13-
* public function restoreOriginalServices(object $original) : void
13+
* public function restoreOriginalService(object $original) : void
1414
* {
1515
* $this->originalService = $original;
1616
* $this->valueHolder = $original;
@@ -22,7 +22,7 @@ class RestoreOriginalsGenerator extends MethodGenerator
2222
{
2323
public function __construct(PropertyGenerator $original, PropertyGenerator $valueHolder)
2424
{
25-
parent::__construct('restoreOriginalServices');
25+
parent::__construct('restoreOriginalService');
2626

2727
$this->setDocBlock('{@inheritDoc}');
2828
$this->setReturnType('void');

test/MockableService/MockableServiceProxyFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function it_should_generate_a_working_set_alternative(): void
5151
public function it_should_generate_a_working_reset(): void
5252
{
5353
$this->proxy->setAlternativeService($this->alternative);
54-
$this->proxy->restoreOriginalServices();
54+
$this->proxy->restoreOriginalService();
5555

5656
$this->assertEquals($this->original->getValue(), $this->proxy->getValue());
5757
}

test/MockableService/RestoreOriginalsGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function it_should_generate_the_reset_method(): void
2121
/**
2222
* {@inheritDoc}
2323
*/
24-
public function restoreOriginalServices() : void
24+
public function restoreOriginalService() : void
2525
{
2626
$this->valueHolder = $this->original;
2727
}

0 commit comments

Comments
 (0)