Skip to content

Commit d8a5768

Browse files
Moved tests to properly directory
1 parent 34ae947 commit d8a5768

12 files changed

+106
-19
lines changed

src/Component/spec/Symfony/Routing/Factory/AttributesOperationRouteFactorySpec.php renamed to src/Component/tests/Symfony/Routing/Factory/AttributesOperationRouteFactoryTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Sylius\Resource\Metadata\Index;
2020
use Sylius\Resource\Metadata\MetadataInterface;
2121
use Sylius\Resource\Metadata\Operation;
22-
use Sylius\Resource\Metadata\Operations;
2322
use Sylius\Resource\Metadata\RegistryInterface;
2423
use Sylius\Resource\Metadata\Resource\Factory\AttributesResourceMetadataCollectionFactory;
2524
use Sylius\Resource\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
@@ -112,18 +111,15 @@ public function testItSkipsNonHttpOperations(): void
112111
{
113112
$routeCollection = new RouteCollection();
114113

115-
// Create a non-HTTP operation (directly extends Operation, not HttpOperation)
116114
$nonHttpOperation = new class() extends Operation {
117115
public function getShortName(): ?string
118116
{
119117
return 'custom';
120118
}
121119
};
122120

123-
// Create an HTTP operation
124121
$httpOperation = (new Index(name: 'app_dummy_index'))->withRouteName('app_dummy_index');
125122

126-
// Create resource with mixed operations
127123
$resource = new ResourceMetadata(
128124
alias: 'app.dummy',
129125
name: 'dummy',
@@ -136,14 +132,12 @@ public function getShortName(): ?string
136132
$resourceCollection = new ResourceMetadataCollection();
137133
$resourceCollection[] = $resource;
138134

139-
// Mock resource metadata factory to return our custom collection
140135
$resourceMetadataFactory = $this->createMock(ResourceMetadataCollectionFactoryInterface::class);
141136
$resourceMetadataFactory
142137
->method('create')
143138
->with(\stdClass::class)
144139
->willReturn($resourceCollection);
145140

146-
// Mock metadata for registry
147141
$metadata = $this->createDummyMetadataMock();
148142
$this->resourceRegistry->method('get')->with('app.dummy')->willReturn($metadata);
149143

@@ -153,7 +147,6 @@ public function getShortName(): ?string
153147
->with($httpOperation, 'dummies')
154148
->willReturn('/dummies');
155149

156-
// Create factory with mocked dependencies
157150
$factory = new AttributesOperationRouteFactory(
158151
$this->resourceRegistry,
159152
new OperationRouteFactory($this->routePathFactory),
@@ -162,7 +155,6 @@ public function getShortName(): ?string
162155

163156
$factory->createRouteForClass($routeCollection, \stdClass::class);
164157

165-
// Only the HTTP operation should create a route
166158
$this->assertCount(1, $routeCollection);
167159
$this->assertNotNull($routeCollection->get('app_dummy_index'), 'Route "app_dummy_index" not found but it should.');
168160
$this->assertNull($routeCollection->get('app_dummy_custom'), 'Non-HTTP operation should not create a route.');

src/Component/spec/Symfony/Routing/Factory/OperationRouteFactorySpec.php renamed to src/Component/tests/Symfony/Routing/Factory/OperationRouteFactoryTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function testItCreatesRouteWithCustomPath(): void
6262
$resource = new ResourceMetadata(alias: 'app.book');
6363
$operation = new Index(path: '/custom/books/list');
6464

65-
// routePathFactory should not be called when path is explicitly set
6665
$this->routePathFactory
6766
->expects($this->never())
6867
->method('createRoutePath');
@@ -246,7 +245,6 @@ public function testItCreatesRouteWithEmptyConditionWhenNotSet(): void
246245

247246
$route = $this->operationRouteFactory->create($metadata, $resource, $operation);
248247

249-
// Symfony Route returns empty string when condition is null
250248
$this->assertSame('', $route->getCondition());
251249
}
252250

src/Component/tests/Symfony/Routing/Factory/Resource/ResourceRouteCollectionFactoryTest.php

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515

1616
use PHPUnit\Framework\TestCase;
1717
use Sylius\Component\Resource\Tests\Dummy\DummyResourceWithOperations;
18+
use Sylius\Resource\Metadata\Index;
1819
use Sylius\Resource\Metadata\MetadataInterface;
20+
use Sylius\Resource\Metadata\Operation;
1921
use Sylius\Resource\Metadata\RegistryInterface;
2022
use Sylius\Resource\Metadata\Resource\Factory\AttributesResourceMetadataCollectionFactory;
23+
use Sylius\Resource\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
24+
use Sylius\Resource\Metadata\Resource\ResourceMetadataCollection;
25+
use Sylius\Resource\Metadata\ResourceMetadata;
2126
use Sylius\Resource\Symfony\Routing\Factory\OperationRouteFactory;
2227
use Sylius\Resource\Symfony\Routing\Factory\Resource\ResourceRouteCollectionFactory;
2328
use Sylius\Resource\Symfony\Routing\Factory\RouteName\OperationRouteNameFactory;
@@ -46,7 +51,7 @@ protected function setUp(): void
4651
);
4752
}
4853

