Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 70d7994

Browse files
committed
Removed Context dep.
1 parent e54ed37 commit 70d7994

File tree

6 files changed

+17
-12
lines changed

6 files changed

+17
-12
lines changed

Enhancer/EnhancerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ interface EnhancerInterface
3131
* @param Context Serialization context
3232
* @param Resource The resource being serialized
3333
*/
34-
public function enhance(array $data, Context $context, Resource $resource);
34+
public function enhance(array $data, Resource $resource);
3535
}

Enhancer/PayloadEnhancer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ class PayloadEnhancer implements EnhancerInterface
2424
/**
2525
* {@inheritDoc}
2626
*/
27-
public function enhance(array $data, Context $context, Resource $resource)
27+
public function enhance(array $data, Resource $resource)
2828
{
29-
$visitor = $context->getVisitor();
3029
$payload = $resource->getPayload();
31-
3230
$data['payload'] = $payload;
3331

3432
return $data;

Enhancer/SonataAdminEnhancer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(Pool $pool, UrlGeneratorInterface $urlGenerator)
3636
/**
3737
* {@inheritDoc}
3838
*/
39-
public function enhance(array $data, Context $context, Resource $resource)
39+
public function enhance(array $data, Resource $resource)
4040
{
4141
$object = $resource->getPayload();
4242

@@ -48,7 +48,6 @@ public function enhance(array $data, Context $context, Resource $resource)
4848
}
4949

5050
$admin = $this->pool->getAdminByClass($class);
51-
$visitor = $context->getVisitor();
5251

5352
$links = array();
5453
foreach (array_keys($admin->getRoutes()) as $routeName) {

Serializer/Handler/ResourceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function serializeResource(
8181
$enhancers = $this->enhancerRegistry->getEnhancers($repositoryAlias);
8282

8383
foreach ($enhancers as $enhancer) {
84-
$data = $enhancer->enhance($data, $context, $resource);
84+
$data = $enhancer->enhance($data, $resource);
8585
}
8686

8787
$context->accept($data);

Tests/Unit/DependencyInjection/CmfResourceRestExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function provideExtension()
5050
*/
5151
public function testExtension($config)
5252
{
53+
$this->container->setParameter('kernel.bundles', array());
5354
$this->container->addCompilerPass(new EnhancerPass());
5455
$this->load($config);
5556
$this->compile();

Tests/Unit/Enhancer/SonataAdminEnhancerTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public function setUp()
2424
{
2525
$this->admin = $this->prophesize('Sonata\AdminBundle\Admin\Admin');
2626
$this->pool = $this->prophesize('Sonata\AdminBundle\Admin\Pool');
27-
$this->context = $this->prophesize('JMS\Serializer\Context');
2827
$this->visitor = $this->prophesize('JMS\Serializer\GenericSerializationVisitor');
2928
$this->generator = $this->prophesize('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
3029
$this->payload = new \stdClass;
3130
$this->resource = $this->prophesize('Puli\Repository\Api\Resource\Resource');
31+
$this->route = $this->prophesize('Symfony\Component\Routing\Route');
3232

3333
$this->enhancer = new SonataAdminEnhancer($this->pool->reveal(), $this->generator->reveal());
3434

@@ -40,11 +40,9 @@ public function testEnhancerNoHasClass()
4040
$this->resource->getPayload()->willReturn($this->payload);
4141

4242
$result = $this->enhancer->enhance(
43-
$this->context->reveal(),
43+
array(),
4444
$this->resource->reveal()
4545
);
46-
47-
$this->visitor->addData()->shouldNotBeCalled();
4846
}
4947

5048
public function testEnhancer()
@@ -53,9 +51,18 @@ public function testEnhancer()
5351
$this->pool->getAdminByClass('stdClass')->willReturn($this->admin);
5452

5553
$this->resource->getPayload()->willReturn($this->payload);
54+
$data = array();
55+
$this->admin->getRoutes()->willReturn(
56+
array(
57+
'foo' => $this->route
58+
)
59+
);
60+
$this->admin->getIdParameter()->willReturn('id');
61+
$this->admin->getUrlsafeIdentifier($this->payload)->willReturn(10);
62+
$this->admin->getLabel()->willReturn('asd');
5663

5764
$result = $this->enhancer->enhance(
58-
$this->context->reveal(),
65+
$data,
5966
$this->resource->reveal()
6067
);
6168

0 commit comments

Comments
 (0)