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

Commit 9228104

Browse files
committed
Clear cache in behat tests
1 parent b0d8b95 commit 9228104

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

Serializer/Jms/Handler/ResourceHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public function serializeResource(
6666
array $type,
6767
Context $context
6868
) {
69-
7069
$data = $this->doSerializeResource($resource);
7170
$context->accept($data);
7271
}

Tests/Features/Context/ResourceContext.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function beforeScenario(BeforeScenarioScope $scope)
4747

4848
touch(__DIR__ . '/../../Resources/app/config/config.php');
4949

50+
$this->cacheClearer = $this->kernel->getContainer()->get('cache_clearer')->clear(
51+
$this->kernel->getCacheDir()
52+
);
53+
5054
$this->manager = $this->kernel->getContainer()->get('doctrine_phpcr.odm.document_manager');
5155
$this->session = $this->manager->getPhpcrSession();
5256

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2014 Symfony CMF
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Cmf\Bundle\ResourceRestBundle\Tests\Serializer\Handler;
13+
14+
use Prophecy\PhpUnit\ProphecyTestCase;
15+
use Symfony\Cmf\Bundle\ResourceRestBundle\Serializer\Jms\Handler\ResourceHandler;
16+
use Prophecy\Argument;
17+
18+
class ResourceHandlerTest extends ProphecyTestCase
19+
{
20+
public function setUp()
21+
{
22+
parent::setUp();
23+
24+
$this->repositoryRegistry = $this->prophesize('Symfony\Cmf\Component\Resource\RepositoryRegistryInterface');
25+
$this->payloadAliasRegistry = $this->prophesize('Symfony\Cmf\Bundle\ResourceRestBundle\Registry\PayloadAliasRegistry');
26+
$this->enhancerRegistry = $this->prophesize('Symfony\Cmf\Bundle\ResourceRestBundle\Registry\EnhancerRegistry');
27+
$this->enhancer = $this->prophesize('Symfony\Cmf\Bundle\ResourceRestBundle\Enhancer\EnhancerInterface');
28+
$this->visitor = $this->prophesize('JMS\Serializer\JsonSerializationVisitor');
29+
$this->resource = $this->prophesize('Symfony\Cmf\Component\Resource\Repository\Resource\CmfResource');
30+
$this->childResource = $this->prophesize('Symfony\Cmf\Component\Resource\Repository\Resource\CmfResource');
31+
32+
$this->repository = $this->prophesize('Puli\Repository\Api\ResourceRepository');
33+
$this->payload = new \stdClass;
34+
$this->context = $this->prophesize('JMS\Serializer\Context');
35+
36+
$this->handler = new ResourceHandler(
37+
$this->repositoryRegistry->reveal(),
38+
$this->payloadAliasRegistry->reveal(),
39+
$this->enhancerRegistry->reveal()
40+
);
41+
42+
$this->resource->getRepository()->willReturn($this->repository);
43+
}
44+
45+
public function testHandler()
46+
{
47+
$this->repositoryRegistry->getRepositoryAlias($this->repository)->willReturn('repo');
48+
$this->repositoryRegistry->getRepositoryType($this->repository)->willReturn('repo_type');
49+
$this->payloadAliasRegistry->getPayloadAlias($this->resource->reveal())->willReturn('alias');
50+
$this->resource->getPayloadType()->willReturn('payload_type');
51+
$this->resource->getPath()->willReturn('/path/to');
52+
$this->resource->getRepositoryPath()->willReturn('/repository/path');
53+
$this->resource->listChildren()->willReturn(array(
54+
$this->childResource
55+
));
56+
57+
$this->payloadAliasRegistry->getPayloadAlias($this->childResource->reveal())->willReturn('alias');
58+
$this->childResource->getPayloadType()->willReturn('payload_type');
59+
$this->childResource->getPath()->willReturn('/path/to/child');
60+
$this->childResource->getRepositoryPath()->willReturn('/child/repository/path');
61+
$this->childResource->getRepository()->willReturn($this->repository->reveal());
62+
$this->childResource->listChildren()->willReturn(array(
63+
));
64+
65+
$this->enhancerRegistry->getEnhancers('repo')->willReturn(array(
66+
$this->enhancer
67+
));
68+
$this->enhancer->enhance(Argument::type('array'), Argument::type('Puli\Repository\Api\Resource\Resource'))
69+
->will(function ($data, $resource) {
70+
return $data[0];
71+
});
72+
73+
$expected = array (
74+
'repository_alias' => 'repo',
75+
'repository_type' => 'repo_type',
76+
'payload_alias' => 'alias',
77+
'payload_type' => 'payload_type',
78+
'path' => '/path/to',
79+
'repository_path' => '/repository/path',
80+
'children' => array(
81+
array (
82+
'repository_alias' => 'repo',
83+
'repository_type' => 'repo_type',
84+
'payload_alias' => 'alias',
85+
'payload_type' => 'payload_type',
86+
'path' => '/path/to/child',
87+
'repository_path' => '/child/repository/path',
88+
'children' => array()
89+
),
90+
),
91+
);
92+
93+
$this->context->accept($expected)->shouldBeCalled();
94+
95+
$this->handler->serializeResource(
96+
$this->visitor->reveal(),
97+
$this->resource->reveal(),
98+
array(),
99+
$this->context->reveal()
100+
);
101+
}
102+
}
103+

0 commit comments

Comments
 (0)