49-
public function testItCreatesRoutesWithOperations(): void
54+
private function createDummyMetadataMock(): MetadataInterface
5055
{
5156
$metadata = $this->createMock(MetadataInterface::class);
5257
$metadata->method('getServiceId')->with('repository')->willReturn('app.repository.dummy');
@@ -58,14 +63,65 @@ public function testItCreatesRoutesWithOperations(): void
5863
$metadata->method('getName')->willReturn('dummy');
5964
$metadata->method('getPluralName')->willReturn('dummies');
6065

66+
return $metadata;
67+
}
68+
69+
public function testItCreatesRoutesWithOperations(): void
70+
{
71+
$metadata = $this->createDummyMetadataMock();
6172
$this->resourceRegistry->method('get')->with('app.dummy')->willReturn($metadata);
6273

6374
$routeCollection = $this->factory->createRouteCollectionForClass(DummyResourceWithOperations::class);
6475

65-
$this->assertEquals(4, $routeCollection->count());
76+
$this->assertCount(4, $routeCollection);
6677
$this->assertNotNull($routeCollection->get('app_dummy_index'), 'Route "app_dummy_index" not found but it should.');
6778
$this->assertNotNull($routeCollection->get('app_dummy_create'), 'Route "app_dummy_create" not found but it should.');
6879
$this->assertNotNull($routeCollection->get('app_dummy_update'), 'Route "app_dummy_update" not found but it should.');
6980
$this->assertNotNull($routeCollection->get('app_dummy_show'), 'Route "app_dummy_show" not found but it should.');
7081
}
82+
83+
public function testItSkipsNonHttpOperations(): void
84+
{
85+
$nonHttpOperation = new class() extends Operation {
86+
public function getShortName(): ?string
87+
{
88+
return 'custom';
89+
}
90+
};
91+
92+
$httpOperation = (new Index(name: 'app_dummy_index'))->withRouteName('app_dummy_index');
93+
94+
$resource = new ResourceMetadata(
95+
alias: 'app.dummy',
96+
name: 'dummy',
97+
operations: [
98+
'app_dummy_custom' => $nonHttpOperation,
99+
'app_dummy_index' => $httpOperation,
100+
],
101+
);
102+
103+
$resourceCollection = new ResourceMetadataCollection();
104+
$resourceCollection[] = $resource;
105+
106+
$resourceMetadataFactory = $this->createMock(ResourceMetadataCollectionFactoryInterface::class);
107+
$resourceMetadataFactory
108+
->method('create')
109+
->with(\stdClass::class)
110+
->willReturn($resourceCollection);
111+
112+
$metadata = $this->createDummyMetadataMock();
113+
$this->resourceRegistry->method('get')->with('app.dummy')->willReturn($metadata);
114+
115+
$factory = new ResourceRouteCollectionFactory(
116+
new OperationRouteFactory($this->routePathFactory),
117+
$resourceMetadataFactory,
118+
$this->resourceRegistry,
119+
);
120+
121+
$routeCollection = $factory->createRouteCollectionForClass(\stdClass::class);
122+
123+
$this->assertCount(1, $routeCollection);
124+
$this->assertNotNull($routeCollection->get('app_dummy_index'), 'Route "app_dummy_index" not found but it should.');
125+
$this->assertNull($routeCollection->get('app_dummy_custom'), 'Non-HTTP operation should not create a route.');
126+
}
71127
}

