Skip to content

Commit 17de9da

Browse files
committed
Fix usage of Route attribute methods which are deprecated in symfony 7.4
1 parent 4d6c0c5 commit 17de9da

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

Controller/Annotations/Route.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@ public function __construct(
123123
);
124124
}
125125

126-
if (!$this->getMethods()) {
127-
$this->setMethods((array) $this->getMethod());
126+
if (property_exists($this, 'methods')) {
127+
if (!$this->methods) {
128+
$this->methods = (array) $this->getMethod();
129+
}
130+
} else {
131+
if (!$this->getMethods()) {
132+
$this->setMethods((array) $this->getMethod());
133+
}
128134
}
129135
}
130136

Tests/Controller/Annotations/RouteTest.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,27 @@ public function testCanInstantiate()
4141
$condition
4242
);
4343

44-
$this->assertEquals($path, $route->getPath());
45-
$this->assertEquals($name, $route->getName());
46-
$this->assertEquals($requirements, $route->getRequirements());
47-
$this->assertEquals($options, $route->getOptions());
48-
$this->assertEquals($defaults, $route->getDefaults());
49-
$this->assertEquals($host, $route->getHost());
50-
$this->assertEquals($methods, $route->getMethods());
51-
$this->assertEquals($schemes, $route->getSchemes());
52-
$this->assertEquals($condition, $route->getCondition());
44+
// Symfony >= 7.4
45+
if (property_exists($route, 'path')) {
46+
$this->assertEquals($path, $route->path);
47+
$this->assertEquals($name, $route->name);
48+
$this->assertEquals($requirements, $route->requirements);
49+
$this->assertEquals($options, $route->options);
50+
$this->assertEquals($defaults, $route->defaults);
51+
$this->assertEquals($host, $route->host);
52+
$this->assertEquals($methods, $route->methods);
53+
$this->assertEquals($schemes, $route->schemes);
54+
$this->assertEquals($condition, $route->condition);
55+
} else {
56+
$this->assertEquals($path, $route->getPath());
57+
$this->assertEquals($name, $route->getName());
58+
$this->assertEquals($requirements, $route->getRequirements());
59+
$this->assertEquals($options, $route->getOptions());
60+
$this->assertEquals($defaults, $route->getDefaults());
61+
$this->assertEquals($host, $route->getHost());
62+
$this->assertEquals($methods, $route->getMethods());
63+
$this->assertEquals($schemes, $route->getSchemes());
64+
$this->assertEquals($condition, $route->getCondition());
65+
}
5366
}
5467
}

0 commit comments

Comments
 (0)