src/Component/spec/Symfony/Routing/Factory/RouteName/OperationRouteNameFactorySpec.php renamed to src/Component/tests/Symfony/Routing/Factory/RouteName/OperationRouteNameFactoryTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public function testItThrowsExceptionWhenOperationHasNoResourceWithShortName():
8686

8787
public function testItThrowsExceptionWhenOperationHasNoResourceWithDefaultShortName(): void
8888
{
89-
// Show operation has default shortName "show"
9089
$operation = new Show();
9190

9291
$this->expectException(\RuntimeException::class);

src/Component/spec/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactorySpec.php renamed to src/Component/tests/Symfony/Routing/Factory/RoutePath/BulkOperationRoutePathFactoryTest.php

File renamed without changes.

src/Component/spec/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactorySpec.php renamed to src/Component/tests/Symfony/Routing/Factory/RoutePath/CollectionOperationRoutePathFactoryTest.php

File renamed without changes.

src/Component/spec/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactorySpec.php renamed to src/Component/tests/Symfony/Routing/Factory/RoutePath/CreateOperationRoutePathFactoryTest.php

File renamed without changes.

src/Component/spec/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactorySpec.php renamed to src/Component/tests/Symfony/Routing/Factory/RoutePath/DeleteOperationRoutePathFactoryTest.php

File renamed without changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
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+
declare(strict_types=1);
13+
14+
namespace Sylius\Resource\Tests\Symfony\Routing\Factory\RoutePath;
15+
16+
use PHPUnit\Framework\TestCase;
17+
use Sylius\Resource\Metadata\Show;
18+
use Sylius\Resource\Symfony\Routing\Factory\RoutePath\OperationRoutePathFactory;
19+
20+
final class OperationRoutePathFactoryTest extends TestCase
21+
{
22+
private OperationRoutePathFactory $operationRoutePathFactory;
23+
24+
protected function setUp(): void
25+
{
26+
$this->operationRoutePathFactory = new OperationRoutePathFactory();
27+
}
28+
29+
public function testItThrowsExceptionWhenCalledWithOperationWithName(): void
30+
{
31+
$operation = new Show(name: 'app_dummy_show');
32+
33+
$this->expectException(\InvalidArgumentException::class);
34+
$this->expectExceptionMessage('Impossible to get a default route path for operation "app_dummy_show". Please define a path.');
35+
36+
$this->operationRoutePathFactory->createRoutePath($operation, '/dummies');
37+
}
38+
39+
public function testItThrowsExceptionWhenCalledWithOperationWithoutName(): void
40+
{
41+
$operation = new Show();
42+
43+
$this->expectException(\InvalidArgumentException::class);
44+
$this->expectExceptionMessage('Impossible to get a default route path for operation "". Please define a path.');
45+
46+
$this->operationRoutePathFactory->createRoutePath($operation, '/dummies');
47+
}
48+
}

src/Component/spec/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactorySpec.php renamed to src/Component/tests/Symfony/Routing/Factory/RoutePath/ShowOperationRoutePathFactoryTest.php

File renamed without changes.

0 commit comments

Comments
 (